Skip to main content

Posts

Showing posts from December, 2014

Streams and Pipelines in UNIX environments

Linux shells use three standard I/O streams, each of which is associated with a well-known file descriptor:   stdout is the standard output stream , which displays output from commands. It has file descriptor 1. stderr is the standard error stream , which displays error output from commands. It has file descriptor 2. stdin is the standard input stream , which provides input to commands. It has file descriptor 0. Redirecting output ls x* z* >stdout.txt 2>stderr.txt Standard output in the first file and the errors in the second file. Output redirection using n> usually overwrites existing files. You can control this with the noclobber option of the set builtin. ls x* z* 2>&1 >output.txt This will redirect all errors to standard output and standard output is redirected to the file. The errors will be displayed in the terminal and the output is written to a file.   ls x* z*

grep useful commands

a_file ------- boot book booze machine boots bungie bark aardvark broken$tuff robots grep "boo" a_file  boot book booze boots grep -n "boo" a_file 1:boot 2:book 3:booze 5:boots grep -vn "boo" a_file 4:machine 6:bungie 7:bark 8:aaradvark 9:robots grep -c "boo" a_file 4 grep -l "boo" * Prints out the file names grep -i "BOO" a_file ignores case grep -x "boo" a_file  exact matches echo "i want to search for this text" > search grep -f search a_file