Append a Command s Output to a File


Append a Command's Output to a File

>>

As you learned previously, the > character redirects output from stdout to a file. For instance, you can redirect the output of the date command to a file easily enough:

$ date Mon Nov 21 21:33:58 CST 2005 $ date > hank_mobley.txt $ cat hank_mobley.txt Mon Nov 21 21:33:58 CST 2005 


Remember that > creates a new file if it doesn't already exist and overwrites a file that already exists. If you use >> instead of >, however, your output is appended to the bottom of the named file (and yes, if the file doesn't exist, it's created).

$  cat hank_mobley.txt Mon Nov 21 21:33:58 CST 2005 $ ls -1F Hank_Mobley/* >> hank_mobley.txt $  cat hank_mobley.txt Mon Nov 21 21:33:58 CST 2005 1958_Peckin' _Time/ 1960_Roll_Call/ 1960_Soul_Station/ 1961_Workout/ 1963_No_Room_For_Squares/ 


Caution

Be careful with >>. If you accidentally type > instead, you won't append, you'll overwrite!




Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net