Wednesday, April 22, 2015

Copy / Move / Remove (delete) Unix files with specific days

As Unix Server Admins, we keep on facing requirements or issues where we are required to copy / move / remove files of specific date or certain days older. Here i am posting the command & arguments that can be used for such requirements.


Condition - For files from source server to Destination server x days older with same timestamp.

Copying Files

find /source/Directory -mtime x -exec cp -p "{}" /destination/directory/ \;

Moving Files

find /source/Directory -mtime x -exec mv "{}" /destination/directory/ \;

Removing / Deleting Files

find /source/Directory -mtime x -exec rm "{}" \;

Where
mtime - Modified Time
exec - Execute

No comments:

Post a Comment