TESTS Ch3. GNU and Unix Commands (Domain 103)

Ace your homework & exams now with Quizwiz!

When using Bash, how would you execute the last command starting with a certain string, even if that command was not the last one that you typed? A. Precede the command with ! and then the string to search for. B. Search for the command in history. C. Precede the command with ? and then the string to search for. D. This is not possible with Bash.

A. Preceding the command with ! will search history and execute the specified command. For example, !vi will start your last vi session.

Which kill signal can be sent in order to restart a process? A. -HUP B. -RESTART C. -9 D. -SIG

A. Sending -HUP as part of the kill command will restart a process. Of the other answers, -9 will kill the process completely. The other two answers do not exist as valid means to kill a process.

The current hierarchy on the server contains a directory called /usr/local. You need to create additional directories below that called /usr/local/test/october. Which command will accomplish this task? A. mkdir -p /usr/local/test/october B. mkdir /usr/local/test/october C. mkdir -r /usr/local/test/october D. mkdir -f /usr/local/test/october

A. The -p option will cause mkdir to create additional levels of directories without error. Running mkdir without options will not work in this case. The -r and -f options to mkdir do not exist.

Which of the following will unzip and extract the contents of a file that has been tarred and gzipped? A. tar -zxf <file.tgz> B. tar -xf <file.tgz> C. tar -vz <file.tgz> D. tar -fd <file.tgz>

A. The -z option will unzip the file while -x will extract from the tar archive, and -f is used to indicate the file on which to perform the aforementioned operations. It's typical to add -v for verbose output as well.

Which of the following commands will provide the usernames in a sorted list gathered from the /etc/passwd file? A. cat /etc/passwd | awk -F: '{print $1}' | sort B. sort /etc/passwd | cut C. echo /etc/passwd D. cat /etc/passwd | awk '{print $1}' | sort

A. The cat command will display the contents of the file /etc/passwd and then pipe that output to the awk command. The awk command then parses its input, splitting along the specified separator for /etc/passwd, which is a colon (:). The output is then printed and piped to the sort command. The sort command in option B will not work because the cut command requires an argument. Likewise, the echo command in option C will only echo /etc/passwd to stdout. The split command can also be used to split input but does so on a fixed width manner which is generally not feasible when working with the passwd file as input. Also, the tr command is a typical companion to the awk command and helps to substitute the characters from awk output.

Which option to the man command accesses a different level of documentation, for example, system call documentation? A. man 2 <argument> B. progman <argument> C. man --sys <argument> D. man --list sys

A. The different levels of the manual are accessed by preceding the argument with the desired level. The other options, such as -list, do not exist in this context.

Assume that you have a file called zips.txt that contains several postal zip codes, and you need to determine how many unique zip codes there are in the file. Which of the following commands can be used for that purpose? A. sort zips.txt | uniq -c B. uniq zips.txt C. count zips.txt D. cat zips.txt | uniq -c

A. The file first needs to be sorted to group common zip codes together. After that, piping the output to uniq will display the unique zip codes, and the -c option provides a count.

Which find command will locate files within the current directory that have been modified within the last 24 hours? A. find ./ -type f -mtime 1 B. find ./ -type f -mtime 24 C. find ./ -type f -mtime +1 D. find ./ type -f time 24

A. The find command is used for this purpose. Adding -type f will limit the search to only files, and the -mtime option will limit to modification time in day format.

When using sed for a substitution operation, which option must be included so that the substitution applies to the entire line rather than just the first instance? A. g B. a C. r D. y

A. The g option, also known as global or greedy, will apply the matched operation to the entire line rather than just the first instance of the match. The other options apply as they would for a Perl Compatible Regular Expression.

What will be the result if the touch command is executed on a file that already exists? A. The access timestamp of the file will change to the current time when the touch command is executed. B. The file will be overwritten. C. There will be no change. D. The file will be appended to.

A. The timestamp of the file will change when touch is run on a file that already exists.

Which command can be used to determine the current load average along with information on the amount of time since the last boot of the system? A. uptime B. sysinfo C. bash D. ls -u

A. The uptime command shows basic information such as that described in the question along with the number of users logged into the system and the current time. The bash command is a shell environment, and the ls command will not display the required information.

