Bash

Which of the three methods will copy the directory named "photo dir" recursively from the user's home directory to /backups?

bash cp -R "~/photo dir" /backups #method1 cp -R ~"/photo dir" /backups #method2 cp -R ~/"photo dir" /backups #method3

1.

None of the three methods will expand to the user's home directory. Only using `"$HOME/photo dir"`will be successful.

2.

Only method 1 will expand `"~/"` to the user's home directory and then append the quoted directory name that includes a space.

3.

Only method 2 will expand `"~/"` to the user's home directory and then append the quoted directory name that includes a space.

4.

Only method 3 will expand `"~/"` to the user's home directory and then append the quoted directory name that includes a space.

Q 1 / 71

Bash

If script.sh is run in the current directory, it will fail. Why?

bash $ ls -1 Beach photo1.jpg Photo1.jpg Photo2.jpg Script.sh $ cat script.sh for i in $(ls *.jpg); do mv $i ${i}.bak done

1.

ls: cannot access nonexistentfile: No such file or directory

2.

The for loop will split on word boundaries and Beach photo1.jpg has a space in it.

3.

The mv command will fail because the curly bracket is a special character in Bash and cannot be used in the names of files.

4.

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.

Q 2 / 71

Bash

To run a copy command in a subshell, which syntax would you use?

1.

`( command )`

2.

`sh command`

3.

`{ command; }`

4.

`(( command ))`

Q 3 / 71

Bash

Using "awk", what would the output of this command string be?

bash echo "1 2 3" | awk '{for (i=1; i<=NF; i++) s=s+$i};END {print s}'

1.

6

2.

123

3.

3

4.

600

Q 4 / 71

Bash

The command below will search the root filesystem for files named "finance.db". In this context, what information is being sent to /dev/null?

bash find / -name "finance.db" 1>results.txt 2>/dev/null

1.

the names of files that do not match finance.db

2.

information sent to the standard error-for example, errors that the find command displays as it runs

3.

the names of files that match finance.db

4.

information sent to the standard output-that is, the path to files the find command has located

Q 5 / 71

Bash

To permanently remove empty lines from a file called textfile, which command could you use?

1.

`sed -i '/^$/d' textfile`

2.

`sed '/^$/d' textfile`

3.

`cat textfile | sed '/^$/d`

4.

`sed -i 's/^$//' textfile`

Q 6 / 71

Bash

Assuming that user1 existed, what would be the result of this command string?

bash awk -F: '/user1/{print $1 "-" $3 "-" $6}' /etc/passwd

1.

It would show the username, UID, and home directory of user1 separated by colons.

2.

It would print the UID, GID, and home directory of user1 separated by hyphens.

3.

It would print the UID, comment, and home directory of user1 separated by hyphens.

4.

It would show the username, UID, and home directory of user1 separated by hyphens.

Q 7 / 71

Bash

What happens if you use the `"set -e"` in a Bash script?

1.

It will cause Bash to exit if a function or subshell returns a nonzero status code.

2.

It will cause Bash to exit if a conditional returns a non-zero status code.

3.

It will cause Bash to exit if local, declare, or typeset assignments return a nonzero status code.

4.

It will cause Bash to exit if a command, list of commands, compound command, or potentially a pipeline returns a nonzero status code.

Q 8 / 71

Bash

The **_** keyword pauses the script to get input from standard input.

1.

get

2.

argument

3.

read

4.

input

Q 9 / 71

Bash

If file.sql holds SQL statements to be executed, what will be in file.txt?

bash mysql < file.sql > file.txt

1.

a copy of the contents of file.sql

2.

an error indicating that this is invalid syntax

3.

the error output of the MySQL command

4.

the non-error output of the MySQL command

Q 10 / 71

Bash

How does the SUID or setuid affect executable commands?

1.

When the command creates files, they will be owned by the group owner of the command.

2.

The SUID bit allows anyone to execute the command no matter what other permissions are set.

3.

When the command is executed, its running privileges elevate to the user owner of the command.

4.

When the command is executed, its running privileges elevate to the group owner of the command.

Q 11 / 71

Bash

In order to extract text from the first column of file called textfile, which command would you use?

1.

`cat {$1,textfile}`

2.

`cat textfile | awk [print $1]`

3.

`cat textfile | awk '{print $1}'`

4.

`awk textfile {print $1}`

Q 12 / 71

Bash

What is the keyboard shortcut to call up the Bash history search as shown below?

