Search code examples
linuxfindlsrm

how to delete file inside directory in linux which is created 3 hours ago


how to delete file inside directory in linux which is created within certain time intreval .

actually i am unable to find file inside file for certain time interval ::

Example::

[root@XXXXXXXX]# ls -lhrt 
total 0
-rw-r--r-- 1 root root 0 Jul 31 13:13 1
-rw-r--r-- 1 root root 0 Jul 31 13:13 2
-rw-r--r-- 1 root root 0 Jul 31 13:13 3
-rw-r--r-- 1 root root 0 Jul 31 13:13 4
-rw-r--r-- 1 root root 0 Jul 31 13:13 5
-rw-r--r-- 1 root root 0 Jul 31 14:27 6

actually i need to delete file which was created within Jul 31 12:00 to Jul 31 14:00 .

Please suggest on same .

Thanks in advance


Solution

  • The easiest way is to create boundary for find to work.

    touch -t 201507311200 start
    touch -t 201507311400 stop
    find . -newer start \! -newer stop -delete