How to copy an entire directory structure except certain files?
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.
How to copy an entire directory structure except certain files?
Suppose I have a large directory with subdirectories nested to arbitrary levels and I want to copy this entire directory, except certain files in it, to another location, what are the shell commands to do this?
That is, the command just recursively copies everything in dir1 to dir2 without preserving directory hierarchies. I've tried several ways but none seems to work. The clause -prune only works on directories, not files. Grep searches file contents, not filenames. When -exec expands the arguments to the cp command from {}, the directory hierarchies are lost.
That would probably be fine by me if space isn't an issue. The thing is, I'm copying from HD to my USB flash drive, and the files to be excluded are really huge.
I suppose I can make a copy of the directory on HD, remove the unwanted files, copy the cleaned up directory to the thumb drive, then delete the cleaned up directory. But that seems wasteful in terms of disk space and waiting time (the directory is tens of GBs), not to mention the impracticality when disk space is low.
If there is another way, I would prefer to avoid this route. (Not to mention the excitement of enhancing my Linux skills.)
Try Krusader. It's a 2 panel file manager like the old PC Commander from the days of DOS. It has very good filters which include ignoring individual files, directories, extensions, dates, etc.
I had been using Unison which is a useable GUI for rsync, but Krusader is not only better but faster. I now use it for backups to USB & NAS and for copying between desktop and laptop.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.