How can I list only non-empty files using ls?
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Quiet Intelligence
--
Chapters
00:00 How Can I List Only Non-Empty Files Using Ls?
00:16 Answer 1 Score 10
00:22 Answer 2 Score 21
01:01 Answer 3 Score 14
01:13 Accepted Answer Score 67
01:22 Thank you
--
Full question
https://superuser.com/questions/191889/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #commandline #bash #shell #ls
#avk47
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Quiet Intelligence
--
Chapters
00:00 How Can I List Only Non-Empty Files Using Ls?
00:16 Answer 1 Score 10
00:22 Answer 2 Score 21
01:01 Answer 3 Score 14
01:13 Accepted Answer Score 67
01:22 Thank you
--
Full question
https://superuser.com/questions/191889/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #commandline #bash #shell #ls
#avk47
ACCEPTED ANSWER
Score 67
I'd use find dirname -not -empty -ls
, assuming GNU find.
ANSWER 2
Score 21
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.
ANSWER 3
Score 14
ls -l | awk '{if ($5 != 0) print $9}'
If you are intent on using ls
, you need a little help from awk
.
ANSWER 4
Score 10
find dirname -type f ! -empty