Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a find command that I want to substitute a list of GIDs into.

Here's the command:

find / -follow \( -group 39 -o -acl_group 39 \) -exec ls -ln {} \; 2> $HOME/error.39.log 1> $HOME/results.39.log

I also have a file with the contents:

3  
100005  
21  
7   

How can I substitute each entry in the file into the find command in turn so that a separate output and error file is created for each?

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

You don't need to invoke ls to get at the stat information, find already did that. Use something like this instead (same output as ls -ln):

find -follow \( -group 39 -o -acl_group 39 \) -printf '%M  %n %U %G %s %Cb %Cd %CH:%CM %p\n'

See section 3.2.2 of the GNU find manual for more on the format directives.

Edit

To apply this to multiple group ids from a file:

while read; do
  find -follow \( -group $REPLY -o -acl_group $REPLY \) \
    -printf '%M  %n %U %G %s %Cb %Cd %CH:%CM %p\n'      \
    1> $HOME/results.$REPLY.log                         \
    2> $HOME/error.$REPLY.log
done < group_id_file
share|improve this answer
    
Well the key part of the problem I was trying to solve was the substitution of the GID from a file into the appropriate part of the command –  conorgriffin Jul 31 '12 at 19:57
    
You could add a while loop around find and use redirect < to get the IDs into $REPLY. I've edited the answer. –  Thor Jul 31 '12 at 20:33
    
Avoiding -exec will have great efficiency benefits if you have many files. You avoid multiple stat calls but more importantly you do not fork for every match. –  Thor Jul 31 '12 at 20:36
add comment

I'm not sure if I understood the question properly, but I have no way to comment cause I'm newbie around...Let's try:

What about a for statement? something like:

for f in `cat file_with_entries`; do
    find -follow \( -group $f -o -acl_group $f \) -exec ls -ln {} \; 2> $HOME/error.$f.log 1> $HOME/results.$f.log
done

Sorry if I didn't understand you well...

share|improve this answer
add comment

Your Answer

 
discard

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.