Viewing Text and Redirecting Output Flashcards
What is a file perusal filter for crt viewingq and provides a filter for paging through text one screenful at a time?
More
-use more followed by the file name it will allow you to view and move around the file
What is a text viewing utility similar to more but with more features like backward movement?
less
What command outputs the first part of files?
head
-the -n option specific the number of lines to print rather then the default of 10
-type head follower by text file for example head /var/log/messages and it will show a default of 10 first lines. To change do head -n /var/log/messages
What command outputs the last part of files?
tail
-the -n option specifies the number of lines and -f is used to append data as the file grows (log file)
Example. tail -f /var/log/messages this will show the new messages as they are happening. Good if you are following an active incident or issue to show the logs in a server
What command prints lines matching a pattern?
grep
- -i option ignores case
- -R option reads files under each directory recursively
Example use grep then a line of text and then wehre you want to search for that text. So grep hello /var/log/messages it will output every line that has the word hello in /var/log/messages
If you do grep -R cloud_user /var/log/ it will search every directory and file within the log directory
What command sorts lines of text files and what order?
sort…ascending alphabetical order
- can be reversed with -r option
- -n used to sort numerically
-can sort multiple files
What are the file descriptors?
0: input stdin
1: output stdout
2: stderr
Output redirection
> > >
Input redirection
< «
Error Redirection
2>
Redirect stdout and stderror (Merge)
2>&1 and &>
What is pipeline redirection
A pipe | allows the output of one command to serve as the input of another command