Ch 4 Using Common Text File-Related Tools Flashcards
(63 cards)
What command opens text file in a pager (to the console/terminal/stdout), allowing for easier reading?
less
(e.g.,
sudo dmesg | less
pipes the output of dmesg to a pager
what command dumpts contents of a text file to screen
cat
(short for concatenate…chaining things together)
because of the limitations of how much data you can see in a shell window, cat will only give you the last lines of a file. What command do you use if you want to see the first lines?
tac (cat spelled backwards)
what command will dump the first ten lines of a file to stdout?
head
what command will dump the last ten lines of a file to stdout?
tail
What does this command do?
head -n 11 /etc/passwd | tail -n 1
The n flag tells it how many lines to give. So first it outputs the first 11 lines of /etc/passwd.
It pipes that to tail, which takes those 11 lines and only shows that last one
What does the -f flag for the tail command do?
shows you the last ten lines of a file, but sends any additional lines to stdout as that process runs,
e.g. tail -f /var/log/messages
what are the 11 main commands (well, one is a tech) used for working with text files?
less
cat
tac
tail
head
sort
cut
grep
regex
awk
sed
what does the cut command do, broadly?
filters out specific fields.
e.g. list of all users in /etc/passwd/
what is the -d flag for cut?
-d is for delimiter. pick something like a comma or a colon. must be followed by -f, for field (and this will be a number)
What is this command doing?
cut -d : -f 1 /etc/passwd
looking at the /etc/passwd file, sort using the 1st field and use : as the delimiter
this filters OUT the first field of the file, which will give you just the usernames
Translate this into plain english:
Cut -d : -f 1 /etc/passwd
Parse the etc/password file and, using a colon as a delimiter, take only the first field
What would be the output of
Sort /etc/passwd?
It will print out the contents of the file, but in byte order – or how characters appear in an ASCII text table – looks like it’s alphabetic, but ISNT
Is the output of sort alphabetical?
No
It’s based off the ASCII text table order. So since all capitals come first, Z would come before a, because it’s capitalized
What command often goes with cut?
Sort
What are different options with the sort command?
-n for numeric order
-rn for reverse numeric
what does the command
sort -k3 -t : /etc/passwd do?
This sorts along a column of your choice – in this case, it’s filtering along the 3rd column in the /etc/passwd file, using : as the field delimiter
what does this command do?
ps aux | sort -k 4 -n
sort the output of the ps aux alone the 4th column, and sort it numerically (don’t need a delimiter because it’s a command’s output, not a file’s?)
overall, this command tells us which processes are using the most memory
What command will give you a word count?
wc
what are the three different results you could get from the wc command?
- number of lines
- number of words
- number of characters
What would be the simplest/easiest/fastest command to figure out how many processes are running right now?
ps aux | wc
what does this command do ?
grep anna /etc/passwd
looks for the word anna in the /etc/passwd file