add to the end of a file
Add lines to a file without replacing it, also to a file only root can write.
filesshell
steps
-
echo 'new line' >> file.txtadd a line at the end
-
command >> log.txt 2>&1add a command's output and errors
-
command | tee -a log.txtsee it and add it to the file
-
echo 'new line' | sudo tee -a /etc/some.confadd to a file only root can write
notes
- One
>replaces the file; two,>>, add to it. sudo echo x >> /etc/filefails: the redirection is done by your shell, not by sudo.
commands used
teeecho
Each has a page in lore: lore tee opens it.
argument list too long
"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.
get a file's name, folder and extension
Take a path apart in a script: the folder, the name, the name without its extension, the extension.
rename many files
Change the ending of many files, replace spaces in names, or number them.
add a folder to the path
Let the shell find programs in a folder, for good, and reload the settings without logging out.