Shell Script to delete files within a particular time frame under multiple sub folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to delete files within a particular time frame under multiple sub folders
# 1  
Old 08-22-2012
Shell Script to delete files within a particular time frame under multiple sub folders

Greetings!

I'm looking for starting information for a shell script. Here's my scenario:

I have multiple folders(100) for example:
/www/test/applications/app1/logs
/www/test/applications/app2/logs
Within these folders there are log files files that need to be deleted after a month.

I would like for the script to move from app1 to app2 and so forth, find the older file(s) and delete.


App1 and App2 are not the actual names and the real names are quite different.
# 2  
Old 08-22-2012
Assuming the directory structures are the same, i.e., 5 levels:

Code:
find /level1/level2/level3/*/logs -type f -mtime +30 -exec rm {} \;

TEST first:
Code:
find /level1/level2/level3/*/logs -type f -mtime +30 -exec ls -l {} \;

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 08-22-2012
You might want to consider the -delete primary that some find implementations offer.
# 4  
Old 08-22-2012
Jim - I tested first and that works for me. Thanks so much!!

There is so much to learn and I'm so excited that I found this place. I'm going to pour through the message boards and pick up what I can.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to compare files in 2 folders and delete the large file

Hello, my first thread here. I've been searching and fiddling around for about a week and I cannot find a solution.:confused: I have been converting all of my home videos to HEVC and sometimes the files end up smaller and sometimes they don't. I am currently comparing all the video files... (5 Replies)
Discussion started by: Josh52180
5 Replies

2. Shell Programming and Scripting

Help on script to capture info on log file for a particular time frame

Hi I have a system running uname -a Linux cmovel-db01 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux I would like to capture the contents of /var/log/syslog from 11:00AM to 11:30AM and sent to this info via email. I was thinking in set a cron entry at that... (2 Replies)
Discussion started by: fretagi
2 Replies

3. UNIX for Advanced & Expert Users

Help with creating script to delete log files/folders

Hi I am new to Linux / scripting language. I need to improve our Linux servers at work and looking to claim some space my deleting log files/ folders on a 5 day basis. Can someone help me with creating a script to do so. Any sample script will be helpful.:b: Regards (2 Replies)
Discussion started by: sachinksl
2 Replies

4. Shell Programming and Scripting

Script to delete folders and files from a prompt

Hi Everyone, I work for GE Money IVR as a DB analyst and the environment on which I work is Solaris 5.0 server and Oracle 11g. I got a project in which I have to clean up the folders and files which are not used in DB. I copied an existing script and edited it, dont know this is the... (5 Replies)
Discussion started by: habeeb506
5 Replies

5. Shell Programming and Scripting

Script to move files in multiple folders

Hello all, I would appreciate any help to write a script. I have folder A which contains over 30 thousands xml files, I would like create multiple folders and move those files (500 in each folders). Thank you (1 Reply)
Discussion started by: mmsiddig
1 Replies

6. Shell Programming and Scripting

Delete multiple folders in a directory which are two weeks old

I need help. I have to delete multiple directories inside a directory that are two weeks old. Example: Today is July 09, 2012 Folder1 > folder1 (created June 4, 2012) -- should be deleted > folder2 (created June 2, 2012) -- should be deleted > folder3 (created... (4 Replies)
Discussion started by: jasperux
4 Replies

7. Shell Programming and Scripting

Shell script to arrange files into several folders

Hello this is the script Im working on I have a picture collection that I rescued from a hard drive and there are thousands of pictures saved in one folder. What I need is to create several folders and put lets say around 200 pictures in each folder. At the end instead of having one huge... (8 Replies)
Discussion started by: kizofilax
8 Replies

8. Shell Programming and Scripting

Shell script to move files to 3 different folders

Hi guys: I've got this problem, I want to move a bunch of files to 3 different folders, without any specific order, and I'm trying to automatize it with a shell script. I'm a newbie at shell scripting so this is my first try: #!/bin/bash COUNTER=`ls -1 | wc -l` while do ARRAY=(... (11 Replies)
Discussion started by: wretchedmike
11 Replies

9. Shell Programming and Scripting

runnning a shell script in multiple folders

Hey everyone, I'm fairly new to both unix and shell scripts. Right now I have a script that I can run in one folder (if a certain text file is there, do one thing, if it's not, do something else). I want to modify this to run in multiple directories. My setup is: a company directory, and within it... (2 Replies)
Discussion started by: melearlin
2 Replies

10. Shell Programming and Scripting

moving multiple folders/files in subversion using bash script

Hi, I'm new here an dlearning a lot from this forum. i didnt find any solution for this in the forum. I have already checked in folders in subversion named HTT01,... HTT21.. and have files in each folder like below: HTT01/HTT01_00000.hex HTT01/HTT01_00000_fb_result.hex... (2 Replies)
Discussion started by: ravishan21
2 Replies
Login or Register to Ask a Question