Linux practice questions with answers
Practise Linux questions at your own pace: shell commands, permissions, pipes, processes, signals and troubleshooting. Pick an answer to see whether you are right and why. Nothing is timed or ranked here; for that, play the Daily Quiz at 4 PM IST.
Which command lists files including hidden ones, with details?
easy
- ls
- ls -la
- dir
- cat -a
Answer: B. ls -la
Explanation: -l gives the long format (permissions, owner, size, date) and -a includes dotfiles.
Which command shows the current directory?
easy
- cd
- pwd
- whoami
- ls
Answer: B. pwd
Explanation: pwd prints the working directory. whoami prints the current user.
Which command searches for text inside files?
easy
- find
- grep
- locate
- which
Answer: B. grep
Explanation: grep -rn "text" . searches recursively with line numbers. find searches for files by name, size or date.
What does chmod 755 script.sh set?
easy
- Everyone can read and write
- The owner can read, write and execute; group and others can read and execute
- Only the owner can read
- Nobody can execute
Answer: B. The owner can read, write and execute; group and others can read and execute
Explanation: 7 = rwx (4 + 2 + 1), 5 = r-x (4 + 1), for owner, group and others.
What does this pipeline print?
medium
printf "b\na\nb\nc\n" | sort | uniq -c | sort -rn | head -1- 2 b
- 1 a
- b
- a b c
Answer: A. 2 b
Explanation: sort groups duplicates, uniq -c counts them, sort -rn puts the biggest count first, head -1 keeps the top line: b appears twice.
What is the difference between > and >> in a shell?
medium
- None
- > overwrites the file; >> appends to it
- >> overwrites; > appends
- > is for errors only
Answer: B. > overwrites the file; >> appends to it
Explanation: 2> redirects standard error, and 2>&1 sends errors to the same place as standard output.
How do you find which process is listening on port 8080?
medium
- ps 8080
- lsof -i :8080 (or ss -ltnp)
- kill 8080
- top -p 8080
Answer: B. lsof -i :8080 (or ss -ltnp)
Explanation: lsof lists open files and sockets; ss is the modern replacement for netstat.
What does kill -9 do differently from kill?
medium
- Nothing
- kill sends SIGTERM, which a process can handle to shut down cleanly; kill -9 sends SIGKILL, which cannot be caught
- kill -9 restarts the process
- kill -9 only works for root
Answer: B. kill sends SIGTERM, which a process can handle to shut down cleanly; kill -9 sends SIGKILL, which cannot be caught
Explanation: Try SIGTERM first so the program can flush files and close connections. Use SIGKILL only when it hangs.
What does this print?
hard
echo "a b c" | awk '{print $2}'- a
- b
- c
- a b c
Answer: B. b
Explanation: awk splits each line into fields on whitespace; $2 is the second field. $0 is the whole line and $NF the last field.
A disk is full but du shows little usage. What is a common cause?
hard
- A broken du command
- A deleted file that a running process still holds open, so its space is not freed
- Too many directories
- The file system is read-only
Answer: B. A deleted file that a running process still holds open, so its space is not freed
Explanation: lsof +L1 lists deleted-but-open files. Restarting or signalling the process (e.g. to reopen its logs) frees the space.
What does the "load average" in top or uptime mean?
hard
- CPU temperature
- The average number of processes running or waiting to run (and, on Linux, in uninterruptible I/O) over 1, 5 and 15 minutes
- Memory used in GB
- Network traffic
Answer: B. The average number of processes running or waiting to run (and, on Linux, in uninterruptible I/O) over 1, 5 and 15 minutes
Explanation: Compare it with the number of CPU cores: a load of 8 on a 4-core machine means work is queuing.
Which are true about file permissions and ownership? (Select all that apply)
hard
- chown changes a file's owner
- The execute bit on a directory lets you enter it (cd)
- sudo runs a command with another user's (usually root's) privileges
- chmod 777 is a safe default for web servers
Answer: A. chown changes a file's owner; B. The execute bit on a directory lets you enter it (cd); C. sudo runs a command with another user's (usually root's) privileges
Explanation: 777 lets any user change the files: a common security hole. Give the least permission that works.