deleting files in sub directories!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting deleting files in sub directories!
# 1  
Old 03-09-2011
deleting files in sub directories!

Hello out there,
I want to setup a crontab feature to remove temporary pdf files from sub directories that are older than 30 days. I want to presevere the directory structer though. I got this far for a command. Will this remove the pdf's in subdirectories or just directly under the pdf folder? If not how can I alter the command to include files in the subdirectory?

0 0 * * * /prod/app/$LOGNAME/data/audit/pdf -type f -name '*.pdf' -mtime +30 -exec rm {} \;
thanks!!!!
# 2  
Old 03-09-2011
I don't know the command you are executing but what I would do is to replace rm {} by echo {}
and execute it on the command line to check files in the subfolders are also printed.

The following command should remove all the pdf files older than 30 days even if they are stored in subfolders

find . -name "*.pdf" -mtime +30 | xargs -I {} rm -f {} \;
# 3  
Old 03-09-2011
Quote:
Originally Posted by fhernu
find . -name "*.pdf" -mtime +30 | xargs -I {} rm -f {} \;
In that particular case, piping to xargs is pointless. You gain nothing. Simply use find's -exec primary as in the original post.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 4  
Old 03-10-2011
thanks for responeses.

So playing around with this from a command line I couldnt get my year old pdf files to be removed unless I took out the "-mtime +30" completely.
Why is that? Does the -mtime not work properly froma command line prompt?
# 5  
Old 03-10-2011
Code:
0 0 * * * /prod/app/$LOGNAME/data/audit/pdf -type f -name '*.pdf' -mtime +30 -exec rm {} \;

Stupid question. Where is the word "find" in this crontab entry?
Also, where is $LOGNAME going to come from?

For your command line problem, please post a directory listing (ls -la) of the files which you could not remove and the exact command you typed.
# 6  
Old 03-10-2011
This is the line I have now working
find /prod/app/$LOGNAME/data/audit/pdf -type f -name '*.pdf' -exec rm {} \;
$logname is just a user login name. I hardcoded an actual file folder there too and that was working eitherway.

Basically I am ftping an pdf file thats 90 days old onto server. Then testing it at a command line. If I put -mtime +30 in there it doesnt work. If I take it out or put -mtime -30 the pdf file gets deleted. What am I doing wrong?
I just want any pdf files older than the 30 days to be deleted and the rest to remain.
# 7  
Old 03-10-2011
The file timestamps on the "ls -la" listing that you didn't post are the same timestamps as the "-mtime" to "find".
I guess that when you used ftp to copy the files it was less than 30 days ago.
Quote:
Basically I am ftping an pdf file thats 90 days old onto server.
This sentence is ambiguous. Not at all clear which server is which.

Your main issue appears to be that you are copying files and not preserving the timestamp (or not looking at the timestamp of the original file).


There is rarely a reason to use "ftp" except between unix and disparate servers (e.g. an IBM Mainframe or a Windows server). Do you have the option to use proper unix commands to transfer files between servers?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for deleting files and directories when the file system reaches the threshold

Hi Can someone assist in writing a script. I have a filesystem named /sybase in my aix lpar. When this filesystem becomes 94% full all the files and directories under /sybase/logs should be deleted immediately. :confused: (7 Replies)
Discussion started by: newtoaixos
7 Replies

2. Shell Programming and Scripting

Deleting all files recursively from directories while ignoring one file type

Hi, Seems like I need help again with a problem: I want to delete all files from my lets say "Music" Directory inkluding all of the subfolders except for .mp3 and .MP3 files. I tried it with globalignoring mp3 files, finding and deleting all other files, which resulted in all files... (3 Replies)
Discussion started by: pasc
3 Replies

3. Shell Programming and Scripting

Deleting directories

I want to delete directories which are empty and directories which are 2 level deep. example: /app/data/logs/G07696115/G07696115 So if a same directory is there inside G07696115 with the same name G07696115, i want to find and delete that alone(Make sure you do not touch directory any... (4 Replies)
Discussion started by: gtm004
4 Replies

4. Shell Programming and Scripting

Deleting all empty files in sub directories with a command

Hello Friends, Im trying to delete empty files in subdirectories with a command. I can find them checking only one directory in each step and then show them with my command like below moreover i could not add removing part: ls -l */* | awk '{if ($5==0) printf "%3s %2d %s... (5 Replies)
Discussion started by: EAGL€
5 Replies

5. UNIX for Dummies Questions & Answers

deleting older directories

how can we delete directories older than 6 months (9 Replies)
Discussion started by: dnat
9 Replies

6. UNIX for Dummies Questions & Answers

deleting all the sub directories

hello., i am creating a certain sub directories as apart of my requirement, and then later on i have to delete all those sub directories.. ____________________________________________________ DIR1="/home/pavi/cvs/20071426/TEMP" echo " DIR1 is : " $DESTDIR1 echo... (2 Replies)
Discussion started by: pavan_test
2 Replies

7. UNIX for Dummies Questions & Answers

What/How to check before deleting files and directories

Hi there, I have a some directories containing web files that are old, and I need to remove them. I know that there might be sym links and hyperlinks pointing to these old directories. If that's the case, then I'll have to fix the links before deleting these old directories to avoid broken... (4 Replies)
Discussion started by: yvochan
4 Replies

8. UNIX for Dummies Questions & Answers

Recursively deleting directories

Say I have a directory call test, and several directories nested in it, and several directories nested in them. And I want to remove all directories within "test" and its subdirectories that have the name "cvs", how can I do this? I tried rm -r cvs, but that only removed the top level direcotry... (4 Replies)
Discussion started by: mikeshank
4 Replies

9. UNIX for Dummies Questions & Answers

deleting nfs directories...

Hi I have Solaris 8 in several Ultras and they share some directories between each others using nfs. (you know, one shares the other mounts the remote directory into a local...). The problem is that one guy (me) deleted a shared directory and now the computer that was mounting it remotely is... (3 Replies)
Discussion started by: piltrafa
3 Replies

10. UNIX for Dummies Questions & Answers

deleting log files only in particular directories

Hi My problem is i have to remove some log files in specific named directories on a regular basis using shell scripts. What i want my shell script to do is i give the shell script some listing of directories from which to delete all log files recursively. Can anyone please help me. ... (2 Replies)
Discussion started by: sameervs
2 Replies
Login or Register to Ask a Question