Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
I am attempting to copy a set of sub folders from their multiple parent directories to a new location.
For example, I have three folders to copy:
/home/user/folder1/photos
/home/user/folder2/photos
/home/user/folder3/photos
I would like them to be copied to:
/newlocation/folder1
/newlocation/folder2
/newlocation/folder3
In actuality there are many folders besides folder1, folder2, folder3, and no numerical order exists. So, the folder named 'photos' would be copied to its parent folder's name in a new location. I would need this to occur for all folders in the '/home/user' directory.
Sorry if confusing, I would appreciate any assistance. Thank you!
I am attempting to copy a set of sub folders from their multiple parent directories to a new location.
For example, I have three folders to copy:
/home/user/folder1/photos
/home/user/folder2/photos
/home/user/folder3/photos
I would like them to be copied to:
/newlocation/folder1
/newlocation/folder2
/newlocation/folder3
In actuality there are many folders besides folder1, folder2, folder3, and no numerical order exists. So, the folder named 'photos' would be copied to its parent folder's name in a new location. I would need this to occur for all folders in the '/home/user' directory.
Sorry if confusing, I would appreciate any assistance. Thank you!
Firs of all make a backup of your directories, just to be sure.
How about just using 'rsync -nvra /home/user/ /newlocation/'? The "-n" will only --dry-run the process (no modifs) and the "-v" will show you what it's doing, so after you read 'man rsync' and agree with what it's doing remove the "-n"?
for i in `ls -l $OLD_LOCATION | grep ^d | awk '{print $9}'`; do
cp $OLD_LOCATION/$i/photos $NEW_LOCATION/$i
done
Regards
Thank you, this worked absolutely perfect, especially since the original folder names were unknown, and were too extensive to place in a pre defined array.
The only change I made was to the cp command, changing to:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.