How can I list only non-empty files using ls?
I'd use find dirname -not -empty -ls
, assuming GNU find.
This is a job for find ls is not powerful enough.
find -maxdepth 1 -size +0 -print
-maxdepth 1
- this tells find to search the current dir only, remove to look in all sub dirs or change the number to go down 2, 3 or more levels.
-size +0
this tells find to look for files with size larger than 0
bytes. 0
can be changed to any size you would want.
-print
tells find to print out the full path to the file it finds
Edit:
Late addition: You should probably also add the -type f
switch above. This tells find to only find files. And as noted in comments below, the -print
switch is not really needed.
ls -l | awk '{if ($5 != 0) print $9}'
If you are intent on using ls
, you need a little help from awk
.