help with removing files which are n days old


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with removing files which are n days old
# 1  
Old 11-13-2008
help with removing files which are n days old

Hi ,

I need to remove files from a specific directory which are 7 days old
using folowing find comand as:
find /home/dir1/log -name "run*.log" -mtime +6 -prune -exec rm -f {} \;
but my script should traverse to /home/dir1/log
and them delete the specified files in the directory.
i.e instead of rm home/dir1/log/run*.log. it should do rm run*.log

please help me

Thanks and Regards
# 2  
Old 11-13-2008
If i undertodd you right you want to find a file in dirA and delete the coresponding file in dirB.

find dirA -type file -name .. -mtime ...... | while read i ; do
file=$(echo $i | awk -F"/" '{print $NF}')
rm dirB/$file
done
# 3  
Old 11-13-2008
Code:
#Always test this sort of script with echo statements before deleting anything.
DIR="/home/dir1/log"
if [ -d "${DIR}" ]
then
     cd "${DIR}"
     find . -name run\*\.log -type f -mtime +6 -print|while read FILENAME
     do
          echo "File which would be deleted: ${FILENAME}"
          # rm -f "${FILENAME}"
     done
else
     echo "Directory missing: ${DIR}"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need files exactly 3 to 7 days old

Hi, I need files exactly 3 to 7 days old. Today is 28th July 2016. I have two files one dated 25th July and other 21st July which are 3 to 7 days old. 94702 1 -rw-r--r-- 1 m1083 user1 26 Jul 25 13:00 ./Report_0751.txt 94751 1 -rw-r--r-- 1 m1083 user1 128 Jul... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

How can i list files above 5 days old?

HI how can i list files above 5 days old i want to keep only last 5 days application logs Regards, Ben (3 Replies)
Discussion started by: bentech4u
3 Replies

3. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

4. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

5. UNIX for Dummies Questions & Answers

Removing certain files after certain days..

Hi guys.. Currently me using AIX 5.3.0.0 I have these files generated by Oracle in /tmp folder.. # date Mon Sep 26 11:53:31 BEIST 2011 # pwd /tmp # df -g . Filesystem GB blocks Free %Used Iused %Iused Mounted on /dev/hd3 10.00 3.65 64% 62479 7% /tmp... (2 Replies)
Discussion started by: mushr00m
2 Replies

6. UNIX for Advanced & Expert Users

removing files older than n days

Hi, on AIX 6.1, is there any commande line to remove the files older than n days in a directory ? Thanks. (2 Replies)
Discussion started by: big123456
2 Replies

7. UNIX for Dummies Questions & Answers

Removing files older than 7 days

Script help, I need to delete files that are older than 7 days. I do that automatically but I know that a cron job can do the job for me. Any help is greatly appreciated, as you can see, I am a DOS or WINDOWS guy. Little on UNIX. Thanks (3 Replies)
Discussion started by: texasoeb
3 Replies

8. Shell Programming and Scripting

ls latest 4 days or specify days of files in the directory

Hi, I would like to list latest 2 days, 3 days or 4 days,etc of files in the directory... how? is it using ls? (3 Replies)
Discussion started by: happyv
3 Replies

9. Shell Programming and Scripting

Removing files automatically from a directory after 30 days.

Hello; I have a directory that is collecting log and act files. I need to write a script that will remove these files once they are 30 days old. I have read through a number of threads on this site that have given me a great deal of information. However I have what seems to be a unique... (7 Replies)
Discussion started by: justinb_155
7 Replies

10. Shell Programming and Scripting

removing files that are 60 days old

Hello guys I'm writing a script and I need some help. I'm almost done but I think I have a problem with my ffind command. I need the scripts to delete files are 60 days old and then append the filenames to a text file on the days they were deleted. If someone can help me I would be thankful. (5 Replies)
Discussion started by: aojmoj
5 Replies
Login or Register to Ask a Question