Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Simple question, I'm running the following find command:

find . -type d \( -path ./.git -o   \
                  -path ./log -o    \
                  -path ./public -o \
                  -path ./tmp       \) \
                  -prune -o         \

To list all the files in my directory, excluding the specified directories.

This works great, however, what I want to also do is exclude any actual directories from the output, so if there is a directory structure as follows:

  -- foo.text
  -- bar.text

when I run my command I'd like to see:


instead of:


Can anybody help?

share|improve this question

Just use ! -type d:

find . -type d \( -path ./.git -o \
                  -path ./log -o \
                  -path ./public -o \
                  -path ./tmp \) -prune -o \
       ! -type d -print
share|improve this answer
find . -type f

will do it. You can do exec if you want to operate on file names.

share|improve this answer
yes, but I need to exclude all files under certain directories. – TheDelChop May 23 '13 at 19:40
-type f is for regular files. directories and regular files are 2 of many different types of files on Unix. With -type f, you're excluding directories, but also all the other types of files like symlinks, sockets, fifos, devices, doors... – Stéphane Chazelas May 23 '13 at 20:07
@StéphaneChazelas, doors? – user1717828 Feb 19 at 19:43

Here's one way to do it. I'm piping your output from find (using xargs) to a little bit of bash which asks the question "Is this not a directory?" and if it's not, it echoes it to your terminal.

Here's the whole she-bang:

find . -type d \( -path ./.git -o -path ./log -o -path ./public -o -path ./tmp \) -prune -o -print | xargs -i bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi'

Here's just my addition:

xargs -i bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi'

To explain:

xargs -i replace string "{}" with arguments (those that are piped in)

bash -c commands read from string

if [ ! -d "{}"]; is this a directory.

echo "{}" echo the find result.

fi; finish if.

share|improve this answer
There, you're turning the filename into shell code. Typical privilege escalation path. As one can create a file called $(do-what-I-want) for instance to have you do what he wants. – Stéphane Chazelas May 23 '13 at 20:12

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.