bash (reverse-i-search)`':

1.

Esc + R

2.

Ctrl + H

3.

Ctrl + R

4.

Alt + R

Q 13 / 71

Bash

Which arithmetic expression will give the most precise answer?

1.

`var=$( expr 10 / 8 )`

2.

`(( var= 10 /8 ))`

3.

`var=$(( 10 / 8 ))`

4.

`var=$(echo 'scale=2; 10 / 8' | bc)`

Q 14 / 71

Bash

What is the result of this script?

bash txt=Penguins

1.

0, representing 'true', because the variable "txt" contains eight letters

2.

0, representing 'true', because everybody loves penguins!

3.

1, representing 'false', because the variable "txt" is longer than eight characters

4.

1, representing 'false', because the variable "txt" does not contain eight lowercase letters between a and z

Q 15 / 71

Bash

How would you change your Bash shell prompt to the following?

bash HAL>

1.

`SHELL="HAL>"`

2.

`SHELL="HAL>"`

3.

`export PS1="HAL>"`

4.

`PS1="HAL>"`

Q 16 / 71

Bash

What is the output of this code?

bash VAR="/var/www/html/website.com/html/" echo "${VAR#*/html}"

1.

`/website.com/html/`

2.

`/html/website.com/html/`

3.

`/var/www/html/website.com/`

4.

Nothing will be echoed on the screen.

Q 17 / 71

Bash

If prompted for text at the standard input, you can tell the command you're done entering text with what key combination?

1.

Ctrl + A (Windows) or Command + A (Mac)

2.

Ctrl + E (Windows) or Command + E (Mac)

3.

Ctrl + D (Windows) or Command + D (Mac)

4.

Ctrl + Z (Windows) or Command + Z (Mac)

Q 18 / 71

Bash

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?

1.

`#!/usr/bin/env bash`

2.

`~/usr/bin/env bash`

3.

`'$!/usr/bin/env bash`

4.

`#/usr/bin/env bash`

Q 19 / 71

Bash

What line of Bash script probably produced the output shown below?

bash The date is: Sun Mar 24 12:30:06 CST 2019!

1.

`echo "The date is: !"`

2.

`echo "The date is: date!"`

3.

`echo "The date is: (date)!"`

4.

`echo "The date is: $(date)!"`

Q 20 / 71

Bash

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.

bash A. /home/demo.sh B. ./demo.sh C. ~/demo.sh D. bash /home/demo.sh E. bash demo.sh

1.

B, C, E

2.

A, B, C

3.

C, D, E

4.

B, D, E

Q 21 / 71

Bash

How could you get a list of all .html files in your tree?

The second seems well, but will expand the * if there is any .html file on your working directory.

1.

`find . -type html`

2.

`find . -name *.html`

3.

`find *.html`

4.

`find . -name *.html -print`

Q 22 / 71

Bash

What would be in out.txt?

bash cat < in.txt > out.txt

1.

The output from the command line. By default STDIN comes from the keyboard.

2.

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.

3.

It would be the contents of in.txt.

4.

Nothing. The redirect will create a new empty file but there will not be any output from the cat command to redirect.

Q 23 / 71

Bash

What does this bash statement do?

bash (( $a == $b )) echo $?

1.

It loops between the values of `$a` and `$b`.

2.

It tests whether the values of variables `$a` and `$b` are equal.

3.

It returns `$b` if it is larger than `$a`.

4.

It returns `$a` if it is larger than `$b`.

Q 24 / 71

Bash

What do you use in a case statement to tell Bash that you're done with a specific test?

1.

`; ;`

2.

`: :`

3.

`done`

4.

`$$`

Q 25 / 71

Bash

What does the asterisk represent in this statement?

bash <em>#!/usr/bin/env bash</em> case $num in 1) echo "one" ; ; 2) echo "two" ; ; *) echo "a mystery" ; ; esac

1.

a case that matches any value, providing a default option if nothing else catches that value

2.

a case only for what happens when the asterisk character is passed into the script

3.

the action of all of the other cases combined together

4.

an action that is taken for any input, even if it matches a specified condition

Q 26 / 71

Bash

What Bash script will correctly create these files?

1.

`touch file{1+10}.txt`

2.

`touch file{1-10}.txt`

3.

`touch file{1..10}.txt`

4.

`touch file(1..10).txt`

Q 27 / 71

Bash

Which variable would you check to verify that the last command executed successfully?

