Home > Mobile >  Copy files within multiple directories to one directory
Copy files within multiple directories to one directory

Time:04-13

We have an Ubuntu Server that is only accessed via terminal, and users transfer files to directories within 1 parent directory (i.e. /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.

CodePudding user response:

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.

CodePudding user response:

Use

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