cp help, copying multiple doc files from multiple dir to one dir. How do i do that?
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.
Distribution: RedHat, Fedora and CentOS. Since 2004
Posts: 10
Rep:
cp help, copying multiple doc files from multiple dir to one dir. How do i do that?
Hello,
I have 60+ directory's each containing multiple .doc files. I need to move them to a single directory and keep their file name intact. I don't think cp will do that with out listing all the file names. I was thinking of something like: cp -r /dir/*.doc /newdir . Or should I use a combo like find -type *.doc|cp /newdir?
Be careful with files that contain spaces or "evil" characters. They can break up the filename to multiple arguments.
This usually means enclosing a variable inside doublequotes.
Also be careful if you have a very large number of files. One solution is to use find with the -print0 command. Pipe the argument to "xargs -0 -L <limit> cp --target-directory /path/to/destination/"
find ./ -iname "*.doc" -print0 | xargs -0 -L 100 cp --target-directory"
For complicated operations, you can use find's -printf to print each command to run and produce a script to run afterwards.
This allows you to preview what would be done.
A common technique is to insert "echo" before a "cp", "mv" or "rm" command to verify that the command will work OK before committing to it.
Distribution: RedHat, Fedora and CentOS. Since 2004
Posts: 10
Original Poster
Rep:
Thank you
Thanks for the fast response.
Unfortunately jschiwal has a valid point. I found numerous files with long and spaced (not to mention other characters) names. These files are not getting copied. I think the safest way looks to be the manual way. I was able to copy most of the files and I will just manually copy up the rest.
Thanks for your help and saving me some hours : - ))
jschiwal's way is perfectly safe. It will use null chars as separators allowing you to correctly copy file names with spaces in the middle (or even with carriage return characters in the middle). The "echo" suggestion is also something you should take note of, for the next time.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.