Linux Fundamentals HW 7
Match the file with the order in which the BASH shell environment files are read:
First: /etc/profile Second: /etc/profile.d/ Third: /etc/bashrc Fourth: ~/.bashrc
Which of the following files can you add filenames to so that the git add * command will not stage them? A) .gitignore B) .gitnopush C) .ignore D) .nopush
A) .gitignore
Which of the following files is always executed immediately after any user logs in to a Linux system and receives a BASH shell? A) /etc/profile B) ~/.bash_profile C) ~/.bash_login D) ~/.profile
A) /etc/profile
Which of the following commands can be used to create a BASH variable named CREATOR with the value of Torvalds? A) CREATOR="Torvalds" B) set $CREATOR = "Torvalds" C) CREATOR = "Torvalds" D) var CREATOR as "Torvalds"
A) CREATOR="Torvalds"
What does &> accomplish when entered on the command line after a command? A) It redirects both stderr and stdout to the same location. B) It does not accomplish anything. C) It redirects stderr and stdin to the same location. D) It appends stdout to a file.
A) It redirects both stderr and stdout to the same location.
You attempt to perform the git commit -m "Added listdir function" but the command fails. What are possible reasons for the failure? (Choose all that apply.) A) The user performing the commit has not set their Git user information. B) No files were added to the Git index beforehand. C) The user performing the commit is not running the command from within the Git repo directory. D) The master branch was not specified within the command itself.
A) The user performing the commit has not set their Git user information. B) No files were added to the Git index beforehand. C) The user performing the commit is not running the command from within the Git repo directory.
A for construct is a loop construct that processes a specified list of objects. As a result, it is executed as long as there are remaining objects to process. True or False? A) True B) False
A) True
Both aliases and functions can be used to store commands that can be executed, but functions can also accept positional parameters. True or False? A) True B) False
A) True
The sed and awk commands are filter commands commonly used to format data within a pipe. True or False? A) True B) False
A) True
Which of the following lines can be used to perform command substitution within a shell script? (Choose all that apply.) A) `command` B) ${command} C) ${!command} D) $(command)
A) `command` D) $(command)
Which of the following commands will send the output of the cat command to the grep command to be filtered? A) cat /etc/passwd | grep jsmith B) cat /etc/passwd > grep jsmith C) cat /etc/passwd >> grep jsmith D) cat /etc/passwd @ grep jsmith
A) cat /etc/passwd | grep jsmith
Which of the following will display the message welcome home if the cd /home/user1 command is successfully executed? A) cd /home/user1 && echo "welcome home" B) cat "welcome home" || cd /home/user1 C) cd /home/user1 || cat "welcome home" D) echo "welcome home" && cd /home/user1
A) cd /home/user1 && echo "welcome home"
You have just created a variable named CREATOR. Which of the following commands will display the contents of the variable to standard output? A) echo $CREATOR B) print CREATOR C) echo CREATOR D) disp $CREATOR
A) echo $CREATOR
Which command can be used to download an updated copy of the master branch from the original Git repository? A) git pull origin master B) git pull original master C) git pull master original D) git pull master origin
A) git pull origin master
Which construct can be used in a shell script to read stdin and place it in a variable? A) read B) sum C) verify D) test
A) read
Because stderr and stdout represent the results of a command and stdin represents the input required for a command, only stderr and stdout can be redirected to/from a file. True or False? A) True B) False
B) False
Consider the following shell script: echo -e "What is your favorite color?--> \c" read REPLY if [ "$REPLY" = "red" -o "$REPLY" = "blue" ] then echo "The answer is red or blue." else echo "The answer is not red nor blue." fi What would be displayed if a user executes this shell script and answers Blue when prompted? A) The answer is red or blue. B) The answer is not red nor blue. C) The code would cause an error. D) The answer is red or blue. The answer is no
B) The answer is not red nor blue.
Which command can be used to create a new command that will monitor the contents of auth.log as they get added to the file? A) create showauth='tail -f /var/log/auth.log' B) alias showauth='tail -f /var/log/auth.log' C) new showauth as 'cat -f /var/log/auth.log' D) ln showauth='tail -f /var/log/auth.log'
B) alias showauth='tail -f /var/log/auth.log'
The current value for the HOME variable is displayed by which of the following commands? (Choose all that apply.) A) echo HOME= B) echo ~ C) echo $HOME D) echo ls HOME
B) echo ~ C) echo $HOME
Which of the following commands will count the number of lines in a file named data.csv? A) lc data.csv B) wc -l data.csv C) lines data.csv D) count -l data.csv
B) wc -l data.csv
Which of the following variables could access the value "/etc" within the sample shell script, if the sample shell script was executed using the bash sample /var /etc /bin command? A) $0 B) $1 C) $2 D) $3
C) $2
Which of the following would be the results of running the command seq 7? A) 6 through 0 being displayed one number per line. B) 7 through 1 being displayed one number per line. C) 1 through 7 being displayed one number per line. D) 0 through 6 being displayed one number per line.
C) 1 through 7 being displayed one number per line.
Which of the following represents stderr at the command line when used for redirection? A) 0 B) 1 C) 2 D) 3
C) 2
What would be the effect of using the alias command to make an alias for the date command named cat in honor of your favorite pet? A) It cannot be done as there already is an environment variable cat associated with the cat command. B) It cannot be done because there already is a command cat on the system. C) When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead. D) There is no effect until the alias is imported because it is a us
C) When you use the cat command at the command prompt with the intention of viewing a text file, the date appears instead.
You have redirected stderr to a file called Errors. You view the contents of this file afterward and notice that there are six error messages. After repeating the procedure, you notice that there are only two error messages in this file. Why? A) After you open the file and view the contents, the contents are lost. B) The system generated different stdout. C) You did not append the stderr to the Error file, and, as a result, it was overwritten when the command was run a second time. D) You must
C) You did not append the stderr to the Error file, and, as a result, it was overwritten when the command was run a second time.
Which of the following is the common escape sequence to display a horizontal tab using the echo command? A) \tab B) ?tab C) \t D) %tab
C) \t
Which of the following results would be created by the command sequence: echo 'apple banana carrot dog elephant' | while read a b c; do echo result: $c $b $a; done A) elephant dog carrot B) apple banana carrot dog elephant C) carrot dog elephant banana apple D) carrot dog elephant apple banana
C) carrot dog elephant banana apple
Which of the following commands will display the exit status of the last command used in the BASH shell? A) echo $status B) echo $exit C) echo $? D) echo $!
C) echo $?
Before a user-defined variable can be used by processes that run in subshells, that variable must be __________. A) imported B) validated by running the env command C) exported D) redirected to the BASH shell
C) exported
Which of the following commands should you use to specify that you want to use Git for version tracking on them? A) git version B) git track C) git add D) git new
C) git add
Which of the following will look at the /etc/passwd file for any lines containing the word root and display them out to the screen while simultaneously writing the results to a file? A) cat /etc/passwd | grep root | merge ~/root.txt B) cat /etc/passwd | grep root >> ~/root.txt C) grep root /etc/passwd | tee ~/root.txt D) grep root /etc/passwd | split ~/root.txt
C) grep root /etc/passwd | tee ~/root.txt
Which of the following constructs can be used in a shell script to determine whether two values are equal and if so run another set of commands? A) when B) where C) if D) comp
C) if
Which of the following commands will display the output of a file while also displaying a line number at the left side of each line for the /etc/passwd file? A) numbers /etc/passwd B) wc -l /etc/passwd C) nl /etc/passwd D) ln /etc/passwd
C) nl /etc/passwd
Which command could you use to see a list of all environment and user-defined shell variables as well as their current values? A) ls /var B) env C) set D) echo
C) set
Which of the following operators reverses the meaning of a test statement? A) #! B) -o C) -a D) !
D) !
Which of the following characters can be entered at the beginning of a line in a shell script to ensure that line is recognized as a comment rather than try to execute it? A) $ B) > C) % D) #
D) #
Which of the following will take output from a command and append it to the end of a file? A) < B) << C) > D) >>
D) >>
How do you indicate a comment line in a shell script? A) There are no comment lines in a shell script. B) Begin the line with #!. C) Begin the line with !. D) Begin the line with #.
D) Begin the line with #.
Which of the following will the split command do on a file when no other options are specified? A) It will split a file into new files that are 1 kilobyte each. B) It will split a file into new files that are 1 megabyte each. C) It will split a file into new equally sized files that are 1/10th of the original file size. D) It will split a file into new files that are 1,000 lines each.
D) It will split a file into new files that are 1,000 lines each.
Every if construct begins with if and must be terminated with? A) end B) endif C) stop D) fi
D) fi
Which of the following commands will display the contents of the /etc/passwd file in alphanumerical order? A) cat --sort /etc/passwd B) cat -s /etc/passwd C) sed /etc/passwd D) sort /etc/passwd
D) sort /etc/passwd
An alias has previously been created named showauth. Which of the following commands can be used to get rid of that alias? A) alias -d showauth B) ualias shoauth C) noalias showauth D) unalias showauth
D) unalias showauth
When writing shell scripts and using an if statement to determine whether a set of code should be executed, what is the proper syntax to end the if construct? ___________
fi