Need to remove files older than 30 days except directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to remove files older than 30 days except directories
# 1  
Old 11-13-2006
Need to remove files older than 30 days except directories

Hi,

I need to remove files (*.trc) which are older than 30 days from one location.

My problem is there I do not want to visit any of the directories at that location. I want to search files at that particular location only (need to skip directorys at that location). maxdepth option is there in LINUX find but its not there in solaris.

How can I do that?

Thanks in advance.

Regards,
Malay Maru
# 2  
Old 11-13-2006
Hi,

Try the following:

Code:
find . -name "*.trc"  -mtime +30 -exec rm -rf {} \;

Regards,
Nir
# 3  
Old 11-13-2006
But it will remove the tracefiles which resides under directoris at that location.

I want to skip this directories.

Malay
# 4  
Old 11-13-2006
Code:
find . \( -type d ! -name . -prune \) -o  -mtime +30 -exec rm -rf {} \;


Jean-Pierre.
# 5  
Old 11-13-2006
Find For Mins

Hello ,


In addition to the problem , if i want to find and remove the files made in last 5 mins then what will be the command as , i have searched for many coomand but all depend upon days not time!!!

KRegards,
Aparna
# 6  
Old 11-13-2006
A solution is to use the -newer expression of the find command.
  1. Compute current date/time minus 5 mn
    The Perderabo's datecalc and Simple date and time calculation in BASH may help you.
  2. Create a timestamp file with access and modification times equal to the computed date/time :
    touch -t [[CC]YY]MMDDhhmm[.SS] timestamp_file
  3. Find files newer that the timestamp file.
    find . -type f -newer timestamp_file -exec rm -f {} \;


Jean-Pierre.
# 7  
Old 11-13-2006
Thanks

Thanks a lot for the solution

KRegards,
Aparna
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shellscript command to remove files starting with a certain string, and older than 3 days

Hi All, Need help in identifying a shellscript command to remove all files on a server directory, starting with a certain prefix and also older than 3 days. That means files created with that prefix, today or yesterday, shouldn't be removed. Thanks, Dev (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

2. Shell Programming and Scripting

Need Help in ksh Script to list files older than 365 days from specified directories

Requirement is to list the files older than 365 days from multiple directories and delete them and log the list of files which are deleted to a log file. so 1 script should only list files older than 365 days for each directory separately to a folder The other script should read these files... (7 Replies)
Discussion started by: prasadn
7 Replies

3. UNIX for Dummies Questions & Answers

How to compress the directories which is older than 7 days?

Hi all, how to compress the directories which is older 7 days. If any one knows please help me this is urgent. Thanks in advance (3 Replies)
Discussion started by: rameshpagadala
3 Replies

4. Shell Programming and Scripting

Remove files older than 2 days.

Hi All, I am new to the scripting and using solaris 10 OS. Please suggest me from the below script which modifications need to be done to delete the files more that 2days older. Current script is deleting existing file. # Remove old explorer runs if needed DIR=`dirname ${EXP_TARGET}` if ... (2 Replies)
Discussion started by: Navkreddy
2 Replies

5. UNIX for Advanced & Expert Users

How to Remove 180 days older non-empty directories

Hi Gurus, I have command to delete more than 180days file. find /home/abc/ -name "CBST_*.txt*" -mtime +180 | xargs -n 100 rm -f Now I would like to delete more than 180days Non empty directory--What will be command? Following is non empty directory as instance CBST2010* (2 Replies)
Discussion started by: thepurple
2 Replies

6. Shell Programming and Scripting

script to remove files older than 60 days

Hi I need help in the script which looks at a contorl file which has a list of file names like xxxx.12345 and I want to take only xxxxx and search in a specific directory and remove the file if its older than 60 days I have written something like this.. but seems to be wrong... (1 Reply)
Discussion started by: antointoronto
1 Replies

7. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

8. Shell Programming and Scripting

How to tar, compress and remove files older than two days

Hi, I'm Eddy from Belgium and I've the following problem. I try to write a ksh script in AIX to tar, compress and remove the original *.wav files from the directory belgacom_sf_messages older than two days with the following commands. The problem is that I do not find a good combination... (4 Replies)
Discussion started by: edr
4 Replies

9. Red Hat

Find files older than 30 days in directories and delete them

Hi, I have dummies questions: My script here can find the files in any directories older than 30 days then it will delete the files but not the directories. I would like to also be able to delete the directories that hold old files more than 30 days not just the files itself. find . -type f... (2 Replies)
Discussion started by: lamoul
2 Replies

10. UNIX for Dummies Questions & Answers

Find files older than 5 days and remove tem after listing

need help with this ... Find files older than 5 days and remove tem after listing list "test" file older than 5 days and then remove them (1 Reply)
Discussion started by: ypatel6871
1 Replies
Login or Register to Ask a Question