Linux – Looking for the name of the smallest file in Linux?

Looking for the name of the smallest file in Linux?… here is a solution to the problem.

Looking for the name of the smallest file in Linux?

Suppose you have to find the name of the 4th smallest (non-hidden) file in the directory

What is the correct command to do this? Let’s say I’m a statement that only knows ls -l, head, tail, line, and awk '{print}'.

Solution

From man ls:-S sorts the outputs in descending order of size, and -r reverses the order of the outputs

So my solution looks like

ls -rS | sed -n '4p'

Or, or,

ls -rS | awk 'NR==4'

Related Problems and Solutions