CL Extras Flashcards
What does the cal command do?
prints out a calendar
What would you type if you wanted to see the current year’s calendar?
cal -y
What would you do if you wanted to display the calendar of a different year?
cal 2015
How can you display the month of a year?
pass two integer parameters:
cal 8 2016 = august 2016
What command will print out the contents of a file to standard output?
cat
How can you send the output of cat to a file?
cat file1.txt file2.txt > new_file.txt
How can we print to the screen a file’s contents with line numbers added?
cat -b file.txt
What is the default signal for kill?
15 or SIGTERM
How can we find the process ID of the process that we need to stop?
ps command shows PID
What does this command do:
kill 123456
It sends a signal to process 123456 to peacefully shut down when it is ready.
What two ways can you pass a signal to the kill command?
with the value of the signal or by using the -s flag and passing the name of the signal.
kill -9 123456
kill -s SIGKILL 123456
What command prints out information about commands?
man
syntax: $ man command_you_want_to_learn_about
What command allows us to look at the end of a file?
Tail
What is the tail command good for?
monitoring log files in a production environment
By default, when you pass a file name to the tail command, the last __ lines of a file will be printed to the screen, and ___.
10
tail will exit.
How do we change the number of lines that are displayed by tail?
with the -n flag
tail -n 5
How can we reverse the direction of how tail displays the selected lines of the file to us?
with the -r flag
tail -r -n 5 /path/filename displays the last five lines of the file with the last line first
What flag makes the tail command go live, continuing to output new data as it is added to the end of a watched file?
-f
tail -f /path/file.log
What is a live file referred to?
A ‘tailing’ file.
How can we filter the live output of a tail command?
tail -f /path/name.log | ag com.apple.windowserver
What command allows you to recursively list the contents of a directory in a high level view?
tree
How can you limit the depth of tree’s recursion?
with the -L flag
tree -L 2 will only display the first two levels of a tree of directories
By default tree will list both files and directories, how can we print out just the directories?
with the -d flag
tree -d
How can we count the number of words in a file?
wc -w filename.txt
How can we count the number of lines in a file?
wc -l file
How can we see in how many lines the pattern DHH is repeated?
ag DHH | wc -l