UNIX MCQs – File Manipulation (Part -3)

UNIX Question and Answer – File Manipulation

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

1. 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.


2. Which command is used to delete a specific line from a file in UNIX?

a) delete

b) del

c) sed ‘/pattern/d’

d) grep ‘/pattern/’

Answer: c) sed ‘/pattern/d’

Explanation: The sed command with the specified pattern is used to delete a specific line from a file in UNIX.


3. What is the 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 used to extract specific columns of text from a file in UNIX.


4. Which command is used to sort the lines of a file numerically in reverse order in UNIX?

a) sort -n

b) sort -r

c) sort -rn

d) sort -nr

Answer: d) sort -nr

Explanation: The sort command with the -nr option is used to sort the lines of a file numerically in reverse order in UNIX.


5. What is the primary function of the tail command in UNIX?

a) Display the last lines of a file

b) Display file permissions

c) Change file ownership

d) Display file contents

Answer: a) Display the last lines of a file

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


6. Which command is used to display only the unique lines from two sorted files in UNIX?

a) unique

b) uniq

c) sort

d) comm -12

Answer: d) comm -12

Explanation: The comm command with the -12 option is used to display only the unique lines from two sorted files in UNIX.


7. 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.


8. Which command is used to display the size of a file in UNIX?

a) size

b) file

c) stat

d) du

Answer: d) du

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


9. What is the primary role 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.


10. Which command is used to display the difference between two files line by line in UNIX?

a) compare

b) diff

c) cmp

d) sdiff

Answer: b) diff

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


11. 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.


12. 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.


13. 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.


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 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.


16. 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.


17. 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.


18. 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.


19. 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.


20. 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.


21. 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.


22. 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.


23. 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.


24. 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.


25. 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.


26. 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.


27. Which command is used to append the contents of one file to another in UNIX?

a) append

b) cat

c) merge

d) concat

Answer: b) cat

Explanation: The cat command is used to concatenate files and can be used to append the contents of one file to another in UNIX.


28. What is the purpose 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.


29. 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.


30. 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.


31. Which command is used to search for a pattern in a file and display the line number where the pattern is found in UNIX?

a) grep -n

b) find

c) awk

d) sed

Answer: a) grep -n

Explanation: The grep command with the -n option is used to search for a pattern in a file and display the line number where the pattern is found in UNIX.


32. What is the primary 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.


33. 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.


34. 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.


35. Which command is used to display the differences between two files in a side-by-side format, highlighting the differences 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 differences in UNIX.


36. What is the purpose 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.


37. Which command is used to create a symbolic link in UNIX?

a) symlink

b) ln

c) link

d) mklink

Answer: b) ln

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


38. 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.


39. 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.


40. 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.


41. 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.


42. 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.


43. 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.


44. 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.


45. 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.


46. 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.


47. 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.


48. 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.


49. 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.


50. 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.

Related Articles

Linux MCQ

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