ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I have a directory containing about 150 sub-directories, each of which contains only files of various types. I need to get all those files together in a single directory without any of the subdirectories. Can it be done with any simple approach like "mv */*.*", or do I need to get a list of all the individual filepaths and feed that to mv?
Click here to see the post LQ members have rated as the most helpful post in this thread.
find /path/to/dir -type f -exec mv -n '{}' /path/to/target \;
The -n option prevents mv to overwrite existing files in the target directory. If you still have files in one of the source directories then you will need a slightly more complicated approach and a naming convention for the files that have the same name.
I thank both AlucardZero and crts for your help, but it seems that \; is the charm
Code:
g find /home/g/x -exec mv '{}' /home/g/y +;
find: missing argument to `-exec'
g find /home/g/x -type f -exec mv '{}' /home/g/y +;
find: missing argument to `-exec'
g find /home/g/x -type f -exec mv '{}' /home/g/y \;
g
Many thanks.
Last edited by porphyry5; 08-04-2011 at 04:02 AM.
Reason: Correction
And my syntax was slightly wrong, it should be \;.
Hi AlucardZero,
your syntax is not wrong; at least the 'find' version (GNU 4.4.2) that I am using accepts it. Although the terminating ';' is not needed when you use '-exec' with a '+', it should not lead to an error if you use it anyway. At least not in bash. Bash will simply interpret it as a line terminator. So possible sources for the error messages can be a 'find' version that does not support '-exec ... +' or maybe executing 'find' in a non-bash terminal.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.