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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
-exec command {} +
This variant of the -exec action runs the specified command on
the selected files, but the command line is built by appending
each selected file name at the end; the total number of invoca‐
tions of the command will be much less than the number of
matched files. The command line is built in much the same way
that xargs builds its command lines. Only one instance of `{}'
is allowed within the command. The command is executed in the
starting directory. If find encounters an error, this can some‐
times cause an immediate exit, so some pending commands may not
be run at all.
The actual better choice might be the "-execdir" option.
For a machine such as a macbook you won't find much difference in performance
between the two commands. However, if you look at the -exec version you can see a
subtle difference:
This means that you will find all those files with name ".file-to-delete". However
this search might return some unwanted false positives. When doing something with
sudo you should be a bit more careful. The advantage of using -exec rm {} is that
you can pass arguments to rm like this:
Code:
sudo find / -iname "*~" -exec rm -i {} \;
In this example I want to remove those backup files that emacs makes. However that
tilde could be in some obscure file that I don't know about and could be
important. Plus I want to confirm the delete. So I put the option '-i' on the rm
command. This will give me an interactive delete.
Also you can refine the usage of rm to delete directories as well as files:
In brief, the -exec gives you a bit more control over the actual command that
removes the found item. The advantage is that you use one tool to find the files,
another tool to remove them. Also not every version of the find utility has the
-delete option. So better to use each tool for its proper job. This is the unix
philosophy - one tool, one job, use them together to do what you need to do.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.