← Space Management
Oracle · Space Management
How to clean up Oracle logs, traces, and archivelogs with find (cheatsheet)
find-based housekeeping recipes for Oracle trace files, audit files, listener logs, archivelogs, and RMAN backups by age.
Tested on11g12c18c19c21c23ai26ai
One-page recipe list for the most common Oracle housekeeping targets with find + rm. Retention values are examples — adjust to your policy. Always run the -exec ls form first to preview what will be removed.
All of these delete files permanently. Preview with -exec ls -lh {} \; before switching to -exec rm -f {} \;. Only run inside directories you own; a wrong path can wipe out data.
# ------------------------------------------------------------------
# Trace files (.trc) and their metadata (.trm) — RDBMS instance
# ------------------------------------------------------------------
find /u01/app/oracle/diag/rdbms/<db>/<instance>/trace -name '*.trc' -type f -mtime +3 -exec ls {} \;
find /u01/app/oracle/diag/rdbms/<db>/<instance>/trace -name '*.trc' -type f -mtime +3 -exec rm -f {} \;
find /u01/app/oracle/diag/rdbms/<db>/<instance>/trace -name '*.trm' -type f -mtime +1 -exec rm -f {} \;
# ------------------------------------------------------------------
# Audit files (.aud) — adump
# ------------------------------------------------------------------
find /u01/app/oracle/admin/<DB>/adump -name '*.aud' -type f -mtime +30 -exec rm -f {} \;
find /u01/app/oracle/diag/rdbms/<db>/<instance>/adump -name '*.aud' -type f -mtime +45 -exec rm -f {} \;
# ------------------------------------------------------------------
# Listener alert log_* rotation files and listener trace files
# ------------------------------------------------------------------
find /u01/app/oracle/diag/tnslsnr/<host>/<listener>/alert -name 'log_*' -type f -mtime +5 -exec rm -f {} \;
find /u01/app/oracle/diag/tnslsnr/<host>/<listener>/trace -name '<listener>_*' -type f -mtime +5 -exec rm -f {} \;
# ------------------------------------------------------------------
# Grid Infrastructure trace (ASM, CRS) — adjust retention (usually short)
# ------------------------------------------------------------------
find /u01/app/grid/diag/asm/+asm/+ASM1/trace -name '*.trc' -type f -mtime +1 -exec rm -f {} \;
find /u01/app/grid/diag/crs/<host>/crs/trace -name '*.trc' -type f -mtime +1 -exec rm -f {} \;
# ------------------------------------------------------------------
# Filesystem-based archivelogs (when NOT using RMAN backups+deletes)
# ------------------------------------------------------------------
find /path/to/archive -name '*.arc' -type f -mtime +3 -exec ls -lh {} \;
find /path/to/archive -name '*.arc' -type f -mtime +3 -exec rm -f {} \;
# ------------------------------------------------------------------
# RMAN backup files retained by age (safer to let RMAN retention policy do this)
# ------------------------------------------------------------------
find /backup/rman/full -type f -mtime +7 -exec ls -lh {} \;
find /backup/rman/full -type f -mtime +7 -exec rm -f {} \;
find /backup/rman/arch -type f -mtime +14 -exec rm -f {} \;
# ------------------------------------------------------------------
# Truncate a single giant log while keeping the tail (context preserved)
# ------------------------------------------------------------------
tail -5000 <path>/listener.log > <path>/listener.log.copy
cp -f <path>/listener.log.copy <path>/listener.log
cat /dev/null > <path>/listener.log.copy
rm -f <path>/listener.log.copy
# ------------------------------------------------------------------
# Useful find variants
# ------------------------------------------------------------------
find . -type f -amin +7 -print # accessed more than 7 minutes ago
find . -type f -newer file.txt -print # newer than a reference file
find . ! -newer /tmp/timeref -exec ls -l {} \; # older than a reference timehousekeepingfindarchivelogtraceauditlistener