Understanding stdout
Let’s say that you want to look at the listing of files that are in a certain directory. Instead of piping the ls
output into less
, you want to create a text file of this listing so that you can print it later. Here’s a graphical representation of how it works:
Figure 4.1: How stdout works
Here’s what it looks like in practice, where I’m sending output from the ls
command to the filelist.txt
file:
[donnie@fedora ~]$ ls > filelist.txt
[donnie@fedora ~]$
As you can see, this is fairly simple. You can take pretty much any command that normally sends its output to the computer screen, and have it sent to a text file instead. There is one thing that you have to be careful with, though. If you redirect a command’s output to a file that already exists, you will overwrite it, and all previous information in that file will be lost. There are three ways to prevent this from happening.