How to delete all the files which are more than 3 weeks old in a particular directory.Thnx in advanc


 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support How to delete all the files which are more than 3 weeks old in a particular directory.Thnx in advanc
# 1  
Old 11-14-2009
How to delete all the files which are more than 3 weeks old in a particular directory.Thnx in advanc

Quote:
Originally Posted by Neo
  1. You may post emergency work-related questions in this forum. To post in this forum you will need to use your Bits. All questions answered on a "best effort" basis.
    Smilie
  2. New members may not have enough Bits to post in the emergency forum. No problem. You can post in the other forums, but please do not demand a quick reply, as some folks do.
  3. If you are new, and do not have enough Bits, to post in this forum, you are free to contact any forum member and ask them for some of their Bits. They can give them to you, or they can sell them to you, that is strictly between you and the other forum member.
  4. In addition, be careful, because if you break the rules, you can lose your Bits and maybe your wits!
  5. Remember, our Bits virtual currency can be freely traded by all members. So, if you work for a company and need priority replies, try to acquire some. Buy them from other members! Win them (or lose them!) in the Bits Club.
  6. Please note you can reply to or edit your thread at any time. The forum admins and moderators reserve the right to close any thread.
  7. Also, note that this is a new, experimental forum. Expect the guidelines to change over time. New threads posted to this forum will (more than likely) be moved to the relevant forum after your question is answered. Again, all questions answered on a "best effort" basis.
  8. In addition, users who reply to questions in this forum receive 1000 Bits per reply, which is much higher than the standard posting credits.
This User Gave Thanks to rajsharma For This Post:
# 2  
Old 11-16-2009
It would be something like:
Code:
 find <given_directory> -type f  -mtime +21 -exec rm {} \;

# 3  
Old 11-17-2009
That also deletes all files in all subdirectories beneath given_directory.
# 4  
Old 11-17-2009
Quote:
Originally Posted by vbe
It would be something like:
Code:
 find <given_directory> -type f  -mtime +21 -exec rm {} \;

Use with maxdepth/prune option.

ex:
Code:
find <given_directory> -type f  -maxdepth 1 -mtime +21 -exec rm {} \;

# 5  
Old 11-17-2009
Thank you all..But I work in AIX, and it doesnot work

Hi friends,
First of all, thank you so much for your help. The following code seems fine
find <directory_name> -type f -maxdepth 1 -mtime +4 -exec print {} \;
But i work on UNIX AIX and it doenot recognise this "-maxdept 1" option.Then i tried
find /inbound/etl/dev/CMD/ -type f -depth 1 -mtime depth +21 -exec print {} \;
I used -depth instead, but it still gives this error
"find: 0652-009 There is a missing conjunction"
I tried
eval find /inbound/etl/dev/CMD/ -type f -depth 1 -mtime +21 -exec print {} \;
Still the error is same.Anyone out there who knows whats going on?
And one more thing i just want to remove the files from CMD directory and not from others(as it happens recursively to other directories) Thanks in advance.
Raj.

Last edited by rajsharma; 11-17-2009 at 07:12 AM..
# 6  
Old 11-17-2009
-depth does something else. You'll have to use -prune.

Code:
find /inbound/etl/dev/CMD/ \( -type d \! name . -prune \) -o \( -type f -mtime +21 -print \)

If you are sure this gives you the output you want, then pipe the command through xargs:
Code:
| xargs rm -f

# 7  
Old 11-17-2009
MySQL find is now working !!!Thanks "Otheus" and all others

Hi all,
Thanks all for ur quick help especially "Otheus" for quick reply. I used
find /inbound/etl/dev/CMD/ \( -type f -mtime +21 -print \) | rm xargs
I appreciate it a lot.Actually i had to complete my script on time.Thanks a lot for ur help.

---------- Post updated at 06:34 AM ---------- Previous update was at 06:32 AM ----------

Hi all,
Thanks all ...for ur quick help especially "Otheus" for quick reply. I used
find /inbound/etl/dev/CMD/ \( -type f -mtime +21 -print \) | rm xargs
I appreciate it a lot.Actually i had to complete my script on time.




Thanks a lot for ur help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

2. Shell Programming and Scripting

List 2 weeks older file on specific directory

Ive been a vocal of FIND command even before. Command below doesnt really give me the file that is older than two weeks.. Is there a script that will list me the log files that i want like for this date December 10, 2014, it shud list me the date between November 26, 2014 and below. When i run... (6 Replies)
Discussion started by: kenshinhimura
6 Replies

3. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurrence of a specific word

he following are the files available in my directory RSK_123_20141113_031500.txt RSK_123_20141113_081500.txt RSK_126_20141113_041500.txt RSK_126_20141113_081800.txt RSK_128_20141113_091600.txt Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
Discussion started by: kridhick
7 Replies

4. Shell Programming and Scripting

Move log files with date and delete older than 3 weeks

I have written a script which generate one logfile on every sunday and thursday I want to move the older log files into /tmp directory befor generating new one so i used mv command like mv usr/sbin/appl/logfile.txt usr/sbin/appl/tmp 2) But when i move this file to /tmp it will... (1 Reply)
Discussion started by: Nakul_sh
1 Replies

5. Shell Programming and Scripting

Delete multiple folders in a directory which are two weeks old

I need help. I have to delete multiple directories inside a directory that are two weeks old. Example: Today is July 09, 2012 Folder1 > folder1 (created June 4, 2012) -- should be deleted > folder2 (created June 2, 2012) -- should be deleted > folder3 (created... (4 Replies)
Discussion started by: jasperux
4 Replies

6. UNIX for Dummies Questions & Answers

Cannot delete files and directory

hello i am trying to delete some files and also some directories. However, despite having the required permissions (i m the owner), Permission is being denied. I also tried to delete using find and inode number, but again Permission was denied. :wall: I am new to unix so please dumb down... (8 Replies)
Discussion started by: curiosity
8 Replies

7. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

8. Shell Programming and Scripting

Delete the files older than 3 weeks in a particular directory.

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... (3 Replies)
Discussion started by: rajsharma
3 Replies

9. Shell Programming and Scripting

delete all but one files in a directory

what`s the script to do that? assuming my text file is "test.txt" (10 Replies)
Discussion started by: finalight
10 Replies

10. Shell Programming and Scripting

Delete Some Old files from Particular Directory

Hi Team, I am new to scripting. I want to create a script, which needs to keep only 5 days directories and want to remove the old directory from a particular directory. Can Somebody help me with starting this script. All my directories will be created in the name <YYYYMMDD>. Thanks... (2 Replies)
Discussion started by: siva80_cit
2 Replies
Login or Register to Ask a Question