Timeline for How do I add text to the beginning of a file in Bash?
Current License: CC BY-SA 4.0
20 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 29, 2022 at 12:27 | comment | added | nonopolarity | a little warning here: it can be dangerous to read and directly overwrite a file this way... for one thing, what if the commands happen to operate like this: read position 10000000 to 10100000 and write to the file, but now that position 10000000 is already of the new file? Even if that won't happen, what if the file system becomes full during this, so the new file is being written, but disk full, and fail, and now where is that old file for you to redo this operation when you clean up some disk space? You may lose this file or (part of it) | |
S Apr 9, 2020 at 14:46 | history | suggested | Sasha | CC BY-SA 4.0 |
The `(echo 'task goes here' && cat todo.txt) > todo.txt` won't work (and it's inserted into the answer not by original answer's author)
|
Apr 9, 2020 at 8:30 | review | Suggested edits | |||
S Apr 9, 2020 at 14:46 | |||||
Feb 20, 2019 at 9:17 | comment | added | Vivek Kodira | Warning: replaces occurrences of '\n' with actual newlines | |
May 10, 2018 at 11:06 | comment | added | jesjimher | I'm not sure this works with large files, bash string size is probably limited to a few MB. | |
Mar 29, 2018 at 5:31 | comment | added | xizdaqrian | Warning: The last one overwrites each file with the echo (or printf) statement. | |
Feb 17, 2018 at 20:10 | comment | added | Peter Berg | printf would be a lot more consistent across platforms and should generally work more smoothly than echo -e | |
S Nov 30, 2015 at 23:21 | history | suggested | dougcosine | CC BY-SA 3.0 |
Added missing ')' changed "the file" to "todo.txt" to clarify (but mostly to get over 6 character edit limit)
|
Nov 30, 2015 at 22:58 | review | Suggested edits | |||
S Nov 30, 2015 at 23:21 | |||||
Jan 9, 2015 at 2:10 | comment | added | ingyhere | Workarounds yield --> cat: <destination filename>: input file is output file ... | |
S Jul 1, 2014 at 19:37 | history | suggested | Parthian Shot | CC BY-SA 3.0 |
added necessary disclaimer
|
Jul 1, 2014 at 17:48 | review | Suggested edits | |||
S Jul 1, 2014 at 19:37 | |||||
Sep 2, 2013 at 21:23 | comment | added | mk12 |
Won't the -e also convert escape sequences inside todo.txt?
|
|
S Aug 11, 2013 at 18:28 | history | suggested | Oli | CC BY-SA 3.0 |
Double quotes required for the `$()`
|
Aug 11, 2013 at 17:31 | review | Suggested edits | |||
S Aug 11, 2013 at 18:28 | |||||
May 22, 2013 at 7:25 | comment | added | raphink | That might work better (or at all) with double quotes instead of single… | |
Feb 22, 2013 at 17:10 | comment | added | SCL | I don't get $(...) executed at all. | |
S Dec 19, 2012 at 19:13 | review | Late answers | |||
Dec 19, 2012 at 19:16 | |||||
S Dec 19, 2012 at 19:13 | review | First posts | |||
Dec 19, 2012 at 19:28 | |||||
Dec 19, 2012 at 18:57 | history | answered | John Alberts | CC BY-SA 3.0 |