This would be another little memo of all the most used (by me) Input/output redirections and pipes.
As other times this would not be a complete guide, and would not go into the deep.

The base :

Standard input (stdin) : 0
Standard output (stdout) : 1
Error output (stderr) : 2

> : output redirection
< : input redirection
>> : append output
| : pass the output to the next utility
|| : execute the next command if the previous failed
&& : execute the next command only if the previous has succeded

Examples :

cat file.txt > /tmp/file.txt

If file.txt exists, the output will be written in /tmp/file.txt
If file.txt doesn’t exist, the error message will be output to the screen while nothing will be written to /tmp/file.txt (but the file will be created if not existing)

cat file.txt 2> /tmp/error_file.txt > /tmp/file.txt

In this case the error message would be written to /tmp/error_file.txt if the file doesn’t exist

cat file.txt 2> /tmp/error_file.txt >> /tmp/file.txt

The error output would still go in error_file.txt while the standard output would be APPENDED to file.txt

cat file1 > file2

Will copy the content of file1 to file2

 cat &gt; file3

Hello world

Will write “Hello world” to file3

[/bash]wc < file.txt > count_file.txt[/bash]

This would count the number of lines, words and bytes in file.txt (”wc < file.txt”) and output the result to count_file.txt

Several ways of counting lines etc. :
$ wc file.txt
7 2 17 file.txt
$ wc < file.txt
7 2 17
$ cat file.txt | wc
7 2 17

ls -l test10 > file.txt 2>&1

This would output anything under file.txt

<code>ls -l test10 2>&1 | mail -s “output in a mail” address@domain.com
Any output in a mail

Hope this help

Bye
Riccardo

Print This Post Print This Post

Leave a Reply

Spam Protection by WP-SpamFree

Contacts
Look at me at Linkedin Follow me on Twitter
My Flickr Albums My Facebook profile My YouTube Videos
SkypeMe My Linux Counter GMail me
Search
Google Search
Categories
Tag Cloud 3D
FeedBurner RSS

Visitors
Locations of visitors to this page
VMware related Blogs
The following are Blog sites with feeds I personally follow. When I'll have some spare time I will complete all Feed and Twitter links.