Command Line: Pipes and Redirection Flashcards
Send output of a command to a file named myoutput and keep the myoutput contents
ls»_space; myoutput
will append the output of ls command to the file named myoutput
Send output of a command to a file named myoutput and overwrite contents
ls > myoutput
will overwrite the contents of the myoutput file and replace it with the current directory list
Read contents of a file to the terminal
cat filename.txt
Count words of a file
wc
Count lines of a file
wc -l
Output errors of a command to a file
… 2> errorfileName.txt
For example if fakeFile.txt does not exist the following command will send the error the errors.txt
ls realFile.txt fakeFile.txt 2> errors.txt
limit the output of a command to the first 4 items
command | head -4
for example: ls | head -4
will only show the first for filesystem items
pipes can be chained so we could: ls | head -4 | head -2 which will only show the 3rd and 4th items
Command line operator uses the same file for input and output
<>