Sort Files by Size with ls
I love reading man pages for even the most basic Unix commands like ls, because there’s always something interesting to learn. Today I discovered that it’s possible to sort ls output by file size.
Sort ls by file size
Simply add the capital S to command line options and you’ll see your output sorted by file size. Be sure to use long output form (-l option). I’m adding more command to the mix because I know that /usr/lib is a directory with quite a number of files:
Reverse Sorting with ls command
Don’t know about you, but I prefer reverse sorting in most commands – this means largest objects are shown at the end of the output. The reason I do it this way is to avoid using pagers like more or less. Another reason is I can scroll up to explore further output of the ls command without having to rerun anything.
So here’s the same command run with the -r option for reverse output (I’m only showing last few lines):
That’s it for today – hope you’ve learned something new today.
See Also
I love reading man pages for even the most basic Unix commands like ls, because there’s always something interesting to learn. Today I discovered that it’s possible to sort ls output by file size.
Sort ls by file size
Simply add the capital S to command line options and you’ll see your output sorted by file size. Be sure to use long output form (-l option). I’m adding more command to the mix because I know that /usr/lib is a directory with quite a number of files:
Reverse Sorting with ls command
Don’t know about you, but I prefer reverse sorting in most commands – this means largest objects are shown at the end of the output. The reason I do it this way is to avoid using pagers like more or less. Another reason is I can scroll up to explore further output of the ls command without having to rerun anything.
So here’s the same command run with the -r option for reverse output (I’m only showing last few lines):
That’s it for today – hope you’ve learned something new today.