Questions and Answers
- Which of the three methods will copy the directory named "photo dir" recursively from the user's home directory to /backups?
- None of the three methods will expand to the user's home directory. Only using `"$HOME/photo dir"`will be successful.
- Only method 1 will expand `"~/"` to the user's home directory and then append the quoted directory name that includes a space.
- Only method 2 will expand `"~/"` to the user's home directory and then append the quoted directory name that includes a space.
- Only method 3 will expand `"~/"` to the user's home directory and then append the quoted directory name that includes a space.
- If script.sh is run in the current directory, it will fail. Why?
- ls: cannot access nonexistentfile: No such file or directory
- The for loop will split on word boundaries and Beach photo1.jpg has a space in it.
- The mv command will fail because the curly bracket is a special character in Bash and cannot be used in the names of files.
- Running script.sh will be successful as the ls command builds a list of files in the current directory and for loops through that list renaming files with a .bak extension.
- To run a copy command in a subshell, which syntax would you use?
- `( command )`
- `sh command`
- `{ command; }`
- `(( command ))`
- Using "awk", what would the output of this command string be?
- 6
- 123
- 3
- 600
- The command below will search the root filesystem for files named "finance.db". In this context, what information is being sent to /dev/null?
- the names of files that do not match finance.db
- information sent to the standard error-for example, errors that the find command displays as it runs
- the names of files that match finance.db
- information sent to the standard output-that is, the path to files the find command has located
- To permanently remove empty lines from a file called textfile, which command could you use?
- `sed -i '/^$/d' textfile`
- `sed '/^$/d' textfile`
- `cat textfile | sed '/^$/d`
- `sed -i 's/^$//' textfile`
- Assuming that user1 existed, what would be the result of this command string?
- It would show the username, UID, and home directory of user1 separated by colons.
- It would print the UID, GID, and home directory of user1 separated by hyphens.
- It would print the UID, comment, and home directory of user1 separated by hyphens.
- It would show the username, UID, and home directory of user1 separated by hyphens.
- What happens if you use the `"set -e"` in a Bash script?
- It will cause Bash to exit if a function or subshell returns a nonzero status code.
- It will cause Bash to exit if a conditional returns a non-zero status code.
- It will cause Bash to exit if local, declare, or typeset assignments return a nonzero status code.
- It will cause Bash to exit if a command, list of commands, compound command, or potentially a pipeline returns a nonzero status code.
- The **\_** keyword pauses the script to get input from standard input.
- get
- argument
- read
- input
- If file.sql holds SQL statements to be executed, what will be in file.txt?
- a copy of the contents of file.sql
- an error indicating that this is invalid syntax
- the error output of the MySQL command
- the non-error output of the MySQL command
- How does the SUID or setuid affect executable commands?
- When the command creates files, they will be owned by the group owner of the command.
- The SUID bit allows anyone to execute the command no matter what other permissions are set.
- When the command is executed, its running privileges elevate to the user owner of the command.
- When the command is executed, its running privileges elevate to the group owner of the command.
- In order to extract text from the first column of file called textfile, which command would you use?
- `cat {$1,textfile}`
- `cat textfile | awk [print $1]`
- `cat textfile | awk '{print $1}'`
- `awk textfile {print $1}`
- What is the keyboard shortcut to call up the Bash history search as shown below?
- Esc + R
- Ctrl + H
- Ctrl + R
- Alt + R
- Which arithmetic expression will give the most precise answer?
- `var=$( expr 10 / 8 )`
- `(( var= 10 /8 ))`
- `var=$(( 10 / 8 ))`
- `var=$(echo 'scale=2; 10 / 8' | bc)`
- What is the result of this script?
- 0, representing 'true', because the variable "txt" contains eight letters
- 0, representing 'true', because everybody loves penguins!
- 1, representing 'false', because the variable "txt" is longer than eight characters
- 1, representing 'false', because the variable "txt" does not contain eight lowercase letters between a and z
- How would you change your Bash shell prompt to the following?
- `SHELL="HAL\>"`
- `SHELL="HAL>"`
- `export PS1="HAL>"`
- `PS1="HAL\>"`
- What is the output of this code?
- `/website.com/html/`
- `/html/website.com/html/`
- `/var/www/html/website.com/`
- Nothing will be echoed on the screen.
- If prompted for text at the standard input, you can tell the command you're done entering text with what key combination?
- Ctrl + A (Windows) or Command + A (Mac)
- Ctrl + E (Windows) or Command + E (Mac)
- Ctrl + D (Windows) or Command + D (Mac)
- Ctrl + Z (Windows) or Command + Z (Mac)
- In order for a Bash script to be executed like an OS command, it should start with a shebang line. What does this look like?
- `#!/usr/bin/env bash`
- `~/usr/bin/env bash`
- `'$!/usr/bin/env bash`
- `#/usr/bin/env bash`
- What line of Bash script probably produced the output shown below?
- `echo "The date is: !"`
- `echo "The date is: date!"`
- `echo "The date is: (date)!"`
- `echo "The date is: $(date)!"`
- Suppose your current working directory is your home directory. How could you run the script demo.sh that is located in your home directory? Find three correct answers.
- B, C, E
- A, B, C
- C, D, E
- B, D, E
- How could you get a list of all .html files in your tree?
- `find . -type html`
- `find . -name *.html`
- `find *.html`
- `find . -name \*.html -print`
- What would be in out.txt?
- The output from the command line. By default STDIN comes from the keyboard.
- Nothing because you can't redirect from file (in.txt) to another file (out.txt). You can only redirect from a command to a file.
- It would be the contents of in.txt.
- Nothing. The redirect will create a new empty file but there will not be any output from the cat command to redirect.
- What does this bash statement do?
- It loops between the values of `$a` and `$b`.
- It tests whether the values of variables `$a` and `$b` are equal.
- It returns `$b` if it is larger than `$a`.
- It returns `$a` if it is larger than `$b`.
- What do you use in a case statement to tell Bash that you're done with a specific test?
- `; ;`
- `: :`
- `done`
- `$$`
- What does the asterisk represent in this statement?
- a case that matches any value, providing a default option if nothing else catches that value
- a case only for what happens when the asterisk character is passed into the script
- the action of all of the other cases combined together
- an action that is taken for any input, even if it matches a specified condition
- What Bash script will correctly create these files?
- `touch file{1+10}.txt`
- `touch file{1-10}.txt`
- `touch file{1..10}.txt`
- `touch file(1..10).txt`
- Which variable would you check to verify that the last command executed successfully?
- `$$`
- `$?`
- `$!`
- `$@`
- What is the output of this script?
- john
- thomas
- Syntax error
- blank
- What is wrong with this script?
- If the value of PET doesn't match dog, the script will return a nonzero status code.
- There is nothing wrong with it. The condition checks the value of PET perfectly.
- It will fail if the user hits the Enter (Return) key without entering a pet name when prompted.
- The then statement needs to be on a separate line.
- How can you gather history together for multiple terminals?
- It just works by default.
- `history --shared`
- `history --combined`
- `shopt -s histappend`
- What is the difference between the $@ and $\* variables?
- `$@` treats each quoted argument as a separate entity. `$*` treats the entire argument string as one entity.
- `$*` treats each quoted argument as a separate entity. `$@` treats the entire argument string as one entity.
- `$*` is used to count the arguments passed to a script, `$@` provides all arguments in one string.
- `$*` is the wildcard that includes all arguments with word splitting, `$@` holds the same data but in an array.
- Which command is being run in this script to check if file.txt exists?
- `/usr/bin/test`
- `/usr/bin/[`
- `the built-in [ command`
- `/usr/bin/[[`
- What will be the output of this script?
- Debian Redhat Ubuntu Android Fedora Suse
- Android
- Fedora Suse
- Debian Redhat Ubuntu Fedora Suse
- Which file allows you to save modifications to the shell environment across sessions?
- `/etc/bash.conf`
- `~/.profile`
- `/etc/bashprofile`
- `~/profile`
- Given the listed permissions on data.txt is it possible that user2 could have read, write, and execute permissions on data.txt?
- No, it's clear that user2 does not have read, write, and execute permissions.
- Yes, the `+` at the end of the 10-digit permission string signifies there's an access control list. This could possibly give user2 permissions not visible by `ls -l`.
- It's possible that SELinux provides read, write, and execute permissions for user2 which are not visible with `ls -l`.
- Yes, the `+` at the end of the 10-digit permission string signifies there's an extended attribute set. This could give user2 permissions to read, write, and execute data.txt.
- What does this script accomplish?
- It sorts the associative array named ARRAY and stores the results in an indexed array named KEYS. It then uses this sorted array to loop through the associative array ARRAY.
- Using a C-style for loop, it loops through the associative array named ARRAY using the associative array's keys and outputs both the key and values for each item.
- It creates an indexed array of the associative array named ARRAY. It then uses a C-style for loop and the indexed array to loop through all items in the associative array, outputting the key and value of each array item using the index number.
- It creates an associative array named ARRAY, which it loops through using a C-style for loop and the index numbers of each item in the associative array's keys, outputting the value of each item.
- What file would match the code below?
- Nothing, this is an invalid file glob.
- `Hello.vertical-line.World`
- `Hello[[.vertical-line.]]World`
- `Hello|World`
- What will be in out.txt?
- No such file
- ls: cannot access nonexistentfile: No such file or directory
- Nothing, out.txt will be empty.
- It will be the contents of nonexistentfile.
- For the script to print "Is numeric" on screen, what would the user have to enter when prompted?
- Any sequence of characters that includes an integer
- The user would have to enter the character sequence of `^[0-9]]+$` Only this will prove to be true and "Is numeric" would be printed on the screen due to incorrect syntax. By encapsulating the regular expression in double quotes every match will fail exce
- One or more characters that only includes integers
- Due to a syntax error it is impossible to get the script to print "Is numeric"
- What will be the difference between the output on the screen and the contents of out.txt
- The output on the screen will be identical to out.txt
- There will be no output on the screen as it's being redirected to out.txt.
- The output on the screen will be identical to out.txt plus line numbers.
- The out.txt file will hold STDERR and STDOUT will go to the screen.
- How would you find the last copy command run in your history?
- history | find cp
- history | grep cp
- grep cp history
- cp history
- In order to write a script that iterates through the files in a directory, which of the following could you use?
- `bash for i in $(ls); do ... done`
- `bash for $(ls); do ... done`
- `bash for i in $ls; do ... done`
- `bash for $ls; do ... done`
- When executing a command and passing the output of that command to another command, which character allows you to chain these commands together?
- |
- ->
- \#
- @
- In the script shown below, what is **greeting**?
- a command
- a loop
- a parameter
- a vairable
- Which statement checks whether the variable num is greater than five?
- `(( \$num -gt 5 ))`
- `[[$num -lt 5]]`
- `(( \$num > 5 ))`
- `\$num > 5`
- Using Bash extended globbing, what will be the output of this command?
- a
- b
- c
- d
- When used from within a script, which variable contains the name of the script?
- \$0
- \$# // number of positional parameters
- \$\$ // pid of the current shell
- \$@ // array-like construct of all positional parameters
- What does the + signify at the end of the 10-digit file permissions on data.txt?
- There is an SELinux security context
- The sticky bit is set and the file will stay in RAM for speed
- There is an access control list
- There is an extended attribute such as immutable set
- In Bash, what does the comment below do?
- It moves you to the directory you were previously in.
- It moves you to your home folder (whatever your current working directory happens to be).
- It deletes the current directory
- It moves you one directory above your current working directory.
- What does this command do?
- Accepts text from standard input and places it in "notes"
- Creates "notes" and exits
- Outputs the content of notes and deletes it
- Appends text to the existing "notes"
- What is the output of:
- This old rolling came rolling
- This old man came man
- This old man came rolling
- This old came
- The shell looks at the contents of a particular variable to identify which programs it can run. What is the name of this variable?
- $INCLUDE
- $PATH
- $PROGRAM
- $PATHS
- What statement would you use to print this in the console?
- `echo "Shall we play a game? yes/\no"`
- `echo "Shall we play a game\? yes\\no"`
- `echo "Shall we play a game? yes\\no"`
- `echo "Shall we play a game? yes\no"`
- Given a directory with these seven files, what would remain after executing these commands?
- a
- b
- c
- d:
- The code below seems to work and outputs "8 is greater than 5". However, what unexpected result will tell you it is not functioning properly?
- There will be no unexpected results. This script works as is and the output will be "8 is greater than 5".
- The comparison will not be able to handle floating-point numbers, as Bash only handles integers. So this example will output an error message if the value of $var is changed to "8.8".
- There will be a file in the current directory named 5.
- The variable $var is not quoted, which will lead to word splitting. This script will fail with a "unary operator expected" message if you change the value of
- What is the result of this script?
- It removes the directory 'foo' and the files contained within it.
- It removes all files except those in the current directory.
- It removes all files in the current directory.
- It removes all files except those in the 'foo' directory.
- Which one is true?
- SELinux policy rules are checked after DAC rules.
- SELinux policy rules are checked before DAC rules
- SELinux policy rules are never checked after DAC rules.
- None of these
- Which does the below command do?
- It doesn't display information about the users currently on the machine.
- It displays information about the users currently on the machine.
- It displays information about the users currently on the another machine.
- None of these
- Which sed options should you use to change the second-to-last instance of variable to rock so it would read:
- s/\(.*\)variable\(.*variable\)/\1rock\2/'
- s/variable/rock/'
- s/variable/rock/g'
- s/(.*\)variable\(.*variable\)/\1rock\2/'
- To make a Bash script named script.sh executable, what should you run?
- exec script.sh
- chmod +x script.sh
- bash script.sh
- source script.sh
- How can you create a shared terminal in a Bash shell?
- screen
- screen -X
- screen --shared
- terminal -shared
- Wich operator sends the output of ls to a file for later use?
- ls < filelist.txt
- ls ? filelist.txt
- ls > filelist.txt
- ls - filelist.txt
- When comparing items with case, what statement indicates an end to the evaluation block?
- stop
- esac
- done
- exit
- To run a group of commands without spawning a subshell, which syntax would you use?
- sh command1; command2
- { command1; command2; }
- (( command1; command2 ))
- command1; command2 )
- What are the results of the command with a user named jon?
- Hello, $(jon)!
- Hello, jon!
- Hello, $(whoami)!
- Hello, whoami!
- How can you copy a directory to another system with compression?
- tar -ssh user@192.158.1.1 /bin/newfile
- tar cvzf - /wwwdata | ssh root@192.168.1.201 "dd of=/backup/wwwdata.tar.gz"
- You can't compress the stream
- scp -r directory user@192.168.1.1:/tmp
- To assign the command `ls -lah` to the shortcut command `lh`, what command should you use?
- alias lh='ls -lah'
- link lh='ls -lah'
- alias 'ls -lah'=lh
- lh | ls -lah
- Which statement will print all of the fully qualified .cvs files in the home directory or subdirectories while not displaying any errors?
- find $USER_DIR -name "\*.csv" 2>/dev/null
- find $HOME -name "\*.csv" 1>/dev/null
- find $HOME -name "\*.csv" 2>/dev/null
- find HOME -name "\*.csv" 1>/dev/null
- In Bash, what does a # at the end of the default prompt string indicate?
- that the user is acting as root
- that the current working directory is the root of the file system
- that there are updates for the system available
- that the user is unprivileged
- What will be the output of this command?
- A
- B
- C
- D
- What is the output of this command sequence?
- A
- B
- C
- D
- What would be in out.txt?
- 123446789
- the hyphen symbol (-)
- 123456789
- the number 5, which is written to the file using echo
- Which variable contains the process ID (PID) of the script while it's running?
- $ID
- $#
- $@
- $$