Shell Features Flashcards
What are the 3 channels every linux program has when it starts?
File Desciptors
stdin 0<
stdout 1>
stderr 2>
How would you overwrite text to a file from the shell?
1> - stdout
i.e echo “Overwrite this.” 1> file.txt
How would you append text to a file from the shell?
1» - stdout
i. e ls -alh 1» file.txt
i. e echo “Append this.” 1» file.txt
How would you append error output to a text file from the shell?
2»
i.e ls -alh nonexistant 2» file.txt
How would you overwrite error output to a text file from the shell?
2>
i.e ls -alh nonexistant 2> file.txt
How do you run a command sequentially after the other?
;
i.e ifconfig; touch file
How do you run a command sequentially only if the first completed successfully?
&&
i.e ls file && mkdir directory1
What is the command to search for text?
grep
i. e grep example file.txt
i. e grep example ./* -all files in current directory
What is the command to count the number of characters and words in a file?
wc
How do you pass the output from one command to another?
|
i.e cat file | sort
What is the command to select only portions of text from a file?
cut
i.e cat file | cut -d’ ‘ -f3,4
What is the command to only display unique text?
uniq
i.e cat file | uniq
What is the command to run a subsequent command only of the previous failed?
||
ls -l nonexistent || touch nonexistent
*or operator evaluates expressions either side