The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Multiple Files deletion in perl pulkit Shell Programming and Scripting 1 02-12-2008 05:55 AM
Finding Hidden files and protecting the folder containing hidden files from deletion pochaw Shell Programming and Scripting 4 12-22-2007 01:33 AM
conditional deletion of log files sonali007 UNIX for Dummies Questions & Answers 3 10-03-2007 11:56 AM
Script for automatic deletion of old files vivek_scv Shell Programming and Scripting 4 09-09-2007 01:57 AM
Deletion of log files. Geeta UNIX for Dummies Questions & Answers 1 06-23-2006 07:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-23-2005
Chidvilas Chidvilas is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 1
Regarding deletion of old files

Hi,

I have a list of directories which contain old files that are to be deleted.

I put the list of all directories in a txt file and it is being read by a script

Iam searching for the files older than 60 days using mtime and then deleting it

But all the files are getting deleted irrespective of mdate.iam providing the

script code here

#! /bin/sh

#setting the date

DATE='date + "%y%m%d"'

cat param.txt|

while read DIR TIME

do

#Check if the directory is present

if [ -d "${DIR}" ]

then

echo "$DIR is a directory on this machine"

echo "Time Limit:$TIME"

echo "looking for files older than $TIME days to be deleted from $DIR"

find $DIR -type f -mtime $TIME |xargs rm -f

echo "older files are now deleted successfully"

else

echo "$DIR is not a directory.please check again"

fi

done

Is there any thing wrong with the find command

my datafile is like this
/var/home/.... +60
/home/chidvilas/.. +60

But the script is removing all files irrespective of mtime??

CAn anyone suggest on this??
  #2 (permalink)  
Old 12-23-2005
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
It works fine for me - ran on Fedora.

Code:
FIRST RUN - ONLY LOOKING FOR THE FILES (CHANGED | xargs rm -f to just -ls)
[tghunter@localhost ~]$ ./oldfiles
. is a directory on this machine
Time Limit:+1900
looking for files older than +1900 days to be deleted from .
387600    8 -rw-r--r--   1 tghunter tghunter     2048 Sep 19  2000 ./.openoffice.org2.0/user/gallery/sg100.sdv
older files are now deleted successfully

[tghunter@localhost ~]$ cp ./.openoffice.org2.0/user/gallery/sg100.sdv ./.openoffice.org2.0/user/gallery/sg100.sdvhog
[tghunter@localhost ~]$ ./oldfiles
. is a directory on this machine
Time Limit:+1900
looking for files older than +1900 days to be deleted from .
387600    8 -rw-r--r--   1 tghunter tghunter     2048 Sep 19  2000 ./.openoffice.org2.0/user/gallery/sg100.sdv
older files are now deleted successfully
CHANGED TO REMOVE FILES
[tghunter@localhost ~]$ vi oldfiles
[tghunter@localhost ~]$ ./oldfiles
. is a directory on this machine
Time Limit:+1900
looking for files older than +1900 days to be deleted from .
older files are now deleted successfully
[tghunter@localhost ~]$ ls ./.openoffice.org2.0/user/gallery/sg100.sdv
ls: ./.openoffice.org2.0/user/gallery/sg100.sdv: No such file or directory
[tghunter@localhost ~]$ ls ./.openoffice.org2.0/user/gallery/sg100.sdvhog
./.openoffice.org2.0/user/gallery/sg100.sdvhog
[tghunter@localhost ~]$ mv ./.openoffice.org2.0/user/gallery/sg100.sdvhog ./.openoffice.org2.0/user/gallery/sg100.sdv
[tghunter@localhost ~]$ cat param.txt
.    +1900
Check that your param.txt file is set up correctly and check your script by listing the files versus removing them to insure it will only get the files you really want to remove. (find $DIR -type f -mtime $TIME -ls )
  #3 (permalink)  
Old 12-27-2005
sudhanshu_sinha sudhanshu_sinha is offline
Registered User
  
 

Join Date: May 2005
Posts: 12
I think you can use the find . -ctime -60 > $file to get the name of all the files 60 days older and then you can delete all the files in that $file.
  #4 (permalink)  
Old 12-27-2005
ml0fl1n ml0fl1n is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 4
Or do it all in one go

find <the path you want to check> -ctime -60 -exec rm {} \;

You would want to be very, very sure of where you run this, as most operating system files would be older than 60 days.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0