Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 5 down vote accepted
find /path/to/dir -type f -size +0
share|improve this answer
find /searchdir -type f -size +0c 

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

share|improve this answer
That will find directories as well as files. – Jenny D Feb 8 '13 at 13:59
Indeed. Fixed it. Thanks – Sven Feb 8 '13 at 13:59

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.