Using redirection on the UNIX command line.

Posted: February 9, 2012. At: 7:42 PM. This was 6 years ago. Post ID: 2672
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

Using redirection on the command line is very easy to do. The main strength of the UNIX commmand line is that you may output data from one command line application to another. Here is one example.

ls -hula | less

This is using the pipe character to pipe the output of the ls(1) command to the less command, which will allow you to scroll through the output. To redirect the output of a program to a file, this command is used.

ps > psout.txt

To redirect the verbose console output of a file to another location when you are running a program from a terminal, this command line will work very well indeed. This redirects the stderr stream.

gedit 2> /dev/null

if you redirect the output to a file, then you may read the contents after you are finished with the program in question. Here we are redirecting the output of both stdout and stderr to the bit bucket /dev/null.

gedit &> /dev/null

Using piping to redirect the contents of a textfile and parse it with sed(1).

cat blog.txt | sed "s/tHe/The/gi;"

There are more verbose explanations of this procedure on this website. The Linux Documentation Project.

1 responses to “Using redirection on the UNIX command line.

Leave a Reply