[SOLVED] how to use find with exec to copy files into another location?
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.
When you use exec, you must end with either \; or \+. This is the missing argument find was complaining about above.
\; will run the specified command for each result of find. \+ ("append") will run the specified command once, placing all results into one command line argument, which can run into command line length restrictions. If you think you may be dealing with long file names, use the former.
To demonstrate the above,
Code:
anthony@miranda:~/tmp$ cat > showme.sh << exit
#!/usr/bin/env bash
echo "arguments: x \${@} x"
exit
anthony@miranda:~/tmp$ touch {0..9}.fileanthony@miranda:~/tmp$ find -type f -print
./1.file
./6.file
./5.file
./4.file
./7.file
./8.file
./3.file
./9.file
./2.file
./0.file
anthony@miranda:~/tmp$ find -type f -exec ./showme.sh "{}" \;
arguments: x ./1.file x
arguments: x ./6.file x
arguments: x ./5.file x
arguments: x ./4.file x
arguments: x ./7.file x
arguments: x ./8.file x
arguments: x ./3.file x
arguments: x ./9.file x
arguments: x ./2.file x
arguments: x ./0.file x
anthony@miranda:~/tmp$ find -type f -exec ./showme.sh "{}" \+
arguments: x ./1.file ./6.file ./5.file ./4.file ./7.file ./8.file ./3.file ./9.file ./2.file ./0.file x
I tried something similar and it worked on my system
HTH
I 'll try that i think i did, but too I was already cd into the destination dive in term
plus the word similar indicates what? just different file types or command?
When you use exec, you must end with either \; or \+. This is the missing argument find was complaining about above.
\; will run the specified command for each result of find. \+ will run the specified command once, which can run into command line length restrictions. If you think you may be dealing with long file names, use the former.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.