Results 1 to 5 of 5
I'm starting to master the learning curve on Linux, it's a good thing. But there are two things that I want to learn:
1. with find you can do this:
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 05-09-2003 #1Just Joined!
- Join Date
- Apr 2003
- Posts
- 55
multiple -execs using find command
I'm starting to master the learning curve on Linux, it's a good thing. But there are two things that I want to learn:
1. with find you can do this:
find -name|criteria something -exec do_something;
but how would you do multiple operations in that same search pass? Specifically I want to execute chown, chgrp, chmod and perhaps touch.
And, it's important that I do each of the operations on the file while in the search path because the changes made will involve the criteria I'm searching by; they wouldn't be found again on a second find.
2. Any good tutorials on creating a batch file? Once things work I don't want to have to retype them
Thank you,
Sam Fullman
Compass Point Media
- 05-09-2003 #2Linux Engineer
- Join Date
- Apr 2003
- Location
- Sweden
- Posts
- 796
Something like this
find / -name "*.tar" | xargs chown root:root
But for that i should do a little program, like this.
Copy that into a file and perform chmod 755 on it to make it executeble.Code:#!/bin/sh MYTARFILES=`find / -name "*.tar"` for i in $MYTARFILES do echo "Beginning with file $i" echo "Chmodding $i 770" chmod 770 $i if [ $? = 0 ] then echo "Chmod went good" else echo "Chmod went BAD" exit 1 fi echo "Chowning $i root:root" chown root:root $i if [ $? = 0 ] then echo "Chown went good" else echo "Chown went BAD" exit 1 fi done
Regards
If you want some program but dont like to program, order it from my page. http://www.utterberg.com/
Regards
Andutt
- 05-09-2003 #3Just Joined!
- Join Date
- Nov 2002
- Location
- USA
- Posts
- 99
BTW, command line scripts are not called batch files like in DOS. In Linux they are called shell scripts and they can be much more powerful than batch files.
The syntax depends on which shell you are using at the command line terminal. Most likely you are using the bash shell. There are a variety of how-to's and documentation on the web for bash scripting. Try the tldp.org site and specifically, http://www.ibiblio.org/pub/Linux/doc...tro-HOWTO.html
- 05-09-2003 #4Just Joined!
- Join Date
- Apr 2003
- Posts
- 55
Ok, but my question was..
I appreciate the resources and will look. But the original question was, can you run multiple -exec commands on a find command, and if so how.
Thanks again,
Sam Fullman
- 05-09-2003 #5Linux Enthusiast
- Join Date
- Jun 2002
- Location
- San Antonio
- Posts
- 621
you can run -exec with multiple commands, but not multiple -exec flags. For instance:
find . -name "*.txt" -exec ls {} \&\& ls {} \;I respectfully decline the invitation to join your delusion.



