2.3 Given a scenario, create, modify, and redirect files Flashcards
grep
Use the grep command to search files for lines that contain a specific pattern. By default, the grep command will display the entire line when it finds a matching pattern
grep “the” /etc/rsyslog.conf
cat
The cat command displays the contents of text files
tail
The tail command displays the bottom part of text data. By default, the last ten lines are displayed. Use the -n option to display a different number of lines
head
The head command displays the top part of text data. By default, the top ten lines are displayed
less
The less command is used to display large chunks of text data. Unlike the cat command, the less command will pause after displaying the first page of information. Keys on the keyboard allow the user to scroll through the document
more
The more command is a slightly less capable version of the less command. Essentially everything that the more command can do, the less command also has as a feature. However, the less command has additional features that the more command does not have
cmd < file
Override STDIN so the input comes from the file specified
cmd > file
Override STDOUT so the output goes into the file specified
cmd 2> file
Override stderr so the output goes into the file specified.
cmd &> file
Override both STDOUT and stderr so the output goes into the file specified.
cmd1 | cmd2
Override STDOUT from cmd1 so it goes into cmd2 as STDIN
/dev/null
You can redirect these messages into the /dev/null device file. This file is called the “bit bucket” and acts as a trash can that never needs to be emptied. Anything sent to the /dev/null device is immediately discarded
/dev/tty
Several files in the /dev directory are used to send data to display devices. These include virtual terminals
xargs
The xargs command takes data from STDIN to build and execute commands. Here is the format of the command
input_command | xarg execute_command
The input_command is designed to provide information for xargs to provide as arguments to the execute_command. For example, suppose you want to run the wc -l command on every file in the /etc directory that begins with the letter “e”:
tee
If you want STDOUT to be sent both to the terminal and to a file, send the output to the tee command and provide an argument that indicates the file in which you want to store the information.