Thursday, January 6, 2011

Unix command to list/delete files older than n days

During software development, we often end up in searching large number of log files. Sometimes there will be hundreds of log files.

The unix command to list/remove files that are older than n days is given below.

Command To  List :
find ./ –mtime +5 –exec ls –l '{}' \;

Command To  Delete :
find ./ –mtime +5 –exec rm –f '{}' \;


Section of command Explanation
find unix find command
./ current directory (can specify any directory)
-exec to execute other commands within find
-mtime +5 To find the files that are not modified atleast 5 days ago.
ls –l or rm -f To list or remove
‘{}’ for each iteration this will be replaced by the next filename
\; indicated the end of inner ls or rm command



Hope this help…
Cool…

1 comment:

  1. CPU
    AMD Phenom II X2 560 31 °C
    Callisto 45nm Technology
    RAM
    2.00 GB Single-Channel DDR3 @ 2762MHz (9-9-9-24)
    Motherboard
    Gigabyte Technology Co., Ltd. GA-78LMT-S2 (Socket M2) 42 °C
    Graphics
    DELL E1912H (1366x768@60Hz)
    AMD 760G (Gigabyte)
    Hard Drives
    466GB Seagate ST500DM002-1BD142 ATA Device (SATA) 40 °C
    Optical Drives
    HL-DT-ST DVDRAM GH24NS72 ATA Device
    Audio
    High Definition Audio Device

    is intex blaze cabinet is suitable please help me sir

    ReplyDelete