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 $ 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
1.
`( command )`
2.
`sh command`
3.
`{ command; }`
4.
`(( command ))`
Q 3 / 71
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 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
1.
`sed -i '/^$/d' textfile`
2.
`sed '/^$/d' textfile`
3.
`cat textfile | sed '/^$/d`
4.
`sed -i 's/^$//' textfile`
Q 6 / 71
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
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
1.
get
2.
argument
3.
read
4.
input
Q 9 / 71
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
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
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 (reverse-i-search)`':
1.
Esc + R
2.
Ctrl + H
3.
Ctrl + R
4.
Alt + R
Q 13 / 71
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 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 HAL>
1.
`SHELL="HAL>"`
2.
`SHELL="HAL>"`
3.
`export PS1="HAL>"`
4.
`PS1="HAL>"`
Q 16 / 71
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
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
1.
`#!/usr/bin/env bash`
2.
`~/usr/bin/env bash`
3.
`'$!/usr/bin/env bash`
4.
`#/usr/bin/env bash`
Q 19 / 71
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 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
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 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 (( $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
1.
`; ;`
2.
`: :`
3.
`done`
4.
`$$`
Q 25 / 71
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
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
1.
`$$`
2.
`$?`
3.
`$!`
4.
`$@`
Q 28 / 71
bash #!/bin/bash fname=john john=thomas echo ${!fname}
1.
john
2.
thomas
3.
Syntax error
4.
blank
Q 29 / 71
![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 #!/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
1.
It just works by default.
2.
`history --shared`
3.
`history --combined`
4.
`shopt -s histappend`
Q 32 / 71
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 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 #!/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
1.
`/etc/bash.conf`
2.
`~/.profile`
3.
`/etc/bashprofile`
4.
`~/profile`
Q 36 / 71
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 #!/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 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 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 #!/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 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
1.
history | find cp
2.
history | grep cp
3.
grep cp history
4.
cp history
Q 43 / 71
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
1.
|
2.
->
3.
#
4.
@
Q 45 / 71
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
1.
`(( $num -gt 5 ))`
2.
`[[$num -lt 5]]`
3.
`(( $num > 5 ))`
4.
`$num > 5`
Q 47 / 71
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
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 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 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 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 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
1.
$INCLUDE
2.
$PATH
3.
$PROGRAM
4.
$PATHS
Q 54 / 71
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 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
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 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 #!/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
![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
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 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
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
1.
exec script.sh
2.
chmod +x script.sh
3.
bash script.sh
4.
source script.sh
Q 64 / 71
1.
screen
2.
screen -X
3.
screen --shared
4.
terminal -shared
Q 65 / 71
1.
ls < filelist.txt
2.
ls ¦ filelist.txt
3.
ls > filelist.txt
4.
ls - filelist.txt
Q 66 / 71
1.
stop
2.
esac
3.
done
4.
exit
Q 67 / 71
1.
sh command1; command2
2.
{ command1; command2; }
3.
(( command1; command2 ))
4.
command1; command2 )
Q 68 / 71
bash echo 'Hello, $(whoami)!'
1.
Hello, $(jon)!
2.
Hello, jon!
3.
Hello, $(whoami)!
4.
Hello, whoami!
Q 69 / 71
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
1.
alias lh='ls -lah'
2.
link lh='ls -lah'
3.
alias 'ls -lah'=lh
4.
lh | ls -lah
Q 71 / 71