Redirection of standard output

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← Redirection of standard errorHomeAppending redirected output →

To redirect output simple use the following syntax:

command > /path/to/file
/path/to/script.sh > output.txt

For example, send output of date command to a file called now.txt:

date > now.txt

You can also use the > operator to print file, enter:

cat file.txt > /dev/lp0

OR

sudo bash -c "cat file.txt > /dev/lp0"

To make a usage listing of the directories in the /home partition, enter:

sudo bash -c "cd /home ; du -s *│ sort -rn >/tmp/usage"

You can also use the following syntax:

echo "Today is $(date)" 1>/tmp/now.txt

External links

← Redirection of standard errorHomeAppending redirected output →