You have made a program secure.c to display which ports are open and what types of services
are running on these ports. You want to write the program’s output to standard output and
simultaneously copy it into a specified file. Which of the following commands will you use to
accomplish the task?
A.
less
B.
tee
C.
cat
D.
more
Explanation:
You will use the tee command to write its content to standard output and simultaneously copy it
into the specified file. The tee command is used to split the output of a program so that it can be
seen on the display and also be saved in a file.
It can also be used to capture intermediate output before the data is altered by another command
or program. The tee command reads standard input, then writes its content to standard output,
and simultaneously copies it into the specified file(s) or variables. The syntax of the tee command
is as follows: tee [-a] [-i] [File] where, the -a option appends the output to the end of File instead of
writing over it and the -i option is used to ignore interrupts.
Answer option C is incorrect. The concatenate (cat) command is used to display or print the
contents of a file.
Syntax: cat filenameFor example, the following command will display the contents of the /var/log/dmesg file:
cat /var/log/dmesg
Note: The more command is used in conjunction with the cat command to prevent scrolling of the
screen while displaying the contents of a file.
Answer option A is incorrect. The less command is used to view (but not change) the contents of a
text file, one screen at a time. It is similar to the more command. However, it has the extended
capability of allowing both forward and backward navigation through the file. Unlike most Unix text
editors/viewers, less does not need to read the entire file before starting; therefore, it has faster
load times with large files.
The command syntax of the less command is as follows: less [options] file_name
Where,Answer option D is incorrect. The more command is used to view (but not modify) the contents of
a text file on the terminal screen at a time.
The syntax of the more command is as follows: more [options] file_name
Where,