The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
listing folders and using in script truCido Shell Programming and Scripting 1 05-31-2007 04:11 AM
script to loop around folders grinder182533 Shell Programming and Scripting 2 11-14-2006 04:46 AM
Php script that copies Unix folders? edtech Shell Programming and Scripting 4 09-26-2006 03:58 PM
Script to Find Diff from two folders gkrishnag UNIX for Advanced & Expert Users 2 07-31-2006 10:14 PM
script to archive certain folders in a hierarchy medazinol Shell Programming and Scripting 3 04-28-2005 07:45 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-29-2005
Registered User
 

Join Date: Apr 2005
Posts: 5
Stumble this Post!
Script To dlete PDF file s and Folders

Hi

We have to delete PDF files and Folders older than five days .Can anyone help with the shell script

Regards
Ved
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-29-2005
Registered User
 

Join Date: Apr 2005
Location: McKinney, TX
Posts: 11
Stumble this Post!
Quote:
Originally Posted by ved123
Hi

We have to delete PDF files and Folders older than five days .Can anyone help with the shell script

Regards
Ved
check this:

Code:
find <directory> -name "*.[pPdDfF]" -ctime +5 -exec rm {} \;
where <directory> is the directory structure that the pdf's are in. the funkiness in " " just checks for any combination of upper-case and lower-case p d f. the only part i'm not 100% on is the -ctime, whether it should be -mtime or not
Reply With Quote
  #3 (permalink)  
Old 04-29-2005
Registered User
 

Join Date: Aug 2001
Posts: 179
Stumble this Post!
"*.[pPdDfF]" should be "*.[pP][dD][fF]"
I have not tried the script myself
Reply With Quote
  #4 (permalink)  
Old 04-29-2005
Registered User
 

Join Date: Apr 2005
Posts: 5
Stumble this Post!
Quote:
Originally Posted by sssow
"*.[pPdDfF]" should be "*.[pP][dD][fF]"
I have not tried the script myself
Hi

But i am new to shell scripting.How do you give the path here.I mean can you please help me with complete script.

Regards
Reply With Quote
  #5 (permalink)  
Old 05-02-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
Stumble this Post!
Quote:
Originally Posted by ved123
Hi

But i am new to shell scripting.How do you give the path here.I mean can you please help me with complete script.

Regards
you already have the complete script ... just put in the correct directory name where <directory> is ... here's chuckuykendalls's code with sssow's modification ...
Code:
find <directory> -name "*.[pP][dD][fF]" -ctime +5 -exec rm {} \;
Reply With Quote
  #6 (permalink)  
Old 05-02-2005
Registered User
 

Join Date: Apr 2005
Posts: 5
Stumble this Post!
Hi guys

even though i am new i tried to put like this

Is this correct

#!/bin/sh
echo "Removing tmp directories and PDF files older than 5 days created by users"
#!/bin/sh
cd /opt/dctm/....Path
echo 'Current Direcotory is' $PWD

"find ./ -name '*.pdf' -mtime +5 >>test.out"

find ./ -type d -mtime +5 -exec rm -R {} \;

find ./ -name '*.pdf' -exec rm '{}' ';'

"find ./ -name '*.pdf' -mtime +5 >>test1.out"

diff test.out,test1.out >> test2.out

mailx -s" Deleted Files For $TODAY at $TIME" xyz.com <test2.out

I am trying to delete folders and pdf files in temp and trying to write before and after and comparing to get deleted files and mailing them.
Reply With Quote
  #7 (permalink)  
Old 05-02-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
Stumble this Post!
Code:
find ./ -name '*.pdf' -exec rm {} \;

"find ./ -name '*.pdf' -mtime +5 >>test1.out"
your code as written will not do what you want as it removes ALL the ".pdf" files before listing those ".pdf" files that are older than 5 days --- your listing will always come out clean since you don't have any ".pdf" files to list ...

btw, i suggest you keep to the same programming style throughout your script --- makes it easier to debug that way ... and don't put your command line in double quotes as the shell will most likely not run it ...
Code:
find ./ -type d -mtime +5 -exec rm -R {} \;

find ./ -name '*.pdf' -exec rm '{}' ';'

find ./ -name '*.pdf' -mtime +5 >>test1.out
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0