Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

delete the files with date wise

Super Advisor

delete the files with date wise

[ Edited ]

 

i want to delete the files with date wise, please share the command

 

example

-rwxrwxrwx   1rajesh   users          261 Oct  1  2010 vgspace
-rwxr-xr-x   1rajesh   users          512 Aug 11  2011 old
-rwxrwxrwx   1rajesh   users          861 Aug 11  2011 bdf.txt

i want to delete Oct  1  2010 file. what is the command

 

P.S. This thread has been moved from HP-UX>System Administration to HP-UX > languages. -HP Forum Moderator

1 REPLY
Highlighted
Honored Contributor Honored Contributor

Re: delete the files with date wise

There is no way to specify a specific date for file deletion with 'rm'.

 

There are ways to use find to locate files withing a specific date range.  You also have to use the 'touch' command to create some empty files with dates around the date you want to find.

 

For example, if you want to find files from Oct. 1 2010, you would have to create 2 reference files.  1 file with a date of Sep. 30 2010 and one with a date of Oct. 2 2010.  The use find.

 

For example:

 

# touch -t 201009300101 /tmp/ref1
# touch -t 201010020101 /tmp/ref2

 

# ll /tmp/ref*
-rw-r--r-- 1 root sys 0 Sep 30 2010 /tmp/ref1
-rw-r--r-- 1 root sys 0 Oct 2 2010 /tmp/ref2

 

Now to find the files between those dates:

 

# find /some/dir -newer /tmp/ref1 -a ! -new /tmp/ref2

 

Here is some test output that I just did:

 

First I created some files with some Oct 2010 dates with the touch command

 

# ll
total 32
drwxr-xr-x 2 root sys 8192 Feb 26 10:02 .
drwxr-xr-x 30 root sys 8192 Feb 26 09:44 ..
-rw-r--r-- 1 root sys 0 Oct 1 2010 file1
-rw-r--r-- 1 root sys 0 Oct 1 2010 file2
-rw-r--r-- 1 root sys 0 Oct 1 2010 file3
-rw-r--r-- 1 root sys 0 Oct 3 2010 file4
-rw-r--r-- 1 root sys 0 Oct 4 2010 file5
-rw-r--r-- 1 root sys 0 Oct 5 2010 file6

 

Now to find files from Oct 1 2010:

 

# find . -newer /tmp/ref1 -a ! -newer /tmp/ref2 -exec ll +
-rw-r--r-- 1 root sys 0 Oct 1 2010 ./file1
-rw-r--r-- 1 root sys 0 Oct 1 2010 ./file2
-rw-r--r-- 1 root sys 0 Oct 1 2010 ./file3

 

If you want to delete the files once you are sure they are correct, you can modify your find command:

 

# find . -newer /tmp/ref1 -a ! -newer /tmp/ref2 -exec rm +