NEOCODE

Linux Administration MCQs

🐧 Basic Linux Tasks

1. Which Linux philosophy encourages building small, focused programs that do one thing well?

Correct Answer: d) Unix philosophy

Explanation:
The Unix philosophy emphasizes building simple, short, clear, modular, and extensible code that can be easily maintained and repurposed. It promotes creating programs that do one thing well rather than complex multi-purpose tools.
Short Trick: Remember "Do One Thing and Do It Well" (DOTADIW).

2. Which command would you use to display a list of files in the current directory with detailed information including permissions?

Correct Answer: b) ls -l

Explanation:
The "ls -l" command provides a long listing format that shows detailed information including permissions, number of links, owner, group, size, and timestamp for each file and directory.
Short Trick: -l stands for "long format."

3. How would you access the manual page for the chmod command?

Correct Answer: c) man chmod

Explanation:
The "man" command followed by a command name displays the manual page for that command. "man chmod" shows detailed documentation on the chmod command's usage, options, and examples.
Short Trick: "man" is short for "manual."

4. Which command displays your current working directory?

Correct Answer: a) pwd

Explanation:
The "pwd" command prints the full pathname of the current working directory to standard output.
Short Trick: "pwd" stands for "Print Working Directory."

5. Which Linux concept allows you to treat hardware devices as if they were files?

Correct Answer: b) Everything is a file

Explanation:
"Everything is a file" is a core Linux/Unix philosophy. In Linux, hardware devices, directories, processes, and even network sockets are treated as files, which provides a consistent interface for interacting with system resources.
Short Trick: Think of /dev directory, where hardware devices are represented as files.

6. Which command would you use to search for a specific text string within files?

Correct Answer: c) grep

Explanation:
The "grep" command searches for patterns in text. It can search through files for specific text strings and display matching lines.
Short Trick: "grep" originally stood for "Global Regular Expression Print."

👥 Managing Users and Groups

7. Which command allows a regular user to execute commands with superuser privileges temporarily?

Correct Answer: b) sudo

Explanation:
The "sudo" command allows authorized users to execute commands as another user, typically the superuser (root), according to security policies configured in the /etc/sudoers file.
Short Trick: "sudo" stands for "Superuser Do."

8. Which file contains the list of all users on a Linux system?

Correct Answer: a) /etc/passwd

Explanation:
The /etc/passwd file contains information about all user accounts on the system, including username, user ID, group ID, home directory, and default shell.
Short Trick: Think "passwd" for "user passwords" (though actual passwords are stored in /etc/shadow).

9. Which command creates a new user account?

Correct Answer: d) Both b and c (depending on distribution)

Explanation:
Both "useradd" and "adduser" can create new users. "useradd" is the low-level utility found on all distributions, while "adduser" is a more user-friendly frontend available on Debian-based systems.
Short Trick: "useradd" is the basic command, "adduser" is often more interactive.

10. Which command modifies an existing user account?

Correct Answer: b) usermod

Explanation:
The "usermod" command is used to modify user account attributes such as username, home directory, shell, and group memberships.
Short Trick: "usermod" = "user modify"

11. Which command creates a new group?

Correct Answer: a) groupadd

Explanation:
The "groupadd" command creates a new group on the system with a specified name and optionally with a specific GID (Group ID).
Short Trick: Similar pattern to "useradd" - "group" + "add".

12. Which command displays the groups a user belongs to?

Correct Answer: d) Both b and c

Explanation:
Both the "groups" command and "id -G" display the groups a user belongs to. The "groups" command shows names, while "id -G" can show either names or group IDs depending on options used.
Short Trick: Both commands query the group membership information.

13. Which file contains the default shell settings for a new user?

Correct Answer: c) /etc/default/useradd

Explanation:
The /etc/default/useradd file defines default settings for new user accounts created with the useradd command, including the default shell. The /etc/skel directory contains files that are copied to a new user's home directory.
Short Trick: "default" in the path indicates default settings.

🔒 Managing Permissions and Ownership

14. Which command changes file permissions?

Correct Answer: b) chmod

Explanation:
The "chmod" command changes the file mode bits (permissions) of files and directories. It can be used with symbolic notation (u+x) or octal notation (755).
Short Trick: "chmod" stands for "change mode."

15. Which permission bit allows a file to be executed?

Correct Answer: c) x (execute)

Explanation:
The execute (x) permission allows a file to be executed as a program or script. For directories, it allows users to access files within the directory.
Short Trick: "x" is for "execute" - to run programs.

