Unix Quiz - Multiple Choice Questions (MCQ)

Welcome to the UNIX Quiz! This quiz provides 25 Multiple Choice Questions (MCQ) covering a broad overview of the fundamental concepts and commands associated with the UNIX operating system. It is crucial for professionals and students to familiarize themselves with these basics for efficient use of UNIX and its various distributions. Dive into the quiz!

1. Which Unix command is used to display the contents of a file?

a) cat
b) show
c) display
d) type

Answer:

a) cat

Explanation:

The cat command is used to display the contents of a file. It stands for "concatenate and display".

2. Which Unix command is used to count the number of lines, words, and characters in a file?

a) count
b) wc
c) calc
d) measure

Answer:

b) wc

Explanation:

The wc command stands for "word count" and is used to display the number of lines, words, and characters in a file.

3. What does the grep command do?

a) Finds a file by name
b) Searches inside a file for a string
c) Replaces strings in a file
d) Lists all files in a directory

Answer:

b) Searches inside a file for a string

Explanation:

grep stands for "global regular expression print" and is used to search for a specific string or pattern inside a file.

4. What is the purpose of the chmod command?

a) Modify file ownership
b) Modify file permissions
c) Change file type
d) Move a file to a different directory

Answer:

b) Modify file permissions

Explanation:

The chmod command is used to change the permissions of a file or directory.

5. Which of the following commands is used to remove a directory?

a) rmdir
b) del
c) remove
d) delete

Answer:

a) rmdir

Explanation:

The rmdir command is used to remove empty directories.

6. The pwd command in UNIX is used for:

a) Printing all directories
b) Printing current directory
c) Changing to the home directory
d) Changing directory permissions

Answer:

b) Printing current directory

Explanation:

pwd stands for "print working directory" and it displays the path of the current directory.

7. Which command will display all hidden files in a directory?

a) ls -a
b) ls -h
c) ls -d
d) ls -s

Answer:

a) ls -a

Explanation:

The ls -a command lists all entries, including those that start with a dot, which are hidden files in UNIX.

8. What does the >> operator do in UNIX?

a) Redirects error messages
b) Appends output to a file
c) Overwrites file content
d) Compares two files

Answer:

b) Appends output to a file

Explanation:

The >> operator is used to append the output of a command to a file. If the file does not exist, it creates one.

9. Which Unix command displays the manual or help pages of a command?

a) man
b) help
c) info
d) guide

Answer:

a) man

Explanation:

The man command is used to display the manual or help pages of a command. It stands for "manual".

10. Which Unix command is used to display the process status?

a) ps
b) stat
c) view
d) proc

Answer:

a) ps

Explanation:

The ps command is used to display information about the currently running processes.

11. What does the kill command do in UNIX?

a) Deletes a file
b) Ends a user session
c) Stops a running process
d) Displays user activity

Answer:

c) Stops a running process

Explanation:

The kill command is used to send signals to processes, allowing you to stop, pause, or otherwise signal processes.

12. Which Unix command can be used to display disk usage?

a) du
b) disk
c) usage
d) space

Answer:

a) du

Explanation:

The du command stands for "disk usage" and is used to estimate and display the disk space used by files.

13. The which command in UNIX is used to:

a) Determine the type of a file
b) Search for a command's binary location
c) Search for files containing a specific string
d) Display users logged into the system

Answer:

b) Search for a command's binary location

Explanation:

The which command is used to locate the binary of a command to see where it resides on disk.

14. The alias command in UNIX is used for:

a) Renaming a file or directory
b) Creating a shortcut for a command
c) Displaying file permissions
d) Listing all available commands

Answer:

b) Creating a shortcut for a command

Explanation:

The alias command allows users to create shortcuts or abbreviations for longer command sequences.

15. Which of the following commands will display the last 100 lines of a file named "data.txt"?

a) tail -n 100 data.txt
b) head -n 100 data.txt
c) cat 100 data.txt
d) print -l 100 data.txt

Answer:

a) tail -n 100 data.txt

Explanation:

The tail command displays the last few lines of a file. With the -n option, you can specify the number of lines to display.

16. What is the primary purpose of the crontab command?

a) Schedule tasks to run at specific intervals
b) Display system's uptime
c) Show system cron logs
d) List files in the current directory

Answer:

a) Schedule tasks to run at specific intervals

Explanation:

The crontab command is used to create, read, update, and delete cron jobs for a user. Cron jobs are tasks scheduled to run at specific intervals.

17. Which of the following commands is used to sort the contents of a file?

a) order
b) arrange
c) sort
d) classify

Answer:

c) sort

Explanation:

The sort command is used to sort the lines in a text file.

18. Which command allows you to substitute a string in a file?

a) replace
b) alter
c) sed
d) swap

Answer:

c) sed

Explanation:

sed, or stream editor can be used to perform basic text transformations on an input stream or file.

19. Which command is used to find the location of a program in UNIX?

a) find
b) locate
c) where
d) which

Answer:

d) which

Explanation:

While both find and locate can be used to search for files, the which command is specifically used to locate the executable file associated with a given command.

20. Which command is used to send the output of one command as the input to another command?

a) >>
b) |
c) >
d) <<

Answer:

b) |

Explanation:

The pipe (|) is used to send the output of one command as input to another command.

21. What does the chown command do?

a) Change the name of a file or directory
b) Change the permissions of a file or directory
c) Change the owner of a file or directory
d) Check for file ownership

Answer:

c) Change the owner of a file or directory

Explanation:

The chown command is used to change the owner (and optionally the group) of a file or directory.

22. The ln command in UNIX is used to:

a) List file names
b) Link files
c) Log in to the system
d) List network connections

Answer:

b) Link files

Explanation:

The ln command is used to create links between files.

23. Which command is used to repeat the last executed command in UNIX?

a) redo
b) !!
c) repeat
d) ^

Answer:

b) !!

Explanation:

In many UNIX shells, !! is used to repeat the last executed command.

24. What does the $? variable signify in UNIX?

a) Total number of arguments
b) Process ID of the last command
c) Exit status of the last command
d) Current user ID

Answer:

c) Exit status of the last command

Explanation:

In UNIX, $? gives the exit status of the last command executed. An exit status of 0 usually indicates success, while any other value indicates an error.

25. The touch command in UNIX is primarily used to:

a) Touch files or directories
b) Display file content
c) Modify file timestamps
d) Change file permissions

Answer:

c) Modify file timestamps

Explanation:

The touch command is primarily used to create empty files and can also change the timestamps on existing files.


Comments