recursively going through folders and subdirectorys and running delete from crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting recursively going through folders and subdirectorys and running delete from crontab
# 1  
Old 08-24-2012
recursively going through folders and subdirectorys and running delete from crontab

Hio, So I have a crontab delete of older files setup. This script works fine if I run them by each individual directory.
Problem is there are so many thousands of files and hundreds of directories and sub directories that I need to recursively have it go through and delete files by directory instead of doing the "\*\*\" method. Right now I get errors when this runs unless I go through each folder and run the command by folder.
How can I modify the below to go through all folders under the "audit" folder and run the same delete command? I saw the ls -1R command but wasnt %100 sure how to implement it.
Code:
 * * * * * find /prod/app/$LOGNAME/data/audit/*/*/*.pdf -type f -name '*.pdf' -mtime +120 -exec rm {} \;


Last edited by methyl; 08-24-2012 at 05:47 PM.. Reason: please use code tags
# 2  
Old 08-24-2012
I'm not sure if I completely understand your problem, but you might want to try using xargs:

Code:
find /prod/app/$LOGNAME/data/audit/ -name "*.pdf" -type f -mtime +120 | xargs -n1 rm

# 3  
Old 08-24-2012
If you "get errors", please post sample error messages.

I'm concerned that you appear to be running this cron once every minute when it is the sort of cron you might run once a day or once a week. I suspect that you will have multiple copies of the cron running concurrently which will be anarchy!

The reply by Subbeh is much better use of find syntax because find not Shell expands the wildcards.

Please remember to post what Operating System and version you have and what Shell you are using. There is much variation in the find command and your original syntax would be invalid on many versions of unix and could generate a command which is too long on others.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How best to remove certain characters from filenames and folders recursively

hello, I'm trying to figure out which tool is best for recursively renaming and files or folders using the characters \/*?”<>| in their name. I've tried many examples that use Bash, Python and Perl, but I'm not much of a programmer I seem to have hit a roadblock. Does anyone have any... (15 Replies)
Discussion started by: prometheon123
15 Replies

2. Shell Programming and Scripting

ftp script to copy folders recursively

hi all I want a script that will use ftp to copy folder and sub folders from source server to current server. if i use -r switch then it just copies folders for 5 level. (1 Reply)
Discussion started by: kashif.live
1 Replies

3. UNIX for Advanced & Expert Users

Delete empty directories recursively - HP-UX

Hi, I want to delete all empty directories in a long directore tree structure. I want to use that from a script that will run on HP-UX 11. My definition of empty directory is that there is no regular file under it and directly beneath it. To elaborate, I have below directories. /app/dev/java... (14 Replies)
Discussion started by: asutoshch
14 Replies

4. UNIX for Advanced & Expert Users

Recursively delete only specified directories with given pattern

Hi All, We have a requirement to recursively delete the directories and its subdirectories older than 60 days based on timestamp (folder creation timestamp)under certain directory. However it has some specific requirements. The directories will continue to be there upto any depth. the... (0 Replies)
Discussion started by: rcvasu
0 Replies

5. Shell Programming and Scripting

RSYNC script to transfer folders recursively without overwriting via FTP

Hi all, I would need a bash script to sync/transfer folders recursively via FTP/RSYNC (I initially planned to use FTP but I heard RSYNC would fit a lot better for this job(?)) The situation: 3 different Linux servers 1. source 2. destination - Samba 3. Server where the script runs on ... (2 Replies)
Discussion started by: thibautp
2 Replies

6. UNIX for Dummies Questions & Answers

delete recursively contents of folders

hi, I've a folder structure like : /home/project/LIBNAMEA/FILE1 /home/project/LIBNAMED/FILE2 /home/project/LIBNAMEC/FILE3 /home/project/LIBNAMED/FILE4 /home/project/LIBNAMEX/FILE5 (there is no relation in the letters after the project/ ) and i need to delete the files keeping... (5 Replies)
Discussion started by: jtmartins
5 Replies

7. UNIX for Dummies Questions & Answers

Delete files Recursively *thumbs*.jpg

Greetings, I need to delete all files that contain the word thumbs. Those files are spread all throughout sub-directories in a file directory tree. Is there a script or single line command that will find all files with the word thumbs, and simply delete the file? For example: Delete... (4 Replies)
Discussion started by: ..Chris..
4 Replies

8. Shell Programming and Scripting

Delete all injected code recursively

Recently all of the php files on my server got injected with some dating site code and I'm trying to get rid of it all at once. I've tried using sed but I don't know how to escape it correctly because I don't really know what I'm doing. Could you guys help me with the syntax? find ./* -type f... (2 Replies)
Discussion started by: ISOcrates
2 Replies

9. Shell Programming and Scripting

recursively delete the text between 2 strings from a file

i have 200000bytes size of a unix file i need to delete some text between two strings recursively using a loop with sed or awk . these two strings are : 1st string getting from a file :::2 nd string is fi...its constant . can anyone help me sed -n'/<1 st string >/,/fi/' <input_filename> is the... (2 Replies)
Discussion started by: santosh1234
2 Replies

10. Shell Programming and Scripting

delete files recursively in the specified directory

I have to write a shell script which can delete all the files and directories recursively inside the specified directory but should not delete the specified directory. Please some body help me in writing the script. (3 Replies)
Discussion started by: deepthi.s
3 Replies
Login or Register to Ask a Question