Using a single "find" cmd to search for multiple file types and output individual files

Hi All,

I am new here but I have a scripting question that I can't seem to figure out with the "find" cmd.

What I am trying to do is to only have to run a single find cmd parsing the directories and output the different file types to induvidual files and I have been running into problems. Below is my code:

find $ROOTDIR  \(-type f -links +1 -exec ls -liad {} \; > $BASEDIR/$OUTDIR/hardlink$EXT 2>> $ERRFILE \), \
  \(-type l -ls > $BASEDIR/$OUTDIR/symlink$EXT 2>> $ERRFILE \), \
  \(-type b > $BASEDIR/$OUTDIR/blockdev$EXT 2>> $ERRFILE \), \
  \(-type s > $BASEDIR/$OUTDIR/sock$EXT 2>> $ERRFILE \), \
  \(-type D > $BASEDIR/$OUTDIR/door$EXT 2>> $ERRFILE \), \
  \(-type p > $BASEDIR/$OUTDIR/pipe$EXT 2>> $ERRFILE \), \
  \(-type c > $BASEDIR/$OUTDIR/chardev$EXT 2>> $ERRFILE \)

When this is run I get the output:

Any help is appreciated!

Thanks

It means what it says, ), is not valid.

Everywhere you have ), try ) instead.

find doesn't recognize ), as a predicate so it's treating it as an option, an option it does not understand. Remove the comma and \) will properly match the opening \(.

All of those redirections are handled by the shell before find is invoked. find will not see any of them and since they all clobber each other, all stdout will go to chardev$EXT.

Further, even if the redirections weren't an issue, you would need one -exec per -type.

You could use find only for finding files with more than one hardlink, piping its output into a while-read loop which uses sh to write to the appropriate file.

Alternatively, you can add an -exec for each -type, but each -exec will need to run a small shell script to redirect output to the target file. There is no other way to redirect the streams of individual -exec's because -exec does not use a shell to parse its arguments.

Regards,
Alister

Ok, awesome. That explains the results and I assumed that it was something like that but didn't understand how the find expressions were used.

Will let you know what I end up using.

Thanks again