Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

How to recursively copy directories starting with "abc" on Linux/Unix?

I have a directory ~/plugins/ and inside there are many sub-directories. If I wanted to create a backup somewhere else of just the sub-directories starting with abc could I do that with a one line copy command? I would assume something like this would work (but it doesn't):

cp -R ~/plugins/abc* ~/destination/

I would rather use a one-line command, if possible, because I would also like to use the same syntax for rsync, and if I have to do something like

find ~/plugins/ -type d -name "abc*" -exec cp -R {} ~/destination;

then that works fine for the cp command but it would mean that I would have to run rsync once for each directory and that just doesn't seem efficient :(

question from:https://stackoverflow.com/questions/5275418/how-to-recursively-copy-directories-starting-with-abc-on-linux-unix

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not sure why what you're trying didn't work (but what is the "copy" command?), but this works on Linux at least:

cp -r ~/plugins/abc* ~/destination

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...