10

I need to get a list of names of files with non-zero size inside a directory. This should be in a shell script, so bash (or a Perl one-liner) would be ideal.

andreas-h
  • 1,054
  • 1
  • 16
  • 27

3 Answers3

14
find /path/to/dir -type f -size +0
Jenny D
  • 27,358
  • 21
  • 74
  • 110
1
find /searchdir -type f -size +0c 

will find files with a size of one or more bytes in /searchdir and below.

Sven
  • 97,248
  • 13
  • 177
  • 225
1

Shell only, avoiding find, without recursion into subdirectories:

bash (for unset GLOBIGNORE):

for file in .* *; do
  test . = "$file" && continue
  test .. = "$file" && continue
  # if you just want real files, no symlinks
  # test -L "$file" && continue
  test -f "$file" || continue
  test -s "$file" || continue
  # here do what you want with what is left
done
Hauke Laging
  • 5,157
  • 2
  • 23
  • 40