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 side by side in UNIX?
a) diff
b) sdiff
c) cmp
d) compare
Answer: b) sdiff
Explanation: The sdiff command is used to display the differences between two files side by side in UNIX.
2. Which command is used to remove leading and trailing whitespace from each line in a file in UNIX?
a) trim
b) whitespace
c) strip
d) sed ‘s/^ *//;s/ *$//’
Answer: d) sed ‘s/^ //;s/ $//’
Explanation: The sed command with the specified pattern is used to remove leading and trailing whitespace from each line in a file in UNIX.
3. What is the purpose of the touch command in UNIX?
a) Display file permissions
b) Create an empty file
c) Update access and modification timestamps of a file
d) Rename a file
Answer: c) Update access and modification timestamps of a file
Explanation: The touch command is used to update access and modification timestamps of a file in UNIX.
4. Which command is used to concatenate files and print on the standard output in UNIX?
a) combine
b) concat
c) merge
d) cat
Answer: d) cat
Explanation: The cat command is used to concatenate files and print on the standard output in UNIX.
5. What is the function 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.
6. Which command is used to display the differences between two files in a side-by-side format in UNIX?
a) diff
b) sdiff
c) cmp
d) compare
Answer: b) sdiff
Explanation: The sdiff command is used to display the differences between two files in a side-by-side format in UNIX.
7. What is the purpose of the nl command in UNIX?
a) Display file permissions
b) Count lines in a file
c) Number lines in a file
d) Display file contents
Answer: c) Number lines in a file
Explanation: The nl command is used to number lines in a file in UNIX.
8. Which command is used to change the case of characters in a file in UNIX?
a) change_case
b) casemap
c) case
d) tr ‘[a-z]’ ‘[A-Z]’
Answer: d) tr ‘[a-z]’ ‘[A-Z]’
Explanation: The tr command with the specified pattern is used to change the case of characters in a file in UNIX.
9. What is the primary function 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.
10. Which command is used to reverse the order of characters in each line of a file in UNIX?
a) reverse
b) rev
c) flip
d) invert
Answer: b) rev
Explanation: The rev command is used to reverse the order of characters in each line of a file in UNIX.
11. What is the purpose of the comm 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: b) Compare two sorted files line by line
Explanation: The comm command is used to compare two sorted files line by line in UNIX.
12. 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.
13. What is the primary function of the uniq command in UNIX?
a) Display unique lines from sorted files
b) Display file permissions
c) Replace text patterns in a file
d) Extract specific columns of text from a file
Answer: a) Display unique lines from sorted files
Explanation: The uniq command is used to display unique lines from sorted files in UNIX.
14. Which command is used to count the number of words, lines, and characters in a file in UNIX?
a) wc
b) count
c) wordcount
d) stats
Answer: a) wc
Explanation: The wc command is used to count the number of words, lines, and characters in a file in UNIX.
15. 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.
16. Which command is used to remove duplicate lines from a sorted file in UNIX?
a) remove_duplicates
b) dedup
c) uniq
d) remove
Answer: c) uniq
Explanation: The uniq command is used to remove duplicate lines from a sorted file in UNIX.
17. What is the purpose 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.
18. 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.
19. What is the primary role of the head command in UNIX?
a) View the contents of a file one page at a time
b) Display file permissions
c) Change file ownership
d) Display the first lines of a file
Answer: d) Display the first lines of a file
Explanation: The head command is primarily used to display the first lines of a file in UNIX.
20. Which command is used to display file permissions in UNIX?
a) chmod
b) chown
c) grep
d) ls -l
Answer: d) ls -l
Explanation: The ls -l command is used to display detailed information about files, including permissions, in UNIX.
21. What is the purpose of the awk command in UNIX?
a) Extract specific columns of text from a file
b) Search and replace text in a file
c) Display file permissions
d) View the contents of a file one page at a time
Answer: a) Extract specific columns of text from a file
Explanation: The awk command is used to extract specific columns of text from a file based on specified delimiters in UNIX.
22. Which command is used to search for patterns in files and display matching lines?
a) grep
b) sed
c) awk
d) cut
Answer: a) grep
Explanation: The grep command is used to search for patterns in files and display matching lines in UNIX.
23. What is the primary function of the sed command in UNIX?
a) Display file contents
b) Search for patterns in files
c) Perform text manipulation tasks
d) Change file permissions
Answer: c) Perform text manipulation tasks
Explanation: The sed command is primarily used to perform text manipulation tasks, such as search and replace, in UNIX.
24. Which command is used to change the permissions of a file or directory in UNIX?
a) chmod
b) chown
c) grep
d) sed
Answer: a) chmod
Explanation: The chmod command is used to change the permissions of a file or directory in UNIX.
25. What command is used to change the owner and group of a file in UNIX?
a) chmod
b) chown
c) grep
d) sed
Answer: b) chown
Explanation: The chown command is used to change the owner and group of a file in UNIX.
26. 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.
27. Which command is used to extract a specific range of lines from a file in UNIX?
a) cut
b) slice
c) extract
d) sed
Answer: b) slice
Explanation: The slice command is not a native UNIX command. However, you can achieve this functionality using tools like sed or awk.
28. What is the primary function 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.
29. 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.
30. What is the purpose 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.
31. Which command is used to replace occurrences of a specified string in a file in UNIX?
a) replace
b) substitute
c) sed ‘s/old_string/new_string/g’
d) grep ‘old_string’ ‘new_string’
Answer: c) sed ‘s/old_string/new_string/g’
Explanation: The sed command with the specified pattern is used to replace occurrences of a specified string in a file in UNIX.
32. What is the purpose of the tee command in UNIX?
a) Concatenate files
b) Display the last lines of a file
c) Redirect output to multiple files and standard output simultaneously
d) Replace text patterns in a file
Answer: c) 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.
33. Which command is used to find files by their permissions in UNIX?
a) find -permissions
b) grep -permissions
c) chmod -permissions
d) ls -permissions
Answer: d) ls -permissions
Explanation: The ls command with specific options can be used to find files by their permissions in UNIX.
34. What is the purpose 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.
35. Which command is used to display the contents of multiple files in columns in UNIX?
a) paste
b) combine
c) merge
d) column
Answer: a) paste
Explanation: The paste command is used to display the contents of multiple files in columns in UNIX.
36. What is the function 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.
37. Which command is used to count the occurrences of each unique line in a file in UNIX?
a) count
b) tally
c) uniq -c
d) unique
Answer: c) uniq -c
Explanation: The uniq -c command is used to count the occurrences of each unique line in a file in UNIX.
38. What is the purpose of the fmt command in UNIX?
a) Format text files
b) Filter text
c) Merge lines of files
d) Translate characters
Answer: a) Format text files
Explanation: The fmt command is used to format text files in UNIX.
39. Which command is used to display the differences between two files side by side in UNIX?
a) diff
b) sdiff
c) cmp
d) compare
Answer: b) sdiff
Explanation: The sdiff command is used to display the differences between two files side by side in UNIX.
40. What is the primary role of the pr command in UNIX?
a) Paginate or columnate files for printing
b) Filter text
c) Sort lines of text files
d) Translate characters
Answer: a) Paginate or columnate files for printing
Explanation: The pr command is primarily used to paginate or columnate files for printing in UNIX.
41. Which command is used to display the differences between two files in a side-by-side format in UNIX?
a) diff
b) sdiff
c) cmp
d) compare
Answer: b) sdiff
Explanation: The sdiff command is used to display the differences between two files in a side-by-side format in UNIX.
42. What is the purpose of the comm 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: b) Compare two sorted files line by line
Explanation: The comm command is used to compare two sorted files line by line in UNIX.
43. 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.
44. What is the primary function of the uniq command in UNIX?
a) Display unique lines from sorted files
b) Display file permissions
c) Replace text patterns in a file
d) Extract specific columns of text from a file
Answer: a) Display unique lines from sorted files
Explanation: The uniq command is used to display unique lines from sorted files in UNIX.
45. Which command is used to count the number of words, lines, and characters in a file in UNIX?
a) wc
b) count
c) wordcount
d) stats
Answer: a) wc
Explanation: The wc command is used to count the number of words, lines, and characters in a file in UNIX.
46. 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.
47. Which command is used to remove duplicate lines from a sorted file in UNIX?
a) remove_duplicates
b) dedup
c) uniq
d) remove
Answer: c) uniq
Explanation: The uniq command is used to remove duplicate lines from a sorted file in UNIX.
48. What is the purpose 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.
49. 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.
50. What is the primary role of the head command in UNIX?
a) View the contents of a file one page at a time
b) Display file permissions
c) Change file ownership
d) Display the first lines of a file
Answer: d) Display the first lines of a file
Explanation: The head command is primarily used to display the first lines of a file in UNIX.