Linux MCQs
Q.1 Which command is used to create an empty file in Linux?
A. touch
B. create
C. mkfile
D. newfile
Q.2 Which command is used to change file access permissions in Linux?
A. chmod
B. chown
C. chgrp
D. chperm
Q.3 Which command is used to display the disk usage of files and directories?
A. df
B. du
C. diskusage
D. checkdisk
Q.4 What does the -r option in the rm command do?
A. Removes directories recursively
B. Removes read-only files
C. Renames files
D. Removes files with a specific pattern
Q.5 Which command is used to find the location of a command in Linux?
A. find
B. locate
C. whereis
D. which
Q.6 Which command is used to view the last few lines of a file?
A. head
B. tail
C. cat
D. less
Q.7 Which command is used to display a file’s contents one page at a time?
A. more
B. cat
C. head
D. tail
Q.8 Which command is used to display the manual pages for other commands in Linux?
A. help
B. man
C. info
D. doc
Q.9 A user reports that they can see a directory named backup in their home directory, but cannot enter it using cd backup.
What could be the reason?
A. The directory does not exist
B. The user does not have execute permissions
C. The directory is a symbolic link
D. The directory is hidden
Q.10 A user complains that they cannot find a file named .hidden_file in their home directory using the ls command.
What could be the reason?
A. The file does not exist
B. The user does not have read permissions
C. The file is hidden
D. The file is in a different directory
Q.11 How do you move a file named document.txt from the current directory to the /backup directory?
A. cp document.txt /backup
B. mv document.txt /backup
C. move document.txt /backup
D. cp document.txt /backup/document.txt
Q.12 Which command is used to create an empty file in Linux?
A. touch
B. create
C. mkfile
D. newfile
Q.13 How do you display detailed information about files and directories, including file permissions, in Linux?
A. ls -a
B. ls -l
C. ls -lh
D. ls -ld
Q.14 Which command is used to display the current working directory?
A. cd
B. ls
C. pwd
D. dir
Q.15 Which file system type is most commonly used by Linux distributions?
A. NTFS
B. FAT32
C. ext4
D. HFS+
Q.16 What is the purpose of the /var directory in the Linux file system?
A. Contains variable data files
B. Contains configuration files
C. Contains user home directories
D. Contains system binaries
Q.17 Which directory is used for temporary files that are created by the system and applications?
A. /tmp
B. /var
C. /usr
D. /etc
Q.18 What is the purpose of the /etc directory in the Linux file system?
A. Contains user home directories
B. Contains configuration files
C. Contains binary executables
D. Contains temporary files
Q.19 Which command is used to change the current working directory in Linux?
A. ls
B. cd
C. pwd
D. mv
Q.20 What is the root directory in the Linux file system?
A. /root
B. /home
C. /
D. /var
Q.21 A user reports that they are unable to write to a file named report.txt on a Linux system, despite the file showing that it exists when listing files with ls.
What could be the most likely cause of this issue?
A. The user does not have write permissions on report.txt
B. The file report.txt is a directory, not a file
C. The disk containing report.txt is full
D. The ls command is malfunctioning
Q.22 Which command is used to list all files and directories in the current directory, including hidden ones?
A. ls -a
B. ls -l
C. dir
D. listall
Q.23 What is the primary advantage of using a command-line interface (CLI) in Linux?
A. Easy to learn
B. Fast and efficient
C. Graphical interface
D. Limited functionality
Q.24 Which of the following is not a Linux distribution?
A. Ubuntu
B. Fedora
C. Windows
D. Debian
Q.25 What is the primary purpose of the Linux bootloader?
A. To load the Linux kernel into memory
B. To provide a graphical user interface
C. To manage user authentication
D. To start the init process
Q.26 Which shell is the default in most Linux distributions?
A. Korn Shell
B. C Shell
C. Bourne-Again Shell
D. Z Shell
Q.27 What does the ‘GPL’ in Linux licensing stand for?
A. General Public License
B. Global Public License
C. General Privacy License
D. Global Privacy License
Q.28 What is the role of the GNU project in the Linux ecosystem?
A. It provides the Linux kernel
B. It provides system libraries and utilities
C. It develops the X Window System
D. It maintains the Linux kernel
Q.29 Which of the following is a key feature of Linux?
A. Closed-source
B. Proprietary
C. Open-source
D. Single-user
Q.30 What is the primary purpose of the Linux operating system’s kernel?
A. To manage the system’s hardware resources effectively
B. To provide a graphical user interface
C. To support the installation of third-party software
D. To protect the system from viruses
Q.31 What is the purpose of the shebang (#!) in a shell script?
A. To comment the script
B. To specify the script’s interpreter
C. To define variables
D. To provide execution permissions
Q.32 Which of the following is used to make a shell script executable?
A. chmod +x script.sh
B. chmod u+x script.sh
C. chmod 777 script.sh
D. chmod 755 script.sh
Q.33 What is a shell script in Linux?
A. A compiled program
B. A series of commands written in a file
C. A binary executable
D. A system call
Q.34 A process is stuck and not responding to SIGTERM.
What is the most effective way to kill it?
A. kill -15 PID
B. kill -1 PID
C. kill -9 PID
D. kill -HUP PID
Q.35 A user has started a process in the background but now wants to bring it to the foreground.
Which command should they use?
A. fg
B. bg
C. kill
D. jobs
Q.36 A user reports that a process is consuming too much CPU.
Which command can help identify this process?
A. ps
B. ls
C. top
D. jobs
Q.37 How do you display a real-time view of running processes, showing system resource usage?
A. ps
B. ls
C. top
D. jobs
Q.38 How do you kill a process with the process ID 1234?
A. kill -9 1234
B. killall 1234
C. kill -KILL 1234
D. terminate 1234
Q.39 How do you put a currently running job into the background?
A. fg
B. bg
C. ctrl+c
D. ctrl+z
Q.40 Which signal is sent to a process to terminate it immediately?
A. SIGINT
B. SIGTERM
C. SIGKILL
D. SIGHUP
Q.41 What is a zombie process in Linux?
A. A process that is sleeping
B. A process that is currently running
C. A terminated process that has not been cleaned up by its parent
D. A process that is in the background
Q.42 What is the purpose of the ‘init’ process in Linux?
A. To initialize network connections
B. To manage the system’s boot process
C. To execute user commands
D. To manage user sessions
Q.43 Which command is used to list all currently running processes?
A. ps
B. ls
C. top
D. jobs
Q.44 A file named data.txt has the permissions set to -rwxr-xr–.
What does this imply about the user’s permissions?
A. The user can read, write, and execute the file
B. The user can read and write the file
C. The user can read and execute the file
D. The user can only read the file
Q.45 A user reports that they cannot delete a file named report.txt, even though they have write permissions.
What could be the reason?
A. The file is read-only
B. The user does not have execute permissions
C. The directory containing the file does not have write permissions
D. The file is hidden
Q.46 Which command is used to change the group ownership of a file named project.txt to a group named devteam?
A. chown devteam project.txt
B. chgrp devteam project.txt
C. chgroup devteam project.txt
D. chmod devteam project.txt
Q.47 How do you add execute permissions for the user on a file named script.sh?
A. chmod +x script.sh
B. chmod u+x script.sh
C. chmod u-x script.sh
D. chmod o+x script.sh
Q.48 How do you grant read and write permissions to the owner and the group for a file named data.txt?
A. chmod 660 data.txt
B. chmod 640 data.txt
C. chmod 644 data.txt
D. chmod 600 data.txt
Q.49 Which command is used to change the owner of a file?
A. chmod
B. chown
C. chgrp
D. ls -l
Q.50 What is the effect of setting the setuid bit on an executable file?
A. The file can be executed with the user’s permissions
B. The file can be executed with the group’s permissions
C. The file can be executed with the owner’s permissions
D. The file can only be executed by the owner
Q.51 How can you view the permissions of a file named example.txt?
A. ls example.txt
B. ls -l example.txt
C. chmod example.txt
D. chown example.txt
Q.52 What does the ‘r’ permission signify in Linux file permissions?
A. Read
B. Write
C. Execute
D. Delete
Q.53 What does the command chmod 755 do?
A. Sets read, write, and execute permissions for the owner, and read and execute permissions for others
B. Sets read and write permissions for the owner, and read permissions for others
C. Sets execute permissions for the owner and group
D. Sets read and execute permissions for the owner and group
Q.54 A user wants to use the find command to search for all .txt files in their home directory, but it returns no results.
What could be the issue?
A. Incorrect syntax
B. The files do not exist
C. The user lacks read permissions
D. The files are hidden
Q.55 A user wants to compress a file but receives a “Permission denied” error.
What is the likely cause?
A. The file is read-only
B. The user does not have write permissions
C. The file is already compressed
D. The user is not in the correct directory
Q.56 A user reports that the df command is showing incorrect free space for a partition.
What could be a possible reason?
A. The partition is unmounted
B. The disk is faulty
C. Inode exhaustion
D. Filesystem is read-only
Q.57 A user complains that they cannot find a command they just installed.
What could be the most likely cause?
A. The command is not in the user’s PATH
B. The command is not executable
C. The command was not installed correctly
D. The command is hidden
Q.58 How do you search for the pattern “error” in a file named log.txt and display matching lines?
A. grep “error” log.txt
B. find “error” log.txt
C. locate “error” log.txt
D. search “error” log.txt
Q.59 How do you view the first 10 lines of a file named data.txt?
A. head -10 data.txt
B. tail -10 data.txt
C. cat data.txt
D. more data.txt
Q.60 How do you list all files, including hidden files, in a directory?
A. ls -a
B. ls -l
C. ls -h
D. ls -all
Q.61 A user reports that they cannot install a package using apt-get due to broken dependencies.
What is the likely solution?
A. Use the –fix-broken option
B. Update the package list
C. Clean the package cache
D. Reinstall the package manager
Q.62 How do you remove a package named “wget” using apt-get?
A. apt-get remove wget
B. apt-get purge wget
C. apt-get delete wget
D. apt-get erase wget
Q.63 How do you install a package named “nano” using yum?
A. yum search nano
B. yum install nano
C. yum remove nano
D. yum update nano
Q.64 How do you search for a package named “vim” using apt-get?
A. apt-get install vim
B. apt-get search vim
C. apt-get remove vim
D. apt-get update vim
Q.65 Which package manager is used by Arch Linux?
A. yum
B. apt-get
C. dnf
D. pacman
Q.66 Which command is used to upgrade all installed packages in Debian-based distributions?
A. yum update
B. apt-get upgrade
C. dnf upgrade
D. zypper update
Q.67 What is the function of the yum package manager?
A. To manage RPM packages
B. To manage DEB packages
C. To manage source code
D. To manage system services
Q.68 Which file contains the list of repositories for Debian-based distributions?
A. /etc/yum.conf
B. /etc/apt/sources.list
C. /etc/pacman.conf
D. /etc/zypper/repos.d
Q.69 What is the primary purpose of a package manager in Linux?
A. To compile source code
B. To manage software packages
C. To update the kernel
D. To configure hardware
Q.70 Which command is used to install packages in Debian-based distributions?
A. yum
B. dnf
C. apt-get
D. zypper
Q.71 A user needs to extract the second column of a comma-separated file named data.csv.
Which command should they use?
A. grep
B. cut
C. awk
D. sed
Q.72 A user reports that the grep command is not finding matches in a file.
What could be the issue?
A. The file does not exist
B. The pattern is incorrect
C. The file is empty
D. The user does not have read permissions
Q.73 How do you replace all occurrences of the word “Linux” with “GNU/Linux” in a file named os.txt?
A. sed ‘s/Linux/GNU/Linux/g’ os.txt
B. awk ‘{gsub(/Linux/, “GNU/Linux”)}1’ os.txt
C. grep -rl “Linux” os.txt
D. cut -d” ” -f1 os.txt
Q.74 How do you search for the string “error” in a file named log.txt and display the matching lines?
A. grep “error” log.txt
B. awk “/error/ {print}” log.txt
C. sed -n “/error/p” log.txt
D. cut -d” ” -f1 log.txt
Q.75 How do you display the first 10 lines of a file named data.txt?
A. head data.txt
B. tail data.txt
C. cat data.txt
D. more data.txt
Q.76 Which command is used to merge lines of files based on a common field?
A. sort
B. uniq
C. paste
D. join
Q.77 What does the cut command do in text processing?
A. Extracts sections from each line of a file
B. Sorts lines in a file
C. Counts the number of lines in a file
D. Displays the first few lines of a file
Q.78 Which command is used to delete lines from a file that match a specific pattern?
A. sed
B. awk
C. grep
D. cut
Q.79 What is the primary function of the awk command?
A. Editing text files
B. Searching for patterns
C. Processing and analyzing text
D. Displaying file contents
Q.80 What does the grep command do?
A. Displays file contents
B. Searches for patterns within files
C. Sorts the contents of a file
D. Counts the number of lines in a file
Q.81 Which command is used to display the contents of a file?
A. cat
B. grep
C. awk
D. sed
Q.82 A shell script executes correctly when run manually but fails when run as a cron job.
What could be the issue?
A. Missing shebang
B. Incorrect script syntax
C. Environment variables not set
D. Script not executable
Q.83 A user wants to debug a shell script to identify where it is failing.
Which command should they use?
A. sh -x script.sh
B. bash -x script.sh
C. set -x
D. echo
Q.84 A shell script is giving a “Permission denied” error when executed.
What is the likely cause?
A. The script is not executable
B. The script has syntax errors
C. The script is missing the shebang
D. The script is not in the PATH
Q.85 How do you create a loop that runs 5 times in a shell script?
A. for i in {1..5}; do … done
B. while [ $i -le 5 ]; do … done
C. for i in 1 2 3 4 5; do … done
D. until [ $i -gt 5 ]; do … done
Q.86 How do you assign the output of the date command to a variable named current_date in a shell script?
A. current_date=date
B. current_date=$(date)
C. current_date=$(date)
D. current_date=$date
Q.87 How do you print “Hello, World!” to the terminal in a shell script?
A. echo “Hello, World!”
B. print “Hello, World!”
C. printf “Hello, World!”
D. disp “Hello, World!”
Q.88 What is the significance of the $? variable in shell scripting?
A. Stores the process ID of the last executed command
B. Stores the exit status of the last executed command
C. Stores the current shell’s process ID
D. Stores the number of arguments passed to the script
Q.89 What does the read command do in a shell script?
A. Reads a file
B. Reads user input
C. Reads a variable
D. Reads a command
Q.90 How can you execute a shell script named script.sh?
A. ./script.sh
B. sh script.sh
C. bash script.sh
D. source script.sh
Q.91 What is the purpose of the fsck command?
A. To check and repair file systems
B. To format a disk
C. To create partitions
D. To display disk usage
Q.92 Which command is used to display disk usage in a human-readable format?
A. du -h
B. df -h
C. lsblk
D. fdisk -l
Q.93 A user is unable to login to their account.
Which file should be checked for locked accounts?
A. /etc/passwd
B. /etc/shadow
C. /etc/group
D. /etc/login.defs
Q.94 A user reports that they cannot change their password.
Which command can help resolve this issue?
A. useradd
B. passwd
C. usermod
D. groupadd
Q.95 How do you change the primary group of a user named “alice” to “developers”?
A. usermod -g developers alice
B. usermod -G developers alice
C. groupmod -g developers alice
D. usermod -aG developers alice
Q.96 How do you delete a user named “john” and remove their home directory?
A. userdel john
B. userdel -r john
C. userdel -d john
D. userdel -f john
Q.97 What does the usermod -aG command do?
A. Adds a user to a group
B. Modifies user account information
C. Deletes a user
D. Locks a user account
Q.98 Which file contains user account information in Linux?
A. /etc/passwd
B. /etc/shadow
C. /etc/group
D. /etc/userinfo
Q.99 What is the purpose of the passwd command?
A. To create a new user
B. To delete a user
C. To change a user’s password
D. To modify user information
Q.100 Which command is used to add a new user in Linux?
A. useradd
B. usermod
C. userdel
D. groupadd
Q.101 A user cannot resolve the hostname “example.com”.
Which command can help diagnose this issue?
A. ping
B. traceroute
C. nslookup
D. netstat
Q.102 A user reports that they cannot reach a website.
Which command can help determine if the network connection is working?
A. ifconfig
B. ping
C. route
D. netstat
Q.103 How do you display network interface statistics using the ifconfig command?
A. ifconfig -s
B. ifconfig -a
C. ifconfig -v
D. ifconfig -r
Q.104How do you find the IP address of the hostname “example.com” using the nslookup command?
A. nslookup example.com
B. nslookup -type=A example.com
C. nslookup -type=MX example.com
D. nslookup -type=NS example.com
Q.105 How do you display all active network connections using the netstat command?
A. netstat -a
B. netstat -r
C. netstat -i
D. netstat -s
Q.106 What is the function of the traceroute command?
A. To display the path packets take to reach a network host
B. To monitor network traffic
C. To display active network connections
D. To check disk usage
Q.107 Which command is used to display the routing table in Linux?
A. route
B. netstat
C. ping
D. ifconfig
Q.108 What is the purpose of the ping command in Linux?
A. To check disk usage
B. To check network connectivity
C. To list open ports
D. To configure network interfaces
Q.109 Which command is used to display the IP address of a Linux system?
A. ifconfig
B. ping
C. traceroute
D. netstat
Q.110 A user reports that their system is running out of memory.
Which command can help identify memory usage by processes?
A. top
B. free
C. ps aux –sort=-%mem
D. vmstat
Q.111 A system is experiencing high load average values.
What could be a likely cause?
A. Insufficient RAM
B. High I/O wait time
C. Low disk space
D. Network congestion
Q.112 A user reports high CPU usage on their system.
Which command can help identify the process causing this issue?
A. top
B. free
C. df
D. ps
Q.113 How do you display the last 100 lines of a system log file named /var/log/syslog using the tail command?
A. tail -100 /var/log/syslog
B. tail -n 100 /var/log/syslog
C. tail –lines=100 /var/log/syslog
D. tail /var/log/syslog
Q.114 How do you check the disk usage of a directory named /home/user using the du command?
A. du -sh /home/user
B. du -h /home/user
C. du -c /home/user
D. du -a /home/user
Q.115 How do you display the memory usage in a human-readable format using the free command?
A. free -h
B. free -m
C. free -g
D. free -b
Q.116 What is the purpose of the iostat command?
A. To report CPU utilization and I/O statistics
B. To display network statistics
C. To show system uptime
D. To monitor memory usage
Q.1117 Which command is used to display a detailed report of CPU usage?
A. mpstat
B. iostat
C. sar
D. uptime
Q.118 What does the vmstat command do in Linux?
A. Displays virtual memory statistics
B. Displays disk usage
C. Displays network statistics
D. Displays process status
Q.119 Which command is used to display system resource usage in real-time?
A. ps
B. top
C. df
D. du
Q.120 A user is unable to update their package list using yum.
What could be the problem?
A. The user does not have sudo privileges
B. The repository list is incorrect
C. The package manager is not installed
D. The system is not connected to the internet
Q.121 A cron job is supposed to run a script, but it fails. The script runs fine manually.
What could be the issue?
A. Incorrect file permissions
B. Missing shebang line
C. Environment variables not set
D. Script syntax error
Q.122 A user reports that their cron job is not executing.
Which command can be used to check the cron logs?
A. crontab -l
B. cronlog
C. grep cron /var/log/syslog
D. tail -f /var/log/cron
Q.123 How do you schedule a cron job to run every Monday at 5 PM?
A. 0 17 * * 1 /path/to/script.sh
B. 0 5 * * 1 /path/to/script.sh
C. 0 17 * * * /path/to/script.sh
D. 0 17 1 * * /path/to/script.sh
Q.124 How do you schedule a cron job to run a script at 2 AM every day?
A. 0 2 * * * /path/to/script.sh
B. 0 2 * * 1 /path/to/script.sh
C. 2 0 * * * /path/to/script.sh
D. 2 0 * * 1 /path/to/script.sh
Q.125 Which special character is used in a crontab file to denote all valid values for a field?
A. *
B. ?
C. –
D. ,
Q.126 What is the role of the crontab command?
A. To display system logs
B. To edit the cron table
C. To start a service
D. To check disk usage
Q.127 What is the purpose of a cron job in Linux?
A. To monitor system performance
B. To schedule repetitive tasks
C. To manage user accounts
D. To compile code
Q.128 A user wants to automate daily backups of their home directory.
Which tool can help achieve this?
A. cron
B. rsync
C. tar
D. dd
Q.129 How do you synchronize the /home/user directory with the /backup/user directory using rsync?
A. rsync -av /home/user /backup/user
B. rsync -z /home/user /backup/user
C. rsync -c /home/user /backup/user
D. rsync -t /home/user /backup/user
Q.130 How do you create a compressed archive of the /home/user directory using tar?
A. tar -cvf home.tar.gz /home/user
B. tar -xvf home.tar.gz /home/user
C. tar -czvf home.tar.gz /home/user
D. tar -tzvf home.tar.gz /home/user
Q.131 What is the role of the dd command in backup and recovery?
A. To display disk usage
B. To copy and convert files at the byte level
C. To list directory contents
D. To manage disk partitions
Q.132 Which option with the tar command is used to create a new archive file?
A. -x
B. -c
C. -t
D. -v
Q.133 What is the purpose of the rsync command?
A. To synchronize files and directories between two locations
B. To compress files
C. To move files
D. To delete files
Q.134 Which command is commonly used for creating backups in Linux?
A. cp
B. mv
C. tar
D. chmod
Q.135 A file’s permissions are set to rwxr-xr–.
What could be a potential security risk with these settings?
A. Unauthorized modification by others
B. Unauthorized execution by the group
C. Unauthorized reading by others
D. Unauthorized deletion by others
Q.136 A user is unable to delete a file in a directory with the sticky bit set.
What could be the reason?
A. The user does not have write permissions on the directory
B. The user is not the owner of the file
C. The file is read-only
D. The file is being used by another process
Q.137 A user is unable to modify a file despite having write permissions.
What could be the reason?
A. The file is read-only
B. The user is not the owner
C. The file has the immutable attribute set
D. The file is in use
Q.138 How do you grant execute permissions to the owner and group for a file named script.sh?
A. chmod u+x script.sh
B. chmod ug+x script.sh
C. chmod o+x script.sh
D. chmod g+x script.sh
Q.139 How do you change the owner of a file named document.txt to a user named alice?
A. chown alice document.txt
B. chmod alice document.txt
C. chgrp alice document.txt
D. usermod alice document.txt
Q.140 What does setting the sticky bit on a directory do?
A. Allows users to read files
B. Allows users to execute files
C. Restricts file deletion to owners
D. Grants root privileges
Q.141 Which file stores user passwords in a hashed format for added security?
A. /etc/passwd
B. /etc/shadow
C. /etc/group
D. /etc/secure
Q.142 What is the purpose of the sudo command?
A. To switch users
B. To execute a command with root privileges
C. To change file permissions
D. To monitor system logs
Q.143 Which command is used to change the permissions of a file in Linux?
A. chmod
B. chown
C. chgrp
D. passwd
Q.144 A file system is showing as read-only.
Which command can be used to remount it as read-write?
A. mount -o remount,ro /mount/point
B. mount -o remount,rw /mount/point
C. umount /mount/point
D. fsck /mount/point
Q.145 A user reports that a partition is not available after a reboot.
Which file should be checked to ensure it mounts automatically?
A. /etc/fstab
B. /etc/mtab
C. /etc/passwd
D. /etc/rc.local
Q.146 How do you mount a file system located at /dev/sda1 to the /mnt directory?
A. mount /dev/sda1 /mnt
B. mount /mnt /dev/sda1
C. mount -t /dev/sda1 /mnt
D. mount -a /dev/sda1 /mnt
Q.147 How do you display detailed information about all block devices?
A. lsblk -f
B. lsblk -a
C. lsblk -l
D. lsblk -d
Q.148 Which command is used to create and manage disk partitions?
A. fdisk
B. mkfs
C. du
D. mount
Q.149 What does the mkfs command do in Linux?
A. Mounts a file system
B. Formats a disk
C. Checks disk usage
D. Creates a file system
Q.150 A user reports that a backup created with tar is not extracting correctly.
What could be the issue?
A. The archive file is corrupted
B. The file permissions are incorrect
C. The compression method is unsupported
D. The tar command is outdated