send output and errors to a file
Keep what a command prints, its errors too, in a file, or throw them away.
shell
steps
-
command > out.log 2>&1the output and the errors into out.log (2>&1: errors go where the output goes)
-
command >> out.log 2>&1the same, added at the end of the file
-
command 2> errors.logonly the errors into a file
-
command 2>/dev/nullthrow the errors away
-
command > /dev/null 2>&1throw everything away
-
command 2>&1 | tee out.logsee everything and keep a copy
notes
- The order matters:
> out.log 2>&1works,2>&1 > out.logsends the errors to the screen. lore explain "command > out.log 2>&1"says what each part does.
commands used
tee
Each has a page in lore: lore tee opens it.
add a folder to the path
Let the shell find programs in a folder, for good, and reload the settings without logging out.
add to the end of a file
Add lines to a file without replacing it, also to a file only root can write.
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.
ask for input in a script
Ask yes or no, read a password without showing it, or wait for an answer with a time limit.