When scripting Bash scripts, often we'll need to output all stdout & stderr of a particular command into a log file, for logging purposes or diagnostic purposes.
Command :
&>(Yup, that's the only 2 symbol to achieve the purpose)
Example :
- This will clear the current file (if exist) and output everything to the file :
tar zcf somefile.tar.gz /etc/ &> log.file
- This will "append" the output into the file :
tar zcf somefile.tar.gz /etc/ &>> log.file
*** Do take note of the double ">>" symbol
Farvel !!!
No comments:
Post a Comment