Linux & Shell Scripting MCQ
Test your Linux and Shell Scripting knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.
What does the "pwd" command do?
2What does the "ls -l" command display?
3What is the purpose of the "cd" command?
4In Linux, what does the command "cat file.txt" do?
5What does the "mkdir" command do?
6What is the purpose of the "rm" command?
7What does the command "chmod 755 file.sh" do?
8What is the role of the "root" user in Linux?
9What does the "sudo" command do?
10What is a "shell" in Linux?
11What does the shebang line "#!/bin/bash" at the top of a script indicate?
12How do you make a shell script executable?
13What is the purpose of an environment variable like "$PATH"?
14What does the "grep" command do?
15What is the purpose of the pipe symbol "|" in a shell command?
16What is the difference between ">" and ">>" in shell redirection?
17What does the "cp" command do?
18What does the "mv" command do?
19What is the home directory typically represented by in the shell?
20What is the purpose of the "man" command?
21What does the "echo" command do in a shell script?
22How do you assign a value to a variable in a bash script?
23How do you access the value of a variable named "name" in a bash script?
24What is the purpose of the "touch" command?
25What does the "ps" command display?
26What is the purpose of the "kill" command?
27What does an "if" statement check in a bash script, and how is its condition typically written?
28What is the purpose of a "for" loop in a shell script?
29What does the "wc -l" command count?
30What is the purpose of the "exit" command (or "exit N") at the end of a script?
31What is the difference between a "relative path" and an "absolute path"?
32What does "Ctrl+C" typically do when a process is running in the foreground of a terminal?
33What does "Ctrl+Z" do to a running foreground process?
34What is the purpose of the "df -h" command?
35What does the "tar" command commonly do?
36What is the purpose of the "find" command?
37What is the meaning of a "hidden file" in Linux, and how is it identified?
38What does the "whoami" command output?
39What does the "head" command do by default?
40What is the purpose of the "history" command in bash?
What is the difference between a "hard link" and a "symbolic link" (symlink)?
2What is the purpose of "process substitution" and "command substitution" in bash, e.g. the difference between `$(command)` and backticks?
3What is the difference between "$@" and "$*" when referring to script arguments in bash?
4What is the purpose of "set -e" in a bash script?
5What is the purpose of "trap" in bash scripting?
6What is the difference between "sed" and "awk", and what is each typically used for?
7What does the command "ls -la | grep '^d'" accomplish?
8What is the difference between a "soft link limit" issue caused by symlink loops, and how does "find" or "cp" typically handle such loops by default?
9What is the purpose of "cron" and a "crontab" file?
10What is the difference between "su" and "su -" (or "su -l")?
11What is the purpose of "xargs"?
12What is the difference between "/etc/passwd" and "/etc/shadow"?
13What does the "&" symbol at the end of a command do in bash?
14What is the purpose of "$?" in bash?
15What is the difference between "while" and "until" loops in bash?
16What is the purpose of "/dev/null"?
17What is the difference between "file descriptors" 0, 1, and 2 in Unix-like systems?
18What does the command "chown user:group file.txt" do?
19What is the purpose of "alias" in bash, e.g. "alias ll='ls -la'"?
20What is the purpose of "export" when used with a variable in bash, e.g. "export VAR=value"?
21What is the difference between "*.txt" and ".*" as wildcard patterns in bash globbing?
22What does the "uniq" command do, and what is a common gotcha when using it?
23What is the purpose of "ssh-keygen" and public/private key authentication for SSH?
24What is the purpose of "/etc/fstab"?
25What does the command "ps aux | grep nginx" accomplish, and what is a common caveat?
26What is the purpose of "background jobs" and the "nohup" command together, e.g. "nohup long_script.sh &"?
27What is the purpose of "diff" command, and what does its typical output represent?
28What is the difference between "$(( ))" (arithmetic expansion) and a regular variable expansion "$VAR" in bash?
29What is the purpose of "umask" in Linux?
30What is the difference between "TCP" and "UDP" as they relate to commands like "netstat" or "ss" showing open ports?
31What is the purpose of "logrotate" in Linux system administration?
32What is the difference between "killall" and "pkill"?
33What is the purpose of the "tee" command?
34What is the difference between "type" and "which" when locating a command?
35What is the purpose of "rsync" and what makes it efficient for synchronizing files?
36What does the "envsubst" or using "$VAR" inside a heredoc accomplish in shell scripting?
37What is the purpose of "/etc/hosts" and how does it interact with DNS lookups?
38What is the purpose of "watch" command, e.g. "watch -n 2 df -h"?
39What is the significance of the "PATH" variable order, and what security risk can arise from including "." (current directory) in it?
40What is the difference between "wget" and "curl" for downloading files from the command line?
How does the Linux kernel's "Out-Of-Memory (OOM) killer" decide which process to terminate when the system runs critically low on memory?
2What is the difference between a "zombie" process and an "orphan" process?
3How do "inodes" relate to files in a Linux filesystem, and what happens to an inode when a file is deleted while a process still has it open?
4What is the purpose of "namespaces" in the Linux kernel, and how do they relate to containerization technologies like Docker?
5What is the purpose of "cgroups" (control groups) in the Linux kernel?
6What is "copy-on-write" (COW) in the context of the "fork()" system call, and why is it important for performance?
7What is the significance of the "setuid" bit on an executable file, and what security risks does it introduce?
8How does "bash" determine command precedence when a command name matches both an alias, a function, a builtin, and an executable in $PATH?
9What is the purpose of "ulimit" in bash, and how does it relate to per-process resource limits enforced by the kernel?
10What is the difference between "strace" and "ltrace", and what kind of debugging information does each provide?
11What is the significance of the "noexec", "nosuid", and "nodev" mount options on a filesystem (e.g. for /tmp)?
12How does "bash" perform word splitting and globbing, and in what order are these (along with other expansions) typically applied to a command line?
13What is the purpose of the "/proc" virtual filesystem, and how might it be used to inspect a running process's open file descriptors?
14What is the difference between "SIGTERM" and "SIGKILL", and why might a process fail to terminate even when sent SIGKILL?
15What is the purpose of "LD_PRELOAD", and what security implications does it have?
16How does the Linux page cache improve filesystem read/write performance, and what is the significance of commands like "sync" or the "fsync()" system call?
17What is the purpose of "systemd" units and targets, and how do they differ from traditional SysV init scripts?
18What is "kernel module" loading (e.g. via "insmod" or "modprobe"), and how does "modprobe" differ from "insmod"?
19What is "DNS resolution order" as configured by "/etc/nsswitch.conf" and "/etc/resolv.conf", and how do they interact?
20What is the significance of "file descriptor leaks" in long-running processes, and how might "lsof" help diagnose them?