1.

`$$`

2.

`$?`

3.

`$!`

4.

`$@`

Q 28 / 71

Bash

What is the output of this script?

bash #!/bin/bash fname=john john=thomas echo ${!fname}

1.

john

2.

thomas

3.

Syntax error

4.

blank

Q 29 / 71

Bash

What will be the output of this script?

![question](images/Q30/question.png) Here's a text based version of Q.30: bash ll .. ll | sed -e 's,file,text,g' -rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 . -rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 .. -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file1.file -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file2.file .. -rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 . -rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 .. -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file1.txt -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file2.txt .. -rw-r--r-- 1 frankmolev staff 68 Jun 3 19:30 . -rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 .. ..

1.

`A` ![A](images/Q30/A.png)

2.

`B` ![B](images/Q30/B.png)

3.

`C` ![C](images/Q30/C.png)

4.

`D` ![D](images/Q30/D.png)

5.

undefined

6.

undefined

7.

undefined

8.

undefined

9.

A

10.

B

11.

C

12.

D

13.

undefined

14.

undefined

15.

undefined

16.

undefined

Q 30 / 71

Bash

What is wrong with this script?

bash #!/bin/bash read -p "Enter your pet type." PET if [ $PET = dog ] ;then echo "You have a dog" fi

1.

If the value of PET doesn't match dog, the script will return a nonzero status code.

2.

There is nothing wrong with it. The condition checks the value of PET perfectly.

3.

It will fail if the user hits the Enter (Return) key without entering a pet name when prompted.

4.

The then statement needs to be on a separate line.

Q 31 / 71

Bash

How can you gather history together for multiple terminals?

1.

It just works by default.

2.

`history --shared`

3.

`history --combined`

4.

`shopt -s histappend`

Q 32 / 71

Bash

What is the difference between the $@ and $* variables?

1.

`$@` treats each quoted argument as a separate entity. `$*` treats the entire argument string as one entity.

2.

`$*` treats each quoted argument as a separate entity. `$@` treats the entire argument string as one entity.

3.

`$*` is used to count the arguments passed to a script, `$@` provides all arguments in one string.

4.

`$*` is the wildcard that includes all arguments with word splitting, `$@` holds the same data but in an array.

Q 33 / 71

Bash

Which command is being run in this script to check if file.txt exists?

bash if [ -f file.txt ]; then echo "file.txt exists" fi

1.

`/usr/bin/test`

2.

`/usr/bin/[`

3.

`the built-in [ command`

4.

`/usr/bin/[[`

Q 34 / 71

Bash

What will be the output of this script?

bash #!/bin/bash Linux=('Debian' 'Redhat' 'Ubuntu' 'Android' 'Fedora' 'Suse') x=3 Linux=(${Linux[@]:0:$x} ${Linux[@]:$(($x + 1))}) echo "${Linux[@]}"

1.

Debian Redhat Ubuntu Android Fedora Suse

2.

Android

3.

Fedora Suse

4.

Debian Redhat Ubuntu Fedora Suse

Q 35 / 71

Bash

Which file allows you to save modifications to the shell environment across sessions?

1.

`/etc/bash.conf`

2.

`~/.profile`

3.

`/etc/bashprofile`

4.

`~/profile`

Q 36 / 71

Bash

Given the listed permissions on data.txt is it possible that user2 could have read, write, and execute permissions on data.txt?

bash $ ls -l total 0

1.

undefined

2.

No, it's clear that user2 does not have read, write, and execute permissions.

3.

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`.

4.

It's possible that SELinux provides read, write, and execute permissions for user2 which are not visible with `ls -l`.

5.

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.

Q 37 / 71

Bash

What does this script accomplish?

bash #!/bin/bash declare -A ARRAY=([user1]=bob [user2]=ted [user3]=sally) KEYS=(${!ARRAY[@]}) for (( i=0; $i < ${#ARRAY[@]}; i+=1 ));do echo ${KEYS[$i]} - ${ARRAY[${KEYS[$i]}]} done

1.

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.

2.

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.

3.

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.

4.

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.

Q 38 / 71

Bash

What file would match the code below?

bash ls Hello[[.vertical-line.]]World

1.

Nothing, this is an invalid file glob.

2.

`Hello.vertical-line.World`

3.

`Hello[[.vertical-line.]]World`

4.

`Hello|World`

Q 39 / 71

Bash

What will be in out.txt?

bash ls nonexistentfile | grep "No such file" > out.txt

1.

No such file

2.

ls: cannot access nonexistentfile: No such file or directory

3.

Nothing, out.txt will be empty.

4.

It will be the contents of nonexistentfile.

Q 40 / 71

Bash

For the script to print "Is numeric" on screen, what would the user have to enter when prompted?

bash #!/bin/bash read -p "Enter text " var if [[ "$var" =~ "^[0-9]+$" ]];then echo "Is numeric" else echo "Is not numeric" fi The regex must not be quoted to work properly.

1.

Any sequence of characters that includes an integer

2.

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 except the text string `^[0-9]+$`

3.

One or more characters that only includes integers

4.

Due to a syntax error it is impossible to get the script to print "Is numeric"

Q 41 / 71

Bash

What will be the difference between the output on the screen and the contents of out.txt

bash mysql < file.sql > out.txt

1.

The output on the screen will be identical to out.txt

2.

There will be no output on the screen as it's being redirected to out.txt.

3.

The output on the screen will be identical to out.txt plus line numbers.

4.

The out.txt file will hold STDERR and STDOUT will go to the screen.

Q 42 / 71

Bash

How would you find the last copy command run in your history?

1.

history | find cp

2.

history | grep cp

3.

grep cp history

4.

cp history

Q 43 / 71

Bash

In order to write a script that iterates through the files in a directory, which of the following could you use?

1.

`bash for i in $(ls); do ... done`

2.

`bash for $(ls); do ... done`

3.

`bash for i in $ls; do ... done`

4.

`bash for $ls; do ... done`

Q 44 / 71

Bash

undefined

1.

|

2.

->

3.

#

4.

@

Q 45 / 71

Bash

In the script shown below, what is **greeting**?

bash <em>#!/usr/bin/env bash</em> greeting="Hello" echo $greeting, everybody!

1.

a command

2.

a loop

3.

a parameter

4.

a vairable

Q 46 / 71

Bash

Which statement checks whether the variable num is greater than five?

1.

`(( $num -gt 5 ))`

2.

`[[$num -lt 5]]`

3.

`(( $num > 5 ))`

4.

`$num > 5`

Q 47 / 71

Bash

Using Bash extended globbing, what will be the output of this command?

bash $ ls -l apple banana bananapple banapple pineapple strawberry $ shopt -s extglob $ ls -l @(ba*(na)|a+(p)le) bash apple banana bash apple banana bananapple banapple pineapple strawberry bash apple banana bananappple banapple pineapple bash apple banana bananapple banapple pineapple

1.

a

2.

b

3.

c

4.

d

Q 48 / 71

Bash

When used from within a script, which variable contains the name of the script?

1.

$0

2.

$# // number of positional parameters

3.

$$ // pid of the current shell

4.

$@ // array-like construct of all positional parameters

Q 49 / 71

Bash

What does the + signify at the end of the 10-digit file permissions on data.txt?

bash ls -l

1.

undefined

2.

There is an SELinux security context

3.

The sticky bit is set and the file will stay in RAM for speed

4.

There is an access control list

5.

There is an extended attribute such as immutable set

Q 50 / 71

Bash

In Bash, what does the comment below do?

bash cd -

1.

It moves you to the directory you were previously in.

2.

It moves you to your home folder (whatever your current working directory happens to be).

3.

It deletes the current directory

4.

It moves you one directory above your current working directory.

Q 51 / 71

Bash

What does this command do?

bash cat > notes -

1.

Accepts text from standard input and places it in "notes"

2.

Creates "notes" and exits

3.

Outputs the content of notes and deletes it

4.

Appends text to the existing "notes"

Q 52 / 71

Bash

What is the output of:

bash VAR="This old man came rolling" echo "${VAR//man/rolling}"

1.

This old rolling came rolling

2.

This old man came man

3.

This old man came rolling

4.

This old came

Q 53 / 71

Bash

The shell looks at the contents of a particular variable to identify which programs it can run. What is the name of this variable?

1.

$INCLUDE

2.

$PATH

3.

$PROGRAM

4.

$PATHS

Q 54 / 71

Bash

What does this command sequence do?

bash cat >notes -

1.

It creates an empty file called "notes" and then exits.

2.

It accepts text from the standard input and places it in the "notes" file.

3.

It appends text to an existing file called "notes."

4.

It outputs the contents of the "notes" file to the screen, and then deletes it.

Q 55 / 71

Bash

What is the output of this code?

bash VAR="This old man came rolling" echo "${VAR//man/rolling}"

1.

This old man came man

2.

This old man came rolling

3.

This old rolling came rolling

4.

This old came

Q 56 / 71

Bash

What statement would you use to print this in the console?

Shall we play a game? yesno

1.

`echo "Shall we play a game? yes/no"`

2.

`echo "Shall we play a game? yesno"`

3.

`echo "Shall we play a game? yesno"`

4.

`echo "Shall we play a game? yesno"`

Q 57 / 71

Bash

Given a directory with these seven files, what would remain after executing these commands?

bash archive.tar image1.gif image1.jpg image2.gif image2.jpg textfile1.txt textfile2.txt <code>shopt -s extglob rm !(*gif|*jpg)</code> bash archive.tar image1.gif image1.jpg image2.gif image2.jpg textfile1.txt textfile2.txt bash archive.tar textfile1.txt textfile2.txt All of this files will be deleted bash image1.gif image1.jpg image2.gif image2.jpg

1.

undefined

2.

a

3.

b

4.

c

5.

d:

Q 58 / 71

Bash

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?

bash #!/bin/bash var="8" if [ $var > 5 ]; then echo "$var is greater than 5" fi

1.

There will be no unexpected results. This script works as is and the output will be "8 is greater than 5".

2.

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".

3.

There will be a file in the current directory named 5.

4.

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

Q 59 / 71

Bash

What is the result of this script?

![question](images/Q60/question.png)

1.

It removes the directory 'foo' and the files contained within it.

2.

It removes all files except those in the current directory.

3.

It removes all files in the current directory.

4.

It removes all files except those in the 'foo' directory.

Q 60 / 71

Bash

Which one is true?

1.

SELinux policy rules are checked after DAC rules.

2.

SELinux policy rules are checked before DAC rules

3.

SELinux policy rules are never checked after DAC rules.

4.

None of these

Q 61 / 71

Bash

Which does the below command do?

bash w

1.

It doesn't display information about the users currently on the machine.

2.

It displays information about the users currently on the machine.

3.

It displays information about the users currently on the another machine.

4.

None of these

Q 62 / 71

Bash

Which sed options should you use to change the second-to-last instance of variable to rock so it would read:

A constant is a variable that is a rock that isn't variable bash var="A constant is a variable that is a variable that isn't variable" echo "$var" | sed _____

1.

s/(.*)variable(.*variable)/1rock2/'

2.

s/variable/rock/'

3.

s/variable/rock/g'

4.

s/(.*)variable(.*variable)/1rock2/'

Q 63 / 71

Bash

To make a Bash script named script.sh executable, what should you run?

1.

exec script.sh

2.

chmod +x script.sh

3.

bash script.sh

4.

source script.sh

Q 64 / 71

Bash

How can you create a shared terminal in a Bash shell?

1.

screen

2.

screen -X

3.

screen --shared

4.

terminal -shared

Q 65 / 71

Bash

Wich operator sends the output of ls to a file for later use??

1.

ls < filelist.txt

2.

ls ¦ filelist.txt

3.

ls > filelist.txt

4.

ls - filelist.txt

Q 66 / 71

Bash

When comparing items with case, what statement indicates an end to the evaluation block?

1.

stop

2.

esac

3.

done

4.

exit

Q 67 / 71

Bash

To run a group of commands without spawning a subshell, which syntax would you use?

1.

sh command1; command2

2.

{ command1; command2; }

3.

(( command1; command2 ))

4.

command1; command2 )

Q 68 / 71

Bash

What are the results of the command with a user named jon?

bash echo 'Hello, $(whoami)!'

1.

Hello, $(jon)!

2.

Hello, jon!

3.

Hello, $(whoami)!

4.

Hello, whoami!

Q 69 / 71

Bash

How can you copy a directory to another system with compression?

1.

tar -ssh user@192.158.1.1 /bin/newfile

2.

tar cvzf - /wwwdata | ssh root@192.168.1.201 "dd of=/backup/wwwdata.tar.gz"

3.

You can't compress the stream

4.

scp -r directory user@192.168.1.1:/tmp

Q 70 / 71

Bash

To assign the command `ls -lah` to the shortcut command `lh`, what command should you use?

1.

alias lh='ls -lah'

2.

link lh='ls -lah'

3.

alias 'ls -lah'=lh

4.

lh | ls -lah

Q 71 / 71