The command du
"summarizes disk usage of each FILE, recursively for directories," e.g.,
du -hs /path/to/directory
-h
is to get the numbers "human readable", e.g. get 140M
instead of 143260
(size in KBytes)
-s
is for summary (otherwise you'll get not only the size of the folder but also for everything in the folder separately)
As you're using -h
you can sort the human readable values using
du -h | sort -h
The -h
flag on sort
will consider "Human Readable" size values.
If want to avoid recursively listing all files and directories, you can supply the --max-depth
parameter to limit how many items are displayed. Most commonly, --max-depth=1
du -h --max-depth=1 /path/to/directory
From man find
-empty File is empty and is either a regular file or a directory.
So to find both empty files and directories it is sufficient to do
find ~/lists -empty
To indicate the type, you could use the %y
output format specifier
%y File's type (like in ls -l), U=unknown type (shouldn't happen)
e.g.
find ~/lists -empty -printf '%y %p\n'
or make use of an external program like ls
, which includes a --classify
option
-F, --classify
append indicator (one of */=>@|) to entries
i.e.
find ~/lists -empty -exec ls -Fd {} \;
If your definition of 'empty' is expanded to include files containing only whitespace characters, then it becomes more complicated - and more computationally intensive, since now you need to actually open at least any non-empty files and examine their contents. The most efficient way I can think of off the top of my head would be something like
find ~/list \( -empty -o \( -type f -a ! -exec grep -qm1 '[^[:blank:]]' {} \; \) \) -exec ls -Fd {} \;
(either empty, OR a file AND grep does not detect at least one non-blank character). Likely there is a better way though.
Best Answer
will get you a human-readable ascending list of the sizes of files and subdirectories in your current directory,
will summarize the current directory size.