How to delete old files in Linux

In order to delete OLD files older than XX days, execute following command on your Linux box, where /opt/app/logs is the directory where files are located:

find /opt/app/logs -mtime +XX -exec rm {} \;

For example, to delete files older than 90 days:

find /opt/app/logs -mtime +90 -exec rm {} \;

If the same directory has multiple type of files, and want to delete ONLY those with .log extension:

find /opt/app/logs -name '*.log' -mtime +90 -exec rm {} \;

If you want to see the files to be deleted, run the same command removing "-exec rm {} \;"

Comments

Popular posts from this blog

Update Manager 6.5 issue ""interface com.vmware.vim.binding.integrity.VcIntegrity is not visible from class loader""

An Overview of Hyper-V Live Migration

iSCSI initiator configuration in RedHat Enterprise Linux 5