Consider the following operations to be performed in Unix : “The pipe sorts…
2016
Consider the following operations to be performed in Unix :
“The pipe sorts all files in the current directory modified in the month of “June” by order of size and prints them to the terminal screen. The sort option skips ten fields then sorts the lines in numeric order.”
Which of the following Unix command will perform above set of operations ?
- A.
ls – l | grep “June” | sort + 10n
- B.
ls – l | grep “June” | sort + 10r
- C.
ls – l | grep – v “June” | sort + 10n
- D.
ls – l | grep – n “June” | sort + 10x
Attempted by 50 students.
Show answer & explanation
Correct answer: A
Answer: ls -l | grep "June" | sort +10n
Explanation: This pipeline produces a detailed listing, keeps only entries modified in June, and then sorts numerically after skipping ten fields, which implements the requested operations.
Run ls -l to get a detailed listing that includes file size and modification month.
Pipe to grep "June" to select only lines for files modified in June.
Pipe to sort +10n to skip the first ten fields and perform a numeric (ascending) sort on the remaining field, achieving the requested sorting by size.
Note: The +POS syntax for sort is historical and may be deprecated on some systems. A modern equivalent is: sort -k11,11 -n to sort numerically by the 11th field.