linux banner

Linux Multiple Choice Questions (MCQs) and Answers

Master Linux with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Linux concepts. Begin your placement preparation journey now!

Q61

Q61 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

Q62

Q62 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

Q63

Q63 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

Q64

Q64 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!"

Q65

Q65 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

Q66

Q66 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

Q67

Q67 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

Q68

Q68 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

Q69

Q69 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

Q70

Q70 Which command is used to display the contents of a file?

A

cat

B

grep

C

awk

D

sed

Q71

Q71 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

Q72

Q72 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

Q73

Q73 Which command is used to delete lines from a file that match a specific pattern?

A

sed

B

awk

C

grep

D

cut

Q74

Q74 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

Q75

Q75 Which command is used to merge lines of files based on a common field?

A

sort

B

uniq

C

paste

D

join

Q76

Q76 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

Q77

Q77 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

Q78

Q78 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

Q79

Q79 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

Q80

Q80 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

Q81

Q81 Which command is used to install packages in Debian-based distributions?

A

yum

B

dnf

C

apt-get

D

zypper

Q82

Q82 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

Q83

Q83 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

Q84

Q84 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

Q85

Q85 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

Q86

Q86 Which package manager is used by Arch Linux?

A

yum

B

apt-get

C

dnf

D

pacman

Q87

Q87 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

Q88

Q88 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

Q89

Q89 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

Q90

Q90 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

ad verticalad vertical
ad