4. Becoming a Power User Flashcards
How do you chain multiple commands in a way that the output from one program is sent as an input to another?
By using a pipe symbol.
ls | less
How do you search for text in a file and what kind of output do you get when you do?
By executing the grep
command and passing it the search term as well as the file name.
grep 1978 oscars.tsv
When we do, we get a list of lines that contains the search term (1978).
How do sort records (lines) of text or binary files?
By executing the sort
command and passing it the lines of text or binary files.
grep 1978 oscars.tsv | sort
How do you save the output from a command to a file?
By using a greater than sign and a filename. This sends the output of a command to that new file, but be careful — this will override any data if the file you send it to already exists.
grep 1987 oscars.tsv > 1987-oscars.tsv
How do you cut out a specific column of each line of a file containing delimiter-separated lines of text?
By executing the cut
command and passing it the column number using the f
flag as well as the filename.
cut -f 3 oscars.tsv
How do you count the words, lines, characters, or bytes in a given text file?
By executing the wc
command with -w
for words, -l
for lines, -m
for characters, and -c
for bytes.
wc -l oscars.tsv
How do you search for a given text in all files in the current folder?
By executing the grep
command and passing it the search term as well as an asterisk
grep someword *
What is the primary wildcard character?
The asterisk (*).
How do you get the shell to repeat an input back to you?
By using the echo
command.
echo Hi there!
What does the echo
command do in its most simple form?
It repeats (or echoes) its input back to you.
How do you echo all of the file names in the current directory?
By executing the echo
command and passing it an asterisk.
echo *
How do you list all files in a directory whose name starts with a given text?
By executing the ls
command and passing it the text suffixed with an asterisk.
ls doc*
How do you list all files in a directory whose name ends with a given text?
By executing the ls
command and passing it the text prefixed with an asterisk.
ls *sh
How do you list all files in a directory whose name contains a given text?
By executing the ls
command and passing it the text surrounded by asterisks.
ls *oc*
How do you move all the files whose names end with a certain text into a given folder?
By executing the mv
command and passing it the text prefixed with an asterisk as well as the folder into which you want to move them.
mv *jpg pictures