Shamrock
Shamrock

Reputation: 1

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 (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.

Upvotes: 0

Views: 255

Answers (3)

user27942901
user27942901

Reputation: 1

Can try with following,

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

Upvotes: 0

Wojtek Kalka
Wojtek Kalka

Reputation: 19

Use

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

Upvotes: 0

Dominique
Dominique

Reputation: 17493

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.

Upvotes: 2

Related Questions