UNIX MCQs – File Manipulation (Part -1)

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 contents of a file in UNIX?

a) grep

b) cat

c) sed

d) chmod

Answer: b) cat

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


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


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

a) head

b) tail

c) more

d) less

Answer: b) tail

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


4. What command is used to view the contents of a file one page at a time in UNIX?

a) cat

b) more

c) less

d) head

Answer: b) more

Explanation: The more command is used to view the contents of a file one page at a time in UNIX.


5. Which command is used to search for patterns in a file in UNIX?

a) grep

b) sed

c) awk

d) cat

Answer: a) grep

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


6. What is the purpose of the sed command in UNIX?

a) Search and replace text in a file

b) Display file permissions

c) Change file ownership

d) Change file permissions

Answer: a) Search and replace text in a file

Explanation: The sed command is used to perform text manipulation tasks, such as search and replace, in UNIX.


7. Which command is used to extract specific columns of text from a file in UNIX?

a) grep

b) sed

c) awk

d) cut

Answer: c) awk

Explanation: The awk command is used to extract and manipulate specific columns of text from a file in UNIX.


8. What command is used to change the permissions of a file 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 in UNIX.


9. Which command is used to change the owner 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 of a file in UNIX.


10. What is the primary purpose of the grep command in UNIX?

a) Display file contents

b) Search for patterns in files

c) Change file permissions

d) Change file ownership

Answer: b) Search for patterns in files

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


11. Which command is used to display specific lines of a file based on pattern matching in UNIX?

a) grep

b) sed

c) awk

d) tail

Answer: c) awk

Explanation: The awk command can be used to display specific lines of a file based on pattern matching criteria in UNIX.


12. What is the purpose of the cut command in UNIX?

a) Search and replace text in a file

b) Display file permissions

c) Extract specific columns of text from a file

d) Change file ownership

Answer: c) 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.


13. Which command is used to display the last 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 lines of a file in UNIX.


14. What is the primary function of the more command in UNIX?

a) View the contents of a file one page at a time

b) Search for patterns in files

c) Change file permissions

d) Change file ownership

Answer: a) View the contents of a file one page at a time

Explanation: The more command is primarily used to view the contents of a file one page at a time in UNIX.


15. Which command is used to display the first 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 lines of a file in UNIX.


16. What is the purpose of the tail command in UNIX?

a) Display file permissions

b) View the contents of a file one page at a time

c) Search for patterns in files

d) Display the last lines of a file

Answer: d) Display the last lines of a file

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


17. Which command is used to search for patterns in files and perform text manipulation tasks?

a) grep

b) sed

c) awk

d) cut

Answer: b) sed

Explanation: The sed command is used to search for patterns in files and perform text manipulation tasks in UNIX.


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


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


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


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


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


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


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


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


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

a) rev

b) reverse

c) revfile

d) tail -r

Answer: a) rev

Explanation: The rev command is used to reverse the order of characters in each line of a file in UNIX.


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


28. Which command is used to append content to the end of a file in UNIX?

a) append

b) add

c) tail -a

d) cat >> filename

Answer: d) cat >> filename

Explanation: The cat command with the >> operator is used to append content to the end of a file in UNIX.


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


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


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


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


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


35. Which command is used to display the difference 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.


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


37. Which command is used to sort the lines of a file alphabetically in UNIX?

a) sort

b) alphabetize

c) arrange

d) order

Answer: a) sort

Explanation: The sort command is used to sort the lines of a file alphabetically in UNIX


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


39. Which command is used to display the last part of files in UNIX?

a) end

b) tail

c) last

d) bottom

Answer: b) tail

Explanation: The tail command is used to display the last part of files in UNIX.


40. What is the purpose of the tr command in UNIX?

a) Translate characters

b) Concatenate files

c) Display file permissions

d) Display file contents

Answer: a) Translate characters

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


41. Which command is used to display the specified number of lines from the beginning of a file in UNIX?

a) first

b) head

c) top

d) beginning

Answer: b) head

Explanation: The head command is used to display the specified number of lines from the beginning of a file in UNIX.


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


43. Which command is used to split a file into multiple files based on specified criteria in UNIX?

a) divide

b) split

c) separate

d) part

Answer: b) split

Explanation: The split command is used to split a file into multiple files based on specified criteria in UNIX.


44. What is the purpose of the comm command in UNIX?

a) Compare two sorted files line by line

b) Concatenate files

c) Display file permissions

d) Display file contents

Answer: a) Compare two sorted files line by line

Explanation: The comm command is used to compare two sorted files line by line in UNIX.


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


46. What is the function of the cmp command in UNIX?

a) Compare two files byte by byte

b) Compare two 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.


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

a) unique

b) uniq

c) sort

d) comm

Answer: d) comm

Explanation: The comm command is used to display the unique lines from two sorted files in UNIX.


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


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


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

Related Articles

Linux MCQ

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