Redirect a Command s Output to a File


Redirect a Command's Output to a File

>

Normally, output goes to your screen, otherwise known as stdout. If you don't want output to go to the screen and instead want it to be placed into a file, use the > (greater than) character.

$ pwd /home/scott/music $  ls -1F Hank_Mobley/ Horace_Silver/ John_Coltrane/ $ ls -1F Hank_Mobley/* > hank_mobley.txt $ cat hank_mobley.txt 1958_Peckin'_Time/ 1960_Roll_Call/ 1960_Soul_Station/ 1961_Workout/ 1963_No_Room_For_Squares/ $  ls -1F Hank_Mobley/ hank_mobley.txt Horace_Silver/ John_Coltrane/ 


Notice that before you used the >, the file hank_mobley.txt didn't exist. When you use > and redirect to a file that doesn't already exist, that file is created. Here's the big warning: If hank_mobley.txt had already existed, it would have been completely overwritten.

Caution

Once again: Be careful when using redirection, as you could potentially destroy the contents of a file that contains important stuff!




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