Sample questions
Question 1Easy
What does kill -9 <pid> do?
- Asks the process to exit gracefully by sending SIGTERM
- Restarts the process with the same arguments and PID
- Sends SIGKILL, which cannot be caught and ends it at once
- Pauses the process until it receives a SIGCONT signal
Answer: C. Sends SIGKILL, which cannot be caught and ends it at once
Explanation
Signal 9 is SIGKILL. Plain kill sends SIGTERM (15), which the process can handle to clean up first.
Step-by-step solution
- -9 is signal number 9, SIGKILL.
- SIGKILL cannot be caught or ignored.
- The kernel ends the process at once, with no cleanup.
Why the other options are wrong
- A. SIGTERM (15) is what plain kill sends.
- B. kill never restarts processes.
- D. Pausing is SIGSTOP.
Tip: kill = polite (15); kill -9 = forced.
Question 2Easy
What is the difference between > and >> in a shell?
- > overwrites the file, >> appends to it
- > appends, >> overwrites
- Both append
- > redirects input, >> redirects output
Answer: A. > overwrites the file, >> appends to it
Explanation
> truncates the target file before writing, while >> adds to the end.
Step-by-step solution
- > truncates the file, then writes.
- >> adds to the end of the file.
- Both create the file if needed.
Why the other options are wrong
- B. That reverses them.
- C. > overwrites.
- D. < redirects input; both > and >> redirect output.
Tip: One > overwrites; two >> append.
Question 3Easy
Which grep option makes the search case-insensitive?
- -i
- -v
- -c
- -r
Answer: A. -i
Explanation
-i ignores case. -v inverts the match, -c counts matching lines and -r searches recursively.
Step-by-step solution
- -i means ignore case.
- grep -i error matches error, Error and ERROR.
Why the other options are wrong
- B. -v inverts the match.
- C. -c counts matching lines.
- D. -r searches recursively.
Tip: -i ignore case, -v invert, -c count, -r recursive.
Question 4Easy
What is printed?
printf 'b\na\nc\n' | sort | head -n 1
- c
- a b c
- b
- a
Answer: D. a
Explanation
printf prints three lines, sort orders them alphabetically, and head -n 1 keeps only the first line.
Step-by-step solution
- printf outputs three lines: b, a, c.
- sort orders them: a, b, c.
- head -n 1 keeps only the first: a.
Why the other options are wrong
- A. c is last after sorting.
- B. head -n 1 keeps one line, not all three.
- C. b is first before sorting, but sort runs before head.
Tip: sort | head -n 1 = smallest line.
Question 5Easy
Which command prints the current working directory?
- whoami
- ls
- cd
- pwd
Answer: D. pwd
Explanation
pwd stands for print working directory.
Step-by-step solution
- pwd = print working directory.
- It shows the full path of the current directory.
Why the other options are wrong
- A. whoami prints the user name.
- B. ls lists files.
- C. cd changes directory.
Tip: Lost in the shell? pwd.
Question 6Easy
What is printed?
echo "root:x:0:0" | cut -d: -f3
- root
- x
- 0
- :
Answer: C. 0
Explanation
cut -d: splits on colons and -f3 selects the third field. Here both the third and fourth fields are 0.
Step-by-step solution
- -d: splits on colons: root | x | 0 | 0.
- -f3 picks the third field.
- That is 0.
Why the other options are wrong
- A. root is field 1.
- B. x is field 2.
- D. The delimiter itself is not printed.
Tip: cut -d<sep> -f<n> = nth field.
Question 7Medium
What is printed?
false
echo $?
- Nothing
- 1
- false
- 0
Answer: B. 1
Explanation
$? holds the exit status of the last command. false always exits with 1, and 0 would mean success.
Step-by-step solution
- false does nothing and exits with status 1.
- $? holds the last command's exit status.
- So echo prints 1.
Why the other options are wrong
- A. echo always prints something, here the status.
- C. $? is a number, not the command name.
- D. 0 means success; false always fails.
Tip: 0 = success; non-zero = failure.
Question 8Medium
After chmod 754 script.sh, what are the permissions?
rwxr-xr--rwxrwxr--rw-r-xr--rwxr--r-x
Answer: A. rwxr-xr--
Explanation
Each digit is a sum of read (4), write (2) and execute (1). 7 = rwx for the owner, 5 = r-x for the group, 4 = r-- for others.
Step-by-step solution
- Each digit is read 4 + write 2 + execute 1.
- 7 = 4+2+1 = rwx (owner).
- 5 = 4+1 = r-x (group); 4 = r-- (others).
- So rwxr-xr--.
Why the other options are wrong
- B. rwxrwxr-- is 774.
- C. rw-r-xr-- is 654.
- D. rwxr--r-x is 745.
Tip: r=4, w=2, x=1; add them per digit.
Question 9Hard
missing does not exist. Which command saves both the normal output and the error message into out.txt?
- ls missing 2>&1 > out.txt
- ls missing > out.txt 2>&1
- ls missing > out.txt
- ls missing 2> out.txt
Answer: B. ls missing > out.txt 2>&1
Explanation
Redirections are processed left to right. > out.txt first points stdout at the file, then 2>&1 points stderr wherever stdout now goes. In the other order, stderr is copied to the terminal before stdout is redirected.
Step-by-step solution
- Redirections run left to right.
- > out.txt points stdout at the file.
- 2>&1 then points stderr wherever stdout now goes: the file.
- So both outputs land in out.txt.
Why the other options are wrong
- A. Here 2>&1 copies stderr to the terminal first, then only stdout goes to the file.
- C. Only stdout is saved; the error still goes to the terminal.
- D. Only stderr is saved.
Tip: File first, then 2>&1.
Practise all 9 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →