UNIX MCQs – File Manipulation (Part -4)

UNIX Question and Answer – File Manipulation

UNIX MCQ – Multiple Choice Questions for exam, interview, and Entrance Test

1. Which command is used to display the differences between two files in UNIX?

a) diff

b) compare

c) delta

d) changes

Answer: a) diff

Explanation: The diff command is used to display the difference between two files in UNIX.


2. Which command is used to display the differences between two files in a side-by-side format, highlighting the changes in UNIX?

a) diff

b) sdiff

c) cmp

d) meld

Answer: b) sdiff

Explanation: The sdiff command is used to display the differences between two files in a side-by-side format, highlighting the changes in UNIX.


3. What is the primary role of the paste command in UNIX?

a) Merge lines of files

b) Split lines of files

c) Convert tabs to spaces

d) Remove empty lines from files

Answer: a) Merge lines of files

Explanation: The paste command is used to merge lines of files in UNIX.


4. Which command is used to count the occurrences of each unique line in a file, sorted numerically, and display the results in UNIX?

a) count

b) tally

c) sort | uniq -c

d) uniq -c | sort

Answer: d) uniq -c | sort

Explanation: The uniq -c command is used to count the occurrences of each unique line in a file, and the results are sorted numerically using the sort command in UNIX.


5. What is the purpose of the od command in UNIX?

a) Display file permissions

b) Display file contents in octal format

c) Display file contents in hexadecimal format

d) Display file contents in binary format

Answer: b) Display file contents in octal format

Explanation: The od command is primarily used to display file contents in octal format in UNIX.


6. Which command is used to search for a pattern in files and display matching lines, ignoring case distinctions in UNIX?

a) grep -i

b) grep -v

c) grep -c

d) grep -r

Answer: a) grep -i

Explanation: The grep command with the -i option is used to search for a pattern in files and display matching lines, ignoring case distinctions in UNIX.


7. What is the purpose of the join command in UNIX?

a) Concatenate files

b) Merge lines of files

c) Remove duplicate lines

d) Combine fields from two files using a common field

Answer: d) Combine fields from two files using a common field

Explanation: The join command is used to combine fields from two files using a common field in UNIX.


8. Which command is used to display the differences between two files line by line, with more context in UNIX?

a) diff

b) sdiff

c) cmp

d) diff -u

Answer: d) diff -u

Explanation: The diff command with the -u option is used to display the differences between two files line by line, with more context in UNIX.


9. What is the purpose of the fold command in UNIX?

a) Fold text files to fit a specified width

b) Search for patterns in files

c) Display the last lines of a file

d) Extract specific columns of text from a file

Answer: a) Fold text files to fit a specified width

Explanation: The fold command is used to fold text files to fit a specified width in UNIX.


10. Which command is used to search for a pattern in files and display matching lines, with line numbers in UNIX?

a) grep -n

b) grep -l

c) grep -o

d) grep -c

Answer: a) grep -n

Explanation: The grep command with the -n option is used to search for a pattern in files and display matching lines, with line numbers in UNIX.


11. What is the primary function of the tr command in UNIX?

a) Translate or delete characters

b) Concatenate files

c) Merge lines of files

d) Display file contents

Answer: a) Translate or delete characters

Explanation: The tr command is used to translate or delete characters in a file in UNIX.


12. Which command is used to remove empty lines from a file in UNIX?

a) clean

b) remove_empty

c) remove_blank

d) sed ‘/^$/d’

Answer: d) sed ‘/^$/d’

Explanation: The sed command with the specified pattern is used to remove empty lines from a file in UNIX.


13. What is the purpose of the sort command in UNIX?

a) Sort lines of text files

b) Merge lines of files

c) Display the last lines of a file

d) Extract specific columns of text from a file

Answer: a) Sort lines of text files

Explanation: The sort command is used to sort lines of text files in UNIX.


14. Which command is used to display the first few lines of a file in UNIX?

a) head

b) tail

c) more

d) less

Answer: a) head

Explanation: The head command is used to display the first few lines of a file in UNIX.


15. What is the primary function of the tac command in UNIX?

a) Display the last lines of a file

b) Reverse the order of lines in a file

c) Merge lines of files

d) Sort the lines of a file

Answer: b) Reverse the order of lines in a file

Explanation: The tac command is used to reverse the order of lines in a file in UNIX.


16. Which command is used to display the differences between two files in UNIX?

a) diff

b) compare

c) delta

d) changes

Answer: a) diff

Explanation: The diff command is used to display the difference between two files in UNIX.


17. What is the purpose of the rsync command in UNIX?

a) Synchronize files and directories between two locations

b) Rename files and directories

c) Remove files and directories

d) Compress files and directories

Answer: a) Synchronize files and directories between two locations

Explanation: The rsync command is used to synchronize files and directories between two locations in UNIX.


18. Which command is used to display the size of a directory and its contents in UNIX?

a) du

b) ls

c) df

d) dir

Answer: a) du

Explanation: The du command is used to display the size of a directory and its contents in UNIX.


19. What is the purpose of the tar command in UNIX?

a) Compress files and directories

b) Display the contents of a file

c) Extract files and directories from an archive

d) Rename files and directories

Answer: c) Extract files and directories from an archive

Explanation: The tar command is used to create, maintain, modify, and extract files and directories from an archive in UNIX.


20. Which command is used to change the ownership of a file in UNIX?

a) own

b) changeown

c) chown

d) chmod

Answer: c) chown

Explanation: The chown command is used to change the ownership of a file in UNIX.


21. What is the purpose of the cmp command in UNIX?

a) Compare two files byte by byte

b) Compare two sorted files line by line

c) Compare two directories

d) Compare two file permissions

Answer: a) Compare two files byte by byte

Explanation: The cmp command is used to compare two files byte by byte in UNIX.


22. Which command is used to display the differences between two files in UNIX?

a) diff

b) compare

c) delta

d) changes

Answer: a) diff

Explanation: The diff command is used to display the difference between two files in UNIX.


23. What is the purpose of the split command in UNIX?

a) Split a file into multiple files based on size

b) Split a file into multiple files based on lines

c) Split a file into two parts

d) Split a file into multiple files based on a delimiter

Answer: b) Split a file into multiple files based on lines

Explanation: The split command is used to split a file into multiple files based on the number of lines in UNIX.


24. Which command is used to concatenate files and print on the standard output in UNIX?

a) cat

b) merge

c) paste

d) join

Answer: a) cat

Explanation: The cat command is used to concatenate files and print on the standard output in UNIX.


25. What is the primary function of the tee command in UNIX?

a) Redirect output to multiple files and standard output simultaneously

b) Display file contents

c) Concatenate files

d) Split lines of files

Answer: a) Redirect output to multiple files and standard output simultaneously

Explanation: The tee command is used to redirect output to multiple files and standard output simultaneously in UNIX.


26. Which command is used to display the size of a file in a human-readable format in UNIX?

a) ls -h

b) size

c) file

d) du -h

Answer: d) du -h

Explanation: The du command with the -h option is used to display the size of a file in a human-readable format in UNIX.


27. What is the primary purpose of the cut command in UNIX?

a) Display file contents

b) Extract specific columns of text from a file

c) Search for patterns in files

d) Display the first lines of a file

Answer: b) Extract specific columns of text from a file

Explanation: The cut command is primarily used to extract specific columns of text from a file in UNIX.


28. Which command is used to display the contents of a file in reverse order in UNIX?

a) tail

b) rev

c) tac

d) head

Answer: c) tac

Explanation: The tac command is used to display the contents of a file in reverse order in UNIX.


29. What is the purpose of the file command in UNIX?

a) Display file permissions

b) Display file type

c) Change file ownership

d) Display file contents

Answer: b) Display file type

Explanation: The file command is used to determine the type of a file in UNIX.


30. Which command is used to create a new directory in UNIX?

a) mkdir

b) touch

c) cd

d) mv

Answer: a) mkdir

Explanation: The mkdir command is used to create a new directory in UNIX.


31. What is the primary function of the find command in UNIX?

a) Display file permissions

b) Search for files and directories based on specified criteria

c) Display file contents

d) Count lines in a file

Answer: b) Search for files and directories based on specified criteria

Explanation: The find command is primarily used to search for files and directories based on specified criteria in UNIX.


32. Which command is used to remove a directory in UNIX?

a) rm

b) rmdir

c) del

d) remove

Answer: b) rmdir

Explanation: The rmdir command is used to remove a directory in UNIX.


33. What is the purpose of the wc command in UNIX?

a) Count the number of words in a file

b) Display file contents

c) Display file permissions

d) Sort lines of text files

Answer: a) Count the number of words in a file

Explanation: The wc command is used to count the number of words in a file in UNIX.


34. Which command is used to display the current working directory in UNIX?

a) pwd

b) cd

c) ls

d) dir

Answer: a) pwd

Explanation: The pwd command is used to display the current working directory in UNIX.


35. What is the primary purpose of the touch command in UNIX?

a) Display file contents

b) Change file permissions

c) Create an empty file or update the timestamp of an existing file

d) Remove a file

Answer: c) Create an empty file or update the timestamp of an existing file

Explanation: The touch command is primarily used to create an empty file or update the timestamp of an existing file in UNIX.


36. Which command is used to display the last modification time of a file in UNIX?

a) mtime

b) ltime

c) stat

d) ls -l

Answer: c) stat

Explanation: The stat command is used to display detailed information about a file, including its last modification time, in UNIX.


37. What is the purpose of the du command in UNIX?

a) Display file type

b) Display file permissions

c) Display the size of a file or directory

d) Count lines in a file

Answer: c) Display the size of a file or directory

Explanation: The du command is used to display the size of a file or directory in UNIX.


38. Which command is used to remove a file in UNIX?

a) rm

b) del

c) remove

d) erase

Answer: a) rm

Explanation: The rm command is used to remove a file in UNIX.


39. What is the purpose of the ln command in UNIX?

a) Create a symbolic link

b) Create a hard link

c) Change file ownership

d) Display file permissions

Answer: a) Create a symbolic link

Explanation: The ln command is used to create a symbolic link in UNIX.


40. Which command is used to display the contents of a file in UNIX?

a) more

b) less

c) cat

d) tail

Answer: c) cat

Explanation: The cat command is used to display the contents of a file in UNIX.


41. What is the primary purpose of the mv command in UNIX?

a) Copy files or directories

b) Move files or directories

c) Rename files or directories

d) Create files or directories

Answer: b) Move files or directories

Explanation: The mv command is primarily used to move files or directories in UNIX.


42. Which command is used to change the permissions of a file or directory in UNIX?

a) chmod

b) chown

c) chgrp

d) perm

Answer: a) chmod

Explanation: The chmod command is used to change the permissions of a file or directory in UNIX.


43. What is the purpose of the grep command in UNIX?

a) Display file contents

b) Search for patterns in files

c) Display file permissions

d) Sort lines of text files

Answer: b) Search for patterns in files

Explanation: The grep command is used to search for patterns in files in UNIX.


44. Which command is used to display the last few lines of a file in UNIX?

a) tail

b) head

c) more

d) less

Answer: a) tail

Explanation: The tail command is used to display the last few lines of a file in UNIX.


45. What is the purpose of the chmod command in UNIX?

a) Change file permissions

b) Change file ownership

c) Display file contents

d) Create a new file

Answer: a) Change file permissions

Explanation: The chmod command is used to change file permissions in UNIX.


46. Which command is used to display the file type of a file in UNIX?

a) type

b) file

c) filetype

d) kind

Answer: b) file

Explanation: The file command is used to display the file type of a file in UNIX.


47. What is the purpose of the ln command with the -s option in UNIX?

a) Create a symbolic link

b) Create a hard link

c) Change file ownership

d) Display file permissions

Answer: a) Create a symbolic link

Explanation: The ln command with the -s option is used to create a symbolic link in UNIX.


48. Which command is used to display the current date and time in UNIX?

a) time

b) date

c) clock

d) datetime

Answer: b) date

Explanation: The date command is used to display the current date and time in UNIX.


49. What is the purpose of the wc -l command in UNIX?

a) Count the number of characters in a file

b) Count the number of lines in a file

c) Display file contents

d) Sort lines of text files

Answer: b) Count the number of lines in a file

Explanation: The wc -l command is used to count the number of lines in a file in UNIX.


50. Which command is used to rename a file in UNIX?

a) rename

b) mv

c) rn

d) ren

Answer: b) mv

Explanation: The mv command is used to rename a file in UNIX.

Related Articles

Linux MCQ

Welcome to Linux Multiple Choice Questions (MCQ) Section Embark on a journey through the world of...