Sunday, January 30, 2011

BASH : I/O Redirection

File descriptors 0,1 ,2 corresponds to keyboard, screen, standard error. By default every thing is redirected to screen. Standard input for computer is keyboard.
ls -l -> standard input is used (keyboard) and standard output displayes the results on monitor
Example:
touch file.txt
vi file.txt - type test in the file
cat < file.txt -> the content is displayed in the screen
ls -l /bin -> display the content of the /bin folder
grep test < file.txt -> search for text 'test' in file.txt
vi file.txt -> add another line 'second line'
grep test < file.txt -> Return the line containing the 'test' word
cat file.txt -> displays the containing text from the file
cat file.txt > file2.txt -> copy file.txt into file2.txt
cat file.txt >> file2.txt -> concatenate copy file.txt into file2.txt. The content is double, has the same content dubled
grep test < file.txt > file3.txt -> search text 'test' in file.txt and copy into file3.txt

No comments:

Post a Comment