Ajith Prabhakaran
Ajith Prabhakaran

Reputation: 13

How to copy files along with a part of folder structure in unix?

I want to copy all the files from a folder which is more than x days old to a new path.

Source folder structure:

/opt/install/sw1/team/p2.csv
/opt/install/sw2/team/p2.csv

Destination should be:

/work/backup/sw1/team/p2.csv
/work/backup/sw2/team/p2.csv

Upvotes: 0

Views: 93

Answers (2)

tkhurana96
tkhurana96

Reputation: 939

Will this do:

mkdir /work/backup/sw1/team
find /opt/install/sw1/team -maxdepth 0 -mtime +5 -exec cp '{}' /work/backup/sw1/team \;
mkdir /work/backup/sw2/team
find /opt/install/sw2/team -maxdepth 0 -mtime +5 -exec cp '{}' /work/backup/sw2/team \;

Upvotes: 1

Penguin Brian
Penguin Brian

Reputation: 2141

If I understand correctly:

cp -a /opt/install/sw1 /opt/install/sw2

Or for verbose:

cp -av /opt/install/sw1 /opt/install/sw2

-a says to copy everything and preserve permissions. If this is not what you want, then -r might be more appropriate.

Upvotes: 0

Related Questions