🐧

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.

100 Questions 40 Beginner 40 Intermediate 20 Advanced
1

What does the "pwd" command do?

2

What does the "ls -l" command display?

3

What is the purpose of the "cd" command?

4

In Linux, what does the command "cat file.txt" do?

5

What does the "mkdir" command do?

6

What is the purpose of the "rm" command?

7

What does the command "chmod 755 file.sh" do?

8

What is the role of the "root" user in Linux?

9

What does the "sudo" command do?

10

What is a "shell" in Linux?

11

What does the shebang line "#!/bin/bash" at the top of a script indicate?

12

How do you make a shell script executable?

13

What is the purpose of an environment variable like "$PATH"?

14

What does the "grep" command do?

15

What is the purpose of the pipe symbol "|" in a shell command?

16

What is the difference between ">" and ">>" in shell redirection?

17

What does the "cp" command do?

18

What does the "mv" command do?

19

What is the home directory typically represented by in the shell?

20

What is the purpose of the "man" command?

21

What does the "echo" command do in a shell script?

22

How do you assign a value to a variable in a bash script?

23

How do you access the value of a variable named "name" in a bash script?

24

What is the purpose of the "touch" command?

25

What does the "ps" command display?

26

What is the purpose of the "kill" command?

27

What does an "if" statement check in a bash script, and how is its condition typically written?

28

What is the purpose of a "for" loop in a shell script?

29

What does the "wc -l" command count?

30

What is the purpose of the "exit" command (or "exit N") at the end of a script?

31

What is the difference between a "relative path" and an "absolute path"?

32

What does "Ctrl+C" typically do when a process is running in the foreground of a terminal?

33

What does "Ctrl+Z" do to a running foreground process?

34

What is the purpose of the "df -h" command?

35

What does the "tar" command commonly do?

36

What is the purpose of the "find" command?

37

What is the meaning of a "hidden file" in Linux, and how is it identified?

38

What does the "whoami" command output?

39

What does the "head" command do by default?

40

What is the purpose of the "history" command in bash?

1

What is the difference between a "hard link" and a "symbolic link" (symlink)?

2

What is the purpose of "process substitution" and "command substitution" in bash, e.g. the difference between `$(command)` and backticks?

3

What is the difference between "$@" and "$*" when referring to script arguments in bash?

4

What is the purpose of "set -e" in a bash script?

5

What is the purpose of "trap" in bash scripting?

6

What is the difference between "sed" and "awk", and what is each typically used for?

7

What does the command "ls -la | grep '^d'" accomplish?

8

What 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?

9

What is the purpose of "cron" and a "crontab" file?

10

What is the difference between "su" and "su -" (or "su -l")?

11

What is the purpose of "xargs"?

12

What is the difference between "/etc/passwd" and "/etc/shadow"?

13

What does the "&" symbol at the end of a command do in bash?

14

What is the purpose of "$?" in bash?

15

What is the difference between "while" and "until" loops in bash?

16

What is the purpose of "/dev/null"?

17

What is the difference between "file descriptors" 0, 1, and 2 in Unix-like systems?

18

What does the command "chown user:group file.txt" do?

19

What is the purpose of "alias" in bash, e.g. "alias ll='ls -la'"?

20

What is the purpose of "export" when used with a variable in bash, e.g. "export VAR=value"?

21

What is the difference between "*.txt" and ".*" as wildcard patterns in bash globbing?

22

What does the "uniq" command do, and what is a common gotcha when using it?

23

What is the purpose of "ssh-keygen" and public/private key authentication for SSH?

24

What is the purpose of "/etc/fstab"?

25

What does the command "ps aux | grep nginx" accomplish, and what is a common caveat?

26

What is the purpose of "background jobs" and the "nohup" command together, e.g. "nohup long_script.sh &"?

27

What is the purpose of "diff" command, and what does its typical output represent?

28

What is the difference between "$(( ))" (arithmetic expansion) and a regular variable expansion "$VAR" in bash?

29

What is the purpose of "umask" in Linux?

30

What is the difference between "TCP" and "UDP" as they relate to commands like "netstat" or "ss" showing open ports?

31

What is the purpose of "logrotate" in Linux system administration?

32

What is the difference between "killall" and "pkill"?

33

What is the purpose of the "tee" command?

34

What is the difference between "type" and "which" when locating a command?

35

What is the purpose of "rsync" and what makes it efficient for synchronizing files?

36

What does the "envsubst" or using "$VAR" inside a heredoc accomplish in shell scripting?

37

What is the purpose of "/etc/hosts" and how does it interact with DNS lookups?

38

What is the purpose of "watch" command, e.g. "watch -n 2 df -h"?

39

What is the significance of the "PATH" variable order, and what security risk can arise from including "." (current directory) in it?

40

What is the difference between "wget" and "curl" for downloading files from the command line?

1

How does the Linux kernel's "Out-Of-Memory (OOM) killer" decide which process to terminate when the system runs critically low on memory?

2

What is the difference between a "zombie" process and an "orphan" process?

3

How 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?

4

What is the purpose of "namespaces" in the Linux kernel, and how do they relate to containerization technologies like Docker?

5

What is the purpose of "cgroups" (control groups) in the Linux kernel?

6

What is "copy-on-write" (COW) in the context of the "fork()" system call, and why is it important for performance?

7

What is the significance of the "setuid" bit on an executable file, and what security risks does it introduce?

8

How does "bash" determine command precedence when a command name matches both an alias, a function, a builtin, and an executable in $PATH?

9

What is the purpose of "ulimit" in bash, and how does it relate to per-process resource limits enforced by the kernel?

10

What is the difference between "strace" and "ltrace", and what kind of debugging information does each provide?

11

What is the significance of the "noexec", "nosuid", and "nodev" mount options on a filesystem (e.g. for /tmp)?

12

How does "bash" perform word splitting and globbing, and in what order are these (along with other expansions) typically applied to a command line?

13

What is the purpose of the "/proc" virtual filesystem, and how might it be used to inspect a running process's open file descriptors?

14

What is the difference between "SIGTERM" and "SIGKILL", and why might a process fail to terminate even when sent SIGKILL?

15

What is the purpose of "LD_PRELOAD", and what security implications does it have?

16

How does the Linux page cache improve filesystem read/write performance, and what is the significance of commands like "sync" or the "fsync()" system call?

17

What is the purpose of "systemd" units and targets, and how do they differ from traditional SysV init scripts?

18

What is "kernel module" loading (e.g. via "insmod" or "modprobe"), and how does "modprobe" differ from "insmod"?

19

What is "DNS resolution order" as configured by "/etc/nsswitch.conf" and "/etc/resolv.conf", and how do they interact?

20

What is the significance of "file descriptor leaks" in long-running processes, and how might "lsof" help diagnose them?