Which command will print the sizes of all files and directories in the tmp directory (including hidden ones) and sort them by sizes fromlargest to smallest in human readable format (e.g. 2 GB)?The output could be as follows:file.mpg 2GBfile.avi 1.8GB.backtup 1.7 GB (this is directory)I tried to use the ls and du commands but was not able to find the right switches.
Find biggest files or directories
shell script;disk usage
Here's a quick fix, use du + sort.  Try this:du -smc * | sort -nThis will ignore hidden files, but that's another easy fix:du -smc .[^.] .??* * | sort -nThis may cause warnings about if one or more of the above patterns don't match a file.  The first pattern .[^.] matches all two character filenames starting with . except for .., the second pattern, .??* matches all three letter or more filenames starting with . and * matches all files not starting with .  For a more sophisticated listing such as finding all file larger than X across a whole filesystem, or maintaining a list of filesystem growth, I have some DIY shell script I've written and can share if your interested.