How can I list only non-empty files using ls?
-------------------------------------------------------------------------------
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
-------------------------------------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3 Looping
--
Chapters
00:00 Question
00:22 Accepted answer (Score 65)
00:36 Answer 2 (Score 21)
01:27 Answer 3 (Score 14)
01:43 Answer 4 (Score 10)
01:55 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
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
-------------------------------------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3 Looping
--
Chapters
00:00 Question
00:22 Accepted answer (Score 65)
00:36 Answer 2 (Score 21)
01:27 Answer 3 (Score 14)
01:43 Answer 4 (Score 10)
01:55 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