![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Delete files older than 30 days | William1482 | SUN Solaris | 2 | 05-08-2009 02:35 PM |
| how to delete the files which are the 30 min older...? | psiva_arul | Shell Programming and Scripting | 2 | 06-13-2008 04:36 PM |
| delete files older than 5 minutes in directory (recursively) | scarfake | Shell Programming and Scripting | 3 | 06-13-2008 01:10 AM |
| Reg: delete older files from ftp | sam99 | UNIX for Dummies Questions & Answers | 3 | 01-09-2008 10:56 AM |
| how to check whether the given file is 5 weeks older than current date | risshanth | Shell Programming and Scripting | 1 | 10-29-2007 04:53 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi, Friends,
I am writing a script to delete all the files which are there for more than 3 weeks. I have tried this : find /home/appl/backup -type f -mtime +21 -exec rm -f {} \; But i am not sure if it deletes only the files in specified directory or all the directorinies in the provieded to it. I tried subtracting the present week and week in which files were last modified.And thus delete all of the remaining.When i do ls -lt to get modification date, i cudnot get the week number from the old files' modification date. Please suggest a way out ASAP.And any help in this regard will be appreciated in advance... |
|
||||
|
Try testing your code. Setup some test directories and files. you can use the touch command to create files and change the date on the file. Create some files and directories that would fall within your delete window and some that don't. you can even create a script to generate these test files to make it easily repeatable.
Code:
mkdir tst ls -lrt drwxr-xr-x 2 user usrgrp 4096 Nov 14 18:02 tst touch -t 200910121314 tst ls -lrt drwxr-xr-x 2 user usrgrp 4096 Oct 12 13:14 tst touch -t 200910121314 tfile.tst ls -lrt drwxr-xr-x 2 user usrgrp 4096 Oct 12 13:14 tst -rw-r--r-- 1 user usrgrp 0 Oct 12 13:14 tfile.tst Good luck. |
|
||||
|
1. You can first execute the find command without -exec part, to view the list as,
Code:
find /home/appl/backup -type f -mtime +21 Code:
find /home/appl/backup -type f -mtime +21 -ok rm -f {} \;
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| delete files older than 3 weeks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|