16. Which command changes the owner of a file?

Correct Answer: a) chown

Explanation:
The "chown" command changes the user and/or group ownership of a specified file or directory.
Short Trick: "chown" stands for "change owner."

17. Which command changes the group of a file?

Correct Answer: a) chgrp

Explanation:
The "chgrp" command changes the group ownership of files or directories. Although "chown" with the format "chown :group filename" can also change group ownership, "chgrp" is specifically designed for this purpose.
Short Trick: "chgrp" stands for "change group."

18. What special permission allows a file to be executed with the permissions of its owner?

Correct Answer: c) SUID (Set User ID)

Explanation:
The SUID (Set User ID) permission causes a program to run with the effective permissions of the file owner rather than the user executing it. This is commonly used for programs that need elevated privileges.
Short Trick: SUID focuses on the User (owner) permissions.

19. In numeric (octal) mode, which value represents read and write permissions?

Correct Answer: d) 6

Explanation:
In octal notation: 4 = read, 2 = write, 1 = execute. To combine permissions, add the values: read + write = 4 + 2 = 6.
Short Trick: Remember r=4, w=2, x=1, then add them up.

20. Which command can be used to set default permissions for new files and directories?

Correct Answer: a) umask

Explanation:
The "umask" command sets the default permission mask for new files and directories. It works by subtracting the umask value from the maximum default permissions (666 for files, 777 for directories).
Short Trick: "umask" stands for "user mask" - it masks (hides) certain permissions.

21. If a file has permissions set to 754, what permissions does "others" have?

Correct Answer: c) Read only

Explanation:
In the permission 754: 7 represents owner permissions (rwx), 5 represents group permissions (r-x), and 4 represents others permissions (r--). The value 4 corresponds to read-only access.
Short Trick: Break down 754 as 7|5|4, where 4 (others) = read only.

💾 Managing Storage

22. Which command is used to create partitions on a disk?

Correct Answer: b) fdisk

Explanation:
The "fdisk" command is a text-based, menu-driven program for creating and manipulating disk partition tables. Other tools like parted and gdisk are also available for this purpose.
Short Trick: "fdisk" = "fixed disk" or "format disk."

23. Which command creates an ext4 filesystem on a partition?

Correct Answer: b) mkfs.ext4

Explanation:
The "mkfs.ext4" command creates an ext4 filesystem on a specified partition or device. While "mkfs" is the generic command, "mkfs.ext4" is specifically for creating ext4 filesystems.
Short Trick: "mkfs" stands for "make filesystem," and ".ext4" specifies the filesystem type.

24. Which command displays the current disk space usage of mounted filesystems?

Correct Answer: a) df

Explanation:
The "df" command displays disk space usage for mounted filesystems, showing information such as total size, used space, available space, and mount points.
Short Trick: "df" stands for "disk free."

25. Which command displays the disk usage of files and directories?

Correct Answer: b) du

Explanation:
The "du" command estimates file and directory space usage. It can show the disk usage of individual files and recursively for directories.
Short Trick: "du" stands for "disk usage."

26. Which command mounts a filesystem?

Correct Answer: a) mount

Explanation:
The "mount" command attaches a filesystem to a specified mount point in the directory tree, making the filesystem accessible for use.
Short Trick: Literally "mount" - attaching the filesystem to the directory tree.

27. Which command creates a new Logical Volume in LVM?

Correct Answer: a) lvcreate

Explanation:
The "lvcreate" command creates a new logical volume in a specified volume group. Logical volumes are flexible storage units that can be resized, unlike traditional partitions.
Short Trick: "lv" stands for "Logical Volume," followed by "create."

28. Which file contains filesystem mount information that gets automatically mounted at boot time?

Correct Answer: b) /etc/fstab

Explanation:
The /etc/fstab (filesystem table) file contains static information about filesystems to be mounted during system boot. It defines which devices are mounted where and with what options.
Short Trick: "fstab" stands for "filesystem table."

29. Which directory typically contains system configuration files in Linux?

Correct Answer: c) /etc

Explanation:
The /etc directory contains host-specific system configuration files. Most system configuration files for applications, services, and various system parameters are stored here.
Short Trick: "etc" is often explained as "etcetera" - where miscellaneous system files are stored.

30. Which directory contains device files representing hardware devices?

Correct Answer: a) /dev

Explanation:
The /dev directory contains device files that represent hardware devices attached to the system. These files allow programs to interact with hardware through standard file operations.
Short Trick: "dev" stands for "devices."