You receive a file with a .lzma extension. Which command can you use to decompress this file? A. xz B. lz C. gz D. bzip

A. The xz command can compress and decompress files in a variety of formats, one of which is lzma.

You are using the vi editor for changing a file and need to exit. You receive a notice indicating "No write since last change." Assuming that you want to save your work, which of the following commands will save your work and exit vi? A. :wq B. :q! C. dd D. x

A. You need to write the changes to the file; therefore, you'll need :w. The addition of q will also quit. Note that you could use ZZ to write and quit as well. The dd command deletes a line whereas x deletes a single character.

Which option to the cp command will copy directories in a recursive manner? A. -v B. -R C. -Z D. -i

B. The -R option will copy directories recursively. Note that if the -i option is not enabled, the recursive copy will overwrite files in the destination. The -v option adds verbosity but does not cause any recursion, and the -Z option does not exist.

You are attempting to use rmdir to remove a directory, but there are still multiple files and other directories contained within it. Assuming that you're sure you want to remove the directory and all of its contents, what are the command and arguments needed to remove the directory and all of its contents? A. rm -f B. rm -rf C. rmdir -a D. rmdir -m

B. The -rf options to rm will recursively remove contents of a directory, including other directories. The -f option alone will not work in this case because of the additional directories. The other options given for rmdir do not exist.

What is the default delimiter used by the cut command? A. Colon B. Tab C. Space D. Comma

B. The cut command uses a tab as its default delimiter. This can be changed with the -d option. You might use the cut command in order to apply text filters to one or more files so that they can be further processed later. For example, you might cut certain fields and create new files that can be connected together using the join or paste commands. You can use the unexpand command if you need to convert spaces to tabs and the expand command to convert tabs to spaces. However, you can also change the delimiter that is used by cut.

What command can be used to view the current settings for your environment when using Bash? A. environment B. env C. listenv D. echoenv

B. The env command will print the current environment variables from Bash. The printenv command will also perform the same operation. The other commands listed in this question do not exist.

Which of the following commands searches each user's .bash_history file to determine if the user has invoked the sudo command? A. find /home -name "bash_history" | grep sudo B. find /home -name ".bash_history" | xargs grep sudo C. find /home/.bash_history | xargs grep sudo D. find /home -type history | xargs grep sudo

B. The find command beginning with the path and then the -name argument will locate all of the files called .bash_history. The output from the find command should be piped to xargs, which can then build further commands from standard input. Note that this question and solution assume that all users use the Bash shell and are keeping history.

Which of the following commands will display the last 50 lines of your command history when using Bash, including commands from the current session? A. bashhist 50 B. history 50 C. cat .bash_history D. tail -f .bash_history

B. The history command will display your command history, including commands from the current session. You can specify how many lines of history to display, as shown in the answer for this question. Note that .bash_history will not show the current session's history.

Which command can be run to determine the default priority for processes spawned by the current user? A. prio B. nice C. renice D. defpriority

B. The nice command, when run without arguments, will output the priority for the currently logged-in user, which is normally 0. The renice command can be used to change the priority of running processes. The other two commands shown as options for this question do not exist.

D. The fg command will bring a command to the foreground if it has been backgrounded with either & or with the bg command. You might background a command or process so that it continues running after logout.

B. While the ps auwx command combined with grep will provide information on the running Apache instances, it will provide much more information than is required or useful for this problem. The pgrep command provides only the process IDs and therefore meets the criteria presented in the question.

What is the default number of lines printed by the head and tail commands, respectively? A. 10 for head, 5 for tail B. 5 for head, 10 for tail C. 10 for both head and tail D. 3 for both head and tail

C. Both head and tail print 10 lines of output by default.

You have attempted to stop a process using its service command and also using the kill command. Which signal can be sent to the process using the kill command in order to force the process to end? A. -15 B. -f C. -9 D. -stop

C. The -9 option invokes SIGKILL, which will force the process to end. The -15 signal is the default, and the -f and -stop options do not exist. Certain commands may have been started with nohup, meaning that they are immune to hangups that might be issued with other signals. Note that you can kill a group of commands with the pkill command rather than individually with kill.

Which options to ls will produce output, including hidden (dot) files, in a list that is ordered such that the newest files are at the end of the output? A. -la B. -lat C. -latr D. -ltr

C. The -l option for ls produces long or listed output, and -t sorts by timestamp. The -r option reverses the order, and -a is needed to include hidden (dot) files, thus making answer C correct.

A. The g option, also known as global or greedy, will apply the matched operation to the entire line rather than just the first instance of the match. The other options apply as they would for a Perl Compatible Regular Expression.

C. The -l option provides the number of lines given as input. For example, wc -l /etc/passwd would print the number of lines in the /etc/passwd file. The other options given in this question are not valid for the wc command.

You're working with a large file in vi, and you need to search for instances of a string earlier in the file. Which key will search backward in the file? A. / B. h C. ? D. x

C. The ? will search backward in a file within vi. The / is used for searching forward. The h key will move the cursor to the left one character, and the x key will delete a character.

Which command will create an image of the /dev/sda1 disk partition and place that image into a file called output.img? A. dd if=sda of=/dev/sda1 B. dd if=output.img of=/dev/sda1 C. dd if=/dev/sda1 of=output.img D. echo /dev/sda1 > output.img

C. The dd command is used to create disk images, among other things. In this case, the input file is /dev/sda1 and the output file is output.img. It's also common to add the blocksize option by using the bs argument, such as bs=1M.

You have received a file that does not have a file extension. Which command can you run to help determine what type of file it might be? A. grep B. telnet C. file D. export

C. The file command can be used to determine which type of file is being used. This can be particularly helpful for files without extensions where you are unsure if you should view the contents of the file. Option A, grep, is used to look within files but would not be helpful in this case. The telnet and export commands are not used for this purpose.

You have backgrounded several tasks using &. Which command can be used to view the current list of running tasks that have been backgrounded? A. procs B. plist C. jobs D. free

C. The jobs built-in command shows the list of jobs running in the background. Its output includes a job number and the status of the job.

Which command can be used to kill all processes by using their name? A. killproc B. killname C. killall D. kill -f

C. The killall command is used to terminate processes using their name.

Which command is used to access documentation on a Linux computer for a given command? A. doc B. heredoc C. man D. manual

C. The man command displays documentation for the command given as the argument. The other options listed for this answer do not exist.

Which command will move all files with a .txt extension to the /tmp directory? A. mv txt* tmp B. move *txt /temp C. mv *.txt /tmp D. mv *.txt tmp

C. The mv command is used to move files, and *.txt will look for all files with a .txt extension. Note the fully qualified destination with a / preceding the name tmp.

When editing with vi, which command changes into insert mode and opens a new line below the current cursor location? A. f B. a C. o D. i

C. The o command opens a new line below the current cursor location. The a command begins an insert mode session at the character after the cursor, not the line. The i command begins an insert mode session at the current cursor location.

Which command will watch the Apache log at /var/log/httpd/access.log and continually scroll as new log entries are created? A. watch /var/log/httpd/access.log B. tail /var/log/httpd/access.log C. tail -f /var/log/httpd/access.log D. mon /var/log/httpd/access.log

C. The tail command provides the end portion of the file given as an argument. Adding the -f option will cause the output to update as new lines are added to the file being tailed.

Which of the following commands will send the contents of /etc/passwd to both stdout and a file called passwordfile? A. cat /etc/passwd > passwordfile B. var /etc/passwd | passwordfile C. cat /etc/passwd | tee passwordfile D. echo /etc/passwd | stdout > passwordfile

C. The tee command will send output both to stdout and to the specified file, thus making answer C correct. Option A will redirect output to the correct file but not to stdout simultaneously. The other answers will not work for this question. It should be noted that there is no specific formatting included with cat or tee. If formatting is needed for text processing, the fmt command can be used.

When working in the Bash shell, you need to redirect both stdout and stderr. Which of the following commands will redirect both stdout and stderr? A. 1>2 B. >2 C. 2>&1 D. >>

C. Within Bash, the number 1 represents stdout and 2 represents stderr. Redirecting both means combining them in the manner shown in option C.

Which option to both mv and cp will cause the command to prompt before overwriting files that already exist? A. -f B. -Z C. -r D. -i

D. The -i option will cause both cp and mv to be interactive, that is, prompt before overwriting. The -f option will force the command to run while -r is recursive.

What option is used to change the number of lines of output for the head and tail commands? A. -l B. -f C. -g D. -n

D. The -n option changes the number of lines of output for both head and tail to the number specified. The other options listed in this question are not valid for head, and the -f option follows a file with tail as the file grows.

Which command will find directories with names beginning with 2014 located beneath the current directory? A. find ./ -name "2014" B. find ./ -type d -name "2014" C. find / -type d "2014" D. find ./ -type d -name "2014*"

D. The -type option causes find to limit its search to directories only, whereas the - name option limits the names of returned elements. Note the use of the wildcard due to the phrasing of the question. Also note the use of ./ to denote beginning the search in the current directory.

What command is used to bring a command to foreground processing after it has been backgrounded with an &? A. bg B. fore C. 4g D. fg

D. The fg command will bring a command to the foreground if it has been backgrounded with either & or with the bg command. You might background a command or process so that it continues running after logout.

Users are reporting that various programs are crashing on the server. When examining logs, you see that certain processes are reporting out-of-memory conditions. Which command can you use to see the overall memory usage, including available swap space? A. tree B. pgrep C. uptime D. free

D. The free command displays overall memory usage for both RAM and swap and can be used to determine when additional memory might be needed.

You are debugging a configuration file and the daemon indicates there is a problem on line 932. Which of the following commands will prepend line numbers onto the file? A. lines B. wc -l C. newline D. nl

D. The nl command will prepend line numbers onto the file given as its argument. The output is then sent to stdout. Of the other answers, wc -l will print the number of lines in the file but not prepend those numbers onto each line, as was asked for in this question.

Which command prints your current directory? A. cwd B. curdur C. cd D. pwd

D. The pwd command prints the current working directory. The cd command changes directory.

You need to start a long-running process that requires a terminal and foreground processing. However, you cannot leave your terminal window open due to security restrictions. Which command will enable you to start the process and return at a later time to continue the session? A. fg B. bg C. kill D. screen

D. The screen command starts a new terminal that can be disconnected and reconnected as needed. Processes running from within the screen session do not know that they are running in a screen session, and therefore this meets the criteria needed to satisfy this question. The fg or bg commands will not meet the criteria, and the kill command will stop a process.

Assume that you're using the Bash shell and want to prevent output redirects from accidentally overwriting existing files. Which command and option can be used to invoke this behavior? A. setoutput -f B. overwrite=no C. overwrite -n D. set -C

D. The set command can be used for a variety of purposes to change how the shell environment works. One such option is -C, which prevents output redirection such as that done with > from overwriting a file if the file already exists.

Which of the following command lines would monitor a single process called nagios in a continuous manner? A. top -n 1 B. top -p 23 C. ps -nagios D. top -p`pidof nagios`

D. The top command is used to monitor continuously things like CPU and memory usage, and the -p option monitors a single process. By using the run quotes with the pidof command, the process ID is provided as input to the -p option.

Which of the following commands will print various information about the kernel and architecture, along with other details? A. info --sys B. man sys C. sysinfo D. uname -a

D. The uname command is used to print system information, and the -a option prints all information available to uname.

Which of the following egrep commands will examine /etc/passwd to find users who are using either /bin/bash or /usr/bin/zsh for their shell environment? A. grep sh /etc/passwd B. egrep '/*/.sh$' /etc/passwd C. grep '/*/.=sh$' /etc/passwd D. egrep '/*/.?sh$' /etc/passwd

D. Within a regular expression, * represents zero or more characters, and in this case the problem doesn't care whether a person is using /bin/bash or /usr/bin/zsh. Likewise, a . matches a single character, but in the case of bash and zsh we need to look at the first and optionally a second character, thus the ? making the second . optional. Finally, the $ anchors the pattern at the end of the string and is also key for this regular expression. The egrep command is equivalent to grep -e and fgrep is equivalent to grep -F, both of which are deprecated. For more information on regular expressions see regex(7).


Related study sets

laptops/ networking/troubleshooting

View Set

Exam 2 (Urinary/Kidney): Med-Surg Success

View Set

CHAPTER 44 - Hazardous Materials

View Set

Chapter 14. Managing the Marketing Mix: Product, Price, Place, and Promotion

View Set

BUS 110 Chapter 6. Entrepreneurship and starting a small business

View Set

Chapter 32: Disorders of Cardiac Function

View Set