Have a Bash With This Linux Shell - page 2
Directing command output into a file is very useful. Some operations generate a lot of output; saving it in a file lets you study it at leisure. This command creates a new file, or replaces the contents of an existing file:
ls -al ~ > homefiles.txt
This creates a new file, or appends to the end of an existing file:
ls -al ~ >> homefiles.txtThis is a fast way to append lines to an existing file:
cat >> homefiles.txt testing, testing, new line
Hit CTRL + D to finish.
I like piping the output of make to a file, so I know what files were installed, and where. And to review any error messages. In this example, I'm installing JOE, Joe's Own Editor:
make install | tee joe-makeinstall.txt
The tee command is one of those odd little specialized Unix commands that come in handy at the strangest times. It both displays the command output on the screen, and stores it in a file. Use tee -a to append, instead of overwrite.
You doubtless noticed how most of the pieces of the above examples are not Bash features at all. The only Bash bits are:
cat < file1 > file2This works great when you're feeding a list, or other data in a file, to a script:
scriptname < filelist > outputfile.txt
Sponsored by BlackBerry
BlackBerry® Enterprise Server Express enables businesses of any size to quickly and easily get started with the BlackBerry solution. It provides advanced BlackBerry smartphone features with no additional software or user license fees, and works with any Internet-enabled BlackBerry data plan or a BlackBerry enterprise data plan. Download now!