using multiple -exec commands in a single find command?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
using multiple -exec commands in a single find command?
Hi all,
Is it possible to have multiple -exec's in a single command? lets say i want to gzip up some files that i have found using the find command, and then somehow extract the contents of the gzip file i just created into another folder.
well you can use multiple exec's easily, but they will work in total isolation on a per command basis, e.g. you might echo the name of the matched file to a log, and then also add it to an archive, but there's no sense of aggregation over the files or anything. you say you want to extract the entire contents of a single archive, well that's not going to be done by processing it on a per file basis unless you explicitly extract each file. sure there are many ways odd things make sense when you know the whole story, but that's never going to make sense!
There are several functions you can use to string together multiple commands in one command line action. The most common one is the pipe "|", which feeds the output from one command into the input of the next. I'd use that instead of multiple -exec functions. Use find to generate a list of files you want to zip up and then pipe it into gzip. Then follow up with a semicolon separator to run a second command to extract them elsewhere.
Open up "man bash" and read the section on shell grammar. Also check out some of the many online shell scripting tutorials, such as LinuxCommand.org, where you can learn a lot about using the shell in general as well. With a little work you can become comfortable with the command line in no time. ^o^
Last edited by David the H.; 03-19-2006 at 11:52 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.