Unit 2 · Self-check
Unit 2 Self-Check Quiz
Twenty questions covering Linux architecture, the shell and command line, users and groups, permissions and access control, and the development environment. Each question can be expanded to reveal a model answer.
Questions
Multiple choice and short answer
Answer each question before expanding. The questions span all five lessons of Unit 2.
Question 1
Which of the following is the strictest definition of "Linux"?
Show answer
Question 2
A shell command is not found when you type it. Which of the following is the most likely cause?
Show answer
$PATH. The command might exist — for example, in the current directory or in a directory that is not on the path — but the shell cannot find it by name alone. To run a program that is not on the path, give an explicit path such as ./myprogram. A lack of execute permission usually produces a different error ("Permission denied"), and being in the wrong directory only matters for relative paths.
Question 3
What is the difference between > and >> in a shell command?
Show answer
> redirects standard output to a file, overwriting whatever the file previously contained. >> also redirects standard output but appends to the file instead of overwriting it. The distinction is important because > can destroy existing data. In error, cmd > log.txt may wipe out the previous log.
Question 4
A file has the mode 640. Which of the following is true?
Show answer
640 in octal is rw-r-----. The owner (6 = rw-) can read and write. The group (4 = r--) can read only. Others (0 = ---) have no access. This mode is common for files shared within a group but not exposed to the wider world. Note that execute permission is not granted to any category.
Question 5
With a umask of 027, what mode will a newly created directory have?
Show answer
~027 = 750 in octal. So the mode is 777 & 750 = 750, or rwxr-x---. The owner has full access; the group can read and traverse; others have no access. If the same umask were applied to a new file (base mode 666), the result would be 666 & 750 = 640 — read/write for the owner, read for the group.
Question 6
Why does the setuid bit on a binary represent a potential security risk?
Show answer
Question 7
What is the difference between a user's primary group and their supplementary groups?
Show answer
/etc/passwd. Every user has exactly one. Files the user creates are initially owned by this group, unless the parent directory has the setgid bit set. The supplementary groups are additional groups the user belongs to, listed in the members field of /etc/group. A user can belong to any number of them. When the kernel checks file access, it considers both the primary group and all supplementary groups.
Question 8
Which of the following is the correct command to add a user to a supplementary group without removing them from their existing groups?
Show answer
usermod -aG group user. The -G option without -a replaces the user's supplementary groups with the listed ones, potentially removing memberships the user needs. The -a flag appends instead of replacing. This is one of the most common mistakes in user administration.
Question 9
Which of the following commands would create a pipeline that counts the number of files in /etc?
Show answer
ls /etc | wc -l. The pipe character connects the output of ls to the input of wc, which counts lines. > would redirect to a file, && runs commands sequentially, and the last option has the redirection backward.
Question 10
What is the difference between the R and S state codes that appear in the STAT column of ps on Linux?
Show answer
R means the process is running or runnable — it is currently executing or on the ready queue, ready to execute. S means the process is in interruptible sleep — it is blocked on an event (typically I/O or a timer), and can be woken by a signal. The distinction corresponds to the Ready and Blocked states of the five-state model. A process in S cannot run until its event occurs; a process in R could run if given the CPU.
Question 11
What does the first line of a shell script #!/bin/bash do?
Show answer
./script.sh), the kernel reads the first two bytes. If they are #!, the rest of the line is interpreted as the path to an interpreter, and the kernel runs that interpreter with the script as its argument. Without a shebang, the kernel does not know how to execute the file directly, and the user must invoke the interpreter explicitly (bash script.sh).
Question 12
Which of the following is the correct way to make a shell script executable?
Show answer
chmod +x script.sh. The chmod command changes permissions; +x adds execute permission. With no explicit user specification, it applies to all categories (owner, group, others) as modified by the umask. This is the standard way to make a script runnable.
Question 13
What does the stat command report about a file, and how does this differ from the output of ls -l?
Show answer
stat reports the full metadata of a file: size in bytes, number of blocks allocated, inode number, device, link count, owner and group IDs, permissions in both octal and symbolic form, and three timestamps — access (atime), modification (mtime), and status change (ctime). ls -l shows a subset: permissions, link count, owner, group, size, and mtime. The two commands report the same underlying inode data, but stat is more complete, and it shows the octal mode directly rather than only the symbolic form.
Question 14
Which of the following commands will build a C program called prog from prog.c with the course-standard flags?
Show answer
-Wall -Wextra), includes debug symbols (-g), and specifies the output filename (-o prog). The first choice compiles but silently produces an executable named a.out and no warnings; the third reverses the source and output; the fourth is not a valid invocation for a simple C file.
Question 15
What is the purpose of strace?
Show answer
strace is the primary tool for connecting the system-call concept from Lesson 1.4 to real program behaviour.
Question 16
A shared project directory is set up with mode 2775 and owned by group projectx. What does the leading 2 do?
Show answer
2 in the leading position is the setgid bit. On a directory, setgid causes new files and subdirectories to inherit the directory's group rather than the creating user's primary group. This is essential for shared project directories: without it, a file created by one project member would be owned by that member's primary group, not projectx, and might be inaccessible to other members.
Question 17
Why are the man pages for section 2 (man 2 ...) particularly important in this course?
Show answer
fork, read, write, mmap, and every other kernel entry point a user program can invoke. These are the interfaces this course uses throughout, from the process-management labs to the memory-management and file-system labs. The system-call man pages describe arguments, return values, error codes, and subtle details (such as how fork uses copy-on-write) that no textbook covers. On Debian and Ubuntu, they are in a separate package (manpages-dev) and are not installed by default.
Question 18
Which of the following commands would print the last 20 lines of /var/log/syslog?
Show answer
tail -20 /var/log/syslog. The tail command prints the last lines of a file by default. With -20, it prints the last 20. head prints the first lines; less opens a pager that requires user interaction; cat prints the entire file. tail -f is a variant that keeps watching the file for new lines, useful for live logs.
Question 19
What is the difference between a hard link and a symbolic link?
Show answer
Question 20
Why does the course standardise on the GCC flags -Wall -Wextra -g?
Show answer
-Wall and -Wextra enable a broad set of compiler warnings. These catch real bugs — uninitialised variables, unintended assignments, format-string mismatches, unused parameters that might indicate incomplete refactoring — that would otherwise compile silently and behave unexpectedly. Warnings should be treated as bugs. -g includes debug symbols so that GDB can map machine state back to source lines, variables, and function names. Together, the three flags make debugging tractable, which matters especially for the concurrent and pointer-heavy code the course will cover in later modules. The standard applies to every laboratory and assignment.
Ready for the graded quiz?
Once you are comfortable with every question above, take the graded Unit 2 quiz in the LMS.