|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
delete file older than N days
Hi, All,
I'd like to delete files older than 1 day. I thought the following command find /your_directory -mtime +1-exec rm -f {} \; will do the work, but not so, it seems like it won't delete files unless it is 2 days old or older. the files between 1 day and 2 days old does not get deleted, so does +1 actually means 2 days? if not so, why it won't delete files between 1 and 2 days old? can someone please help me? |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
delete files older than 1 day
Hi, All,
I'd like to delete files older than 1 day. I thought the following command : find /your_directory -mtime +1-exec rm -f {} \; will do the work, but not so, it seems like it won't delete files unless it is 2 days old or older. the files between 1 day and 2 days old won't get deleted, so does +1 actually means 2 days? if not so, why it won't delete files between 1 and 2 days old? can someone please help me? |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
That command will delete anything that is older than 24 hours from when the command was run.
|
|
#4
|
||||
|
||||
|
Erika,
As you said: Quote:
1) +n --> More than 'n' days ago. 2) -n --> Less than 'n' days ago. 3) n ---> Exactly 'n' days ago. Thus, if you specify '+1', it means more than 1 day ago. |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Actually, date ranges in the find command do not work quite how you expect them to. Demonstration at the ksh prompt... Code:
$ for i in 09 10 11 12;do touch -t 200707${i}0000 July_${i};done
$ ls -o
total 0
-rw-r--r-- 1 Ygor 0 Jul 9 00:00 July_09
-rw-r--r-- 1 Ygor 0 Jul 10 00:00 July_10
-rw-r--r-- 1 Ygor 0 Jul 11 00:00 July_11
-rw-r--r-- 1 Ygor 0 Jul 12 00:00 July_12
$ for j in 1 -1 +0 +1;do echo "[[ ${j} ]]";find . -type f -mtime ${j} -print;done
[[ 1 ]]
./July_11
[[ -1 ]]
./July_12
[[ +0 ]]
./July_09
./July_10
./July_11
[[ +1 ]]
./July_09
./July_10The reason is that "+1" means 2 or more days old, i.e. more than 48 hours old. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
if you need to be really precise I usually do summink like: Code:
touch -t YYYYMMDDhhmmss 111 find . -older 111 | xargs rm |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
How to find the Cron entrys path in UNIX server?
Actually, i wanted know about the cron entry path in my UNIX server?
if i issued the crontab -l it will listout the all cront entries in the current server, But i wanted to know about the PATH where all the cron entries is stored? Please, any one help me. Thanks, Siva.P |
| Sponsored Links | ||
|
![]() |
| Tags |
| mtime |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do i delete files older than 15 days in AIX? | bluesteel | AIX | 4 | 03-31-2010 11:23 AM |
| delete files more than 15 days older | ali560045 | Shell Programming and Scripting | 3 | 11-28-2008 04:43 AM |
| Delete user file(s) older then 'X' days ?? | varungupta | UNIX for Advanced & Expert Users | 2 | 08-24-2007 05:01 AM |
| How can I delete files older than 7 days? | odogbolu98 | UNIX for Dummies Questions & Answers | 3 | 02-26-2002 07:35 PM |
|
|