Saturday, October 24, 2015

Archive or Delete Old Files

With a single command in Linux, we can archive or delete thousands of files.

Objective: Delete old pdf files more than 60 days old.


mtime
mtime is the file modify time. The mtime gets updated when you modify a file. Whenever you update content of a file or save a file the mtime gets updated.

For instance, "/opt/jakarta-tomcat-4.1.24/temp/" directory contains old pdf files. We want to delete those files which were last modified more than 60 days ago.

find /opt/jakarta-tomcat-4.1.24/temp/*.pdf -mtime +60 -type f -exec rm -f {} \; 


Objective: Archive old pdf files more than 60 days old.

find /opt/jakarta-tomcat-4.1.24/temp/* -name *.pdf -mtime +60 -type f -exec mv -f {} /app/u04/logs/oldpdf/ \;


Objective: Archive all files from one server to another.

Source location: /opt/RadiusCDR/CSV/10.10.0.69/
Destination location: /app/u03/rman_backup/Radius_CSV_Backup/10.10.0.69/
Destination IP: 10.10.10.3


find /opt/RadiusCDR/CSV/10.10.0.69 -name CDRs_2012-12-* -type f -exec cp -f {} root@10.10.10.3:/app/u03/cdr_backup/Radius_CSV_Backup/10.10.0.69/ \;


Cheers!!

No comments:

Restore Archived Log into VMware Aria Operations for Logs (formerly known as vRealize Log Insight - vRLI)

As we cannot keep all logs in searchable space in vRLI production system due to performance and slowness issue, it is always recommended to ...