010-160 Linux Command Line & Shell Scripting 3 — Questions and Answers
Question 1: What does the chmod 755 filename command set as permissions?
- Owner: rwx, Group: r-x, Others: r-x (Correct answer)
- Owner: rwx, Group: rwx, Others: rwx
- Owner: rw-, Group: r--, Others: r--
- Owner: rwx, Group: rw-, Others: r--
Correct answer: Owner: rwx, Group: r-x, Others: r-x
7=rwx for owner, 5=r-x for group, 5=r-x for others.
Question 2: Which command shows the manual page for the ls command?
- help ls
- info ls --manual
- man ls (Correct answer)
- ls --help-full
Correct answer: man ls
The man command opens the manual page for any installed command.
Question 3: In bash, how do you define a function named greet?
- function greet() { ... } (Correct answer)
- def greet() { ... }
- greet = function() { ... }
- sub greet { ... }
Correct answer: function greet() { ... }
The bash syntax for a function is: function name() { commands; } or name() { commands; }.
Question 4: What does the command wc -l file.txt report?
- Word count
- Character count
- Line count (Correct answer)
- File size in bytes
Correct answer: Line count
wc -l counts the number of newline characters, effectively reporting the number of lines.
Question 5: Which command removes an alias named ll that was set in the current shell session?
- delete alias ll
- rm alias ll
- unalias ll (Correct answer)
- alias -d ll
Correct answer: unalias ll
The unalias command removes a previously defined alias from the current shell.
Question 6: What does the semicolon ; do when placed between two commands on the same line?
- Runs both commands only if the first succeeds
- Runs both commands regardless of the first command's exit status (Correct answer)
- Runs the second command in the background
- Creates a logical OR between the two commands
Correct answer: Runs both commands regardless of the first command's exit status
A semicolon is a simple command separator; the second command always runs after the first finishes.
Question 7: Which of these is a valid way to read user input into a variable named NAME in bash?
- input NAME
- NAME = read
- read NAME (Correct answer)
- get $NAME
Correct answer: read NAME
The read built-in reads a line from stdin and stores it in the given variable.
What does the chmod 755 filename command set as permissions?