NOS 120 Study Guide Ch 7 UPDATED ACTUAL QUESTIONS AND CORRECT
ANSWERS
When writing shell scripts and using an if statement to fi
determine whether a set of code should be executed,
what is the proper syntax to end the if construct? Answer:
________________________________
The subdirectory newdir does not currently exist in the mkdir newdir && cd newdir
current directory that you are in. Which of the following mkdir newdir; cd newdir
commands will create a new directory named newdir and
then change into that directory? (Choose two.)
Select one or more:
a. mkdir newdir; cd newdir
b. mkdir newdir || cd newdir
c. mkdir newdir >> cd newdir
d. mkdir newdir && cd newdir
How many times will the following loop execute as part until ctrl-c is used to terminate it
of a script:
#!/bin/bash
COUNTER=0
while [ $COUNTER -lt 7 ]
do
echo "hello world"
done
Select one:
a. 7
b. 0
c. 1
d. until ctrl-c is used to terminate it
, Which of the following will the split command do on a file It will split a file into new equally sized files that are 1/10th of the original file size.
when no other options are specified?
Select one:
a. It will split a file into new files that are 1 kilobyte each.
b. It will split a file into new equally sized files that are
1/10th of the original file size.
c. It will split a file into new files that are 1 megabyte each.
d. It will split a file into new files that are 1,000 lines each.
Match the file with the order in which the BASH shell Second
environment files are read: /etc/profile.d/*
/etc/profile, /etc/bashrc, ~/.bashrc, /etc/profile.d/* Fourth
~/.bashrc
Third
/etc/bashrc
First
/etc/profile
Which of the following is a valid method of running a ./myscript.sh
script named myscript.sh? (Choose two) source myscript.sh
Select one or more:
a. source myscript.sh
b. run myscript.sh
c. ./myscript.sh
d. exec ./myscript.sh
Which of the following would be the results of running 1 through 7 being displayed one number per line.
the command seq 7?
Select one:
a. 6 through 0 being displayed one number per line.
b. 7 through 1 being displayed one number per line.
c. 0 through 6 being displayed one number per line.
d. 1 through 7 being displayed one number per line.
Which of the following will look at the /etc/passwd file for grep root /etc/passwd | tee ~/root.txt
any lines containing the word root and display them out
to the screen while simultaneously writing the results to a
file?
Select one:
a. cat /etc/passwd | grep root >> ~/root.txt
b. grep root /etc/passwd | split ~/root.txt
c. cat /etc/passwd | grep root | merge ~/root.txt
d. grep root /etc/passwd | tee ~/root.txt
Which command can be used to create a new command alias showauth='tail -f /var/log/auth.log'
that will monitor the contents of auth.log as they get
added to the file?
Select one:
a. create showauth='tail -f /var/log/auth.log'
b. ln showauth='tail -f /var/log/auth.log'
c. new showauth as 'cat -f /var/log/auth.log'
d. alias showauth='tail -f /var/log/auth.log'
ANSWERS
When writing shell scripts and using an if statement to fi
determine whether a set of code should be executed,
what is the proper syntax to end the if construct? Answer:
________________________________
The subdirectory newdir does not currently exist in the mkdir newdir && cd newdir
current directory that you are in. Which of the following mkdir newdir; cd newdir
commands will create a new directory named newdir and
then change into that directory? (Choose two.)
Select one or more:
a. mkdir newdir; cd newdir
b. mkdir newdir || cd newdir
c. mkdir newdir >> cd newdir
d. mkdir newdir && cd newdir
How many times will the following loop execute as part until ctrl-c is used to terminate it
of a script:
#!/bin/bash
COUNTER=0
while [ $COUNTER -lt 7 ]
do
echo "hello world"
done
Select one:
a. 7
b. 0
c. 1
d. until ctrl-c is used to terminate it
, Which of the following will the split command do on a file It will split a file into new equally sized files that are 1/10th of the original file size.
when no other options are specified?
Select one:
a. It will split a file into new files that are 1 kilobyte each.
b. It will split a file into new equally sized files that are
1/10th of the original file size.
c. It will split a file into new files that are 1 megabyte each.
d. It will split a file into new files that are 1,000 lines each.
Match the file with the order in which the BASH shell Second
environment files are read: /etc/profile.d/*
/etc/profile, /etc/bashrc, ~/.bashrc, /etc/profile.d/* Fourth
~/.bashrc
Third
/etc/bashrc
First
/etc/profile
Which of the following is a valid method of running a ./myscript.sh
script named myscript.sh? (Choose two) source myscript.sh
Select one or more:
a. source myscript.sh
b. run myscript.sh
c. ./myscript.sh
d. exec ./myscript.sh
Which of the following would be the results of running 1 through 7 being displayed one number per line.
the command seq 7?
Select one:
a. 6 through 0 being displayed one number per line.
b. 7 through 1 being displayed one number per line.
c. 0 through 6 being displayed one number per line.
d. 1 through 7 being displayed one number per line.
Which of the following will look at the /etc/passwd file for grep root /etc/passwd | tee ~/root.txt
any lines containing the word root and display them out
to the screen while simultaneously writing the results to a
file?
Select one:
a. cat /etc/passwd | grep root >> ~/root.txt
b. grep root /etc/passwd | split ~/root.txt
c. cat /etc/passwd | grep root | merge ~/root.txt
d. grep root /etc/passwd | tee ~/root.txt
Which command can be used to create a new command alias showauth='tail -f /var/log/auth.log'
that will monitor the contents of auth.log as they get
added to the file?
Select one:
a. create showauth='tail -f /var/log/auth.log'
b. ln showauth='tail -f /var/log/auth.log'
c. new showauth as 'cat -f /var/log/auth.log'
d. alias showauth='tail -f /var/log/auth.log'