简体   繁体   中英

Copy files within multiple directories to one directory

We have an Ubuntu Server that is only accessed via terminal, and users transfer files to directories within 1 parent directory (ie /storage/DiskA/userA/doc1.doc /storage/DiskA/userB/doc1.doc). I need to copy all the specific files within the user folders to another dir, and I'm trying to specifically target the.doc extension.

I've tried running the following:

cp -R /storage/diskA/*.doc /storage/diskB/monthly_report/

However, it keeps telling me there is no such file/dir.

I want to be able to just pull the.doc files from all the user dirs and transfer to that dir, /storage/monthly_report/.

I know this is an easy task, but apparently, I'm just daft enough to not be able to figure this out. Any assistance would be wonderful.

EDIT: I updated the original to show that I have 2 Disks. Moving from Disk A to Disk B.

I would go for find -exec for such a task, something like:

find /storage/DiskA -name "*.doc" -exec cp {} /storage/DiskB/monthly_report/ \;

That should do the trick.

Use

 rsync -zarv --include="*/" --include="*.doc" --exclude="*"  /storage/diskA/*.doc /storage/diskB/monthly_report/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM