I have to come up with a find command to find certain files in a directory. The directory has sub directories and sym-links to other directories. If I use the following find command it ignores the sym-links:

find $dir/ -name '*.out' -size 0 -mtime +0 

The following follows the sym-links:

find -L $dir/ -name '*.out' -size 0 -mtime +0 2

I am trying to figure out a way to use -prune and additional -name flags to omit certain elements from the directory. I need something that works on both Linux and AIX.

Some commands I've tried:

find -L . ( -name dest ) -prune -o -name "*.out"
find -L $dir -name *.out ( ! -name "dest" -prune )
  • Can you post what you tried with -prune?
    – h3rrmiller
    Sep 14 '17 at 14:04
  • Did you read documentation of find ? BTW you could compile and use GNU findutils on your AIX system Sep 14 '17 at 14:04
  • @h3rrmiller Some commands that i tried without success <br/> find -L . ( -name dest ) -prune -o -name "*.out" <br/> find -L $dir -name *.out ( ! -name "dest" -prune )
    – Jay
    Sep 14 '17 at 14:35

Without an "action" (like -print), find will print out each file it visits. This behavior is why find -L . ( -name dest ) -prune -o -name "*.out" still shows the files you are pruning. find has to visit the file before it can evaluate the conditions you provided.

Adding the -print action to the end of your find command should do the trick.

find -L . -name dest -prune -o -name "*.out" -print

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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