Sunday, January 30, 2011

BASH : PIPES

Connect the output stream of command A to the input strem of a command B
ls -l | wc -l -> returns the number of files in a directory plus one( the . which is teh current direcotry). 
ls -A | wc -l -> returns the number of files in a directory. The output strem is redirected.
ls -l | sort -r -> return the file in reverse alfabetic order
ls -A | sort -r | wc -l -> returns the number of files in the folder
touch data
pico data -> write 2 colums separated by space;
CONTENT of file
firstname lastname
first last
---------------------
cat data -> display the data
cat data | cut -f 2 -d ' ' -> -f - field 2; -d - delimiter space
Returns:
lastname
last
---------
cp data data2 -> copy data to data2
pico data2 -> change the demiter to comma ','
cat data2 -> values in the file are delimited by comma ','
cat data2 | cut -f 1 - d ','
Returns:
firstname
first
--------------
cat data2 | cut -f 1 - d ',' | wc -> returns the 2 lines 2 words 14 caracters
ps -ax | grep httpd -> processes that contains streng 'httpd' are displayed
ps -ax |grep httpd | wc -l -> returns a number containing all the httpd processes plus the grep process
pipes are very fast, are done in memory not in disk
ps -ax -> this in done in memory

No comments:

Post a Comment