Delete multiple folders in a directory which are two weeks old


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete multiple folders in a directory which are two weeks old
# 1  
Old 07-09-2012
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 July 1, 2012) -- should be retained as of July 9, 2012 but will be deleted after two weeks
> folder4 (created July 3, 2012) -- -- should be retained retained as of July 9, 2012 but will be deleted after two weeks

Thanks for the help.

---------- Post updated at 03:55 AM ---------- Previous update was at 03:46 AM ----------

I think, the following script is closely related to the problem:

( for d in */*/ do ksh -c "rm ${d}*" & done wait )

Thanks to DGPickett for the above script, however, I need to identify the age of the file
which should be 2 weeks old.

Thanks
# 2  
Old 07-09-2012
Search for FIND command in man pages. It will be really helpful Smilie
# 3  
Old 07-09-2012
Please post what Operating System and version you have and what Shell you use.

Is the "last modified" times stamp which you see in ls -la usable to identify which directories to delete?
Are there any subdirectories below the directories concerned? Especially any subdirectories which should not be deleted?
Do the directories have a naming convention which makes them easy to identify by name? (Using * in deletion scripts can be dangerous).
Does the creation date appear in the directory name?
# 4  
Old 07-09-2012
Quote:
Originally Posted by methyl
Please post what Operating System and version you have and what Shell you use.

OS version is Red Hat 4.5-6, Bash

Is the "last modified" times stamp which you see in ls -la usable to identify which directories to delete? Yes, actually, the files to be deleted is only created once and will not be modified.


Are there any subdirectories below the directories concerned? Especially any subdirectories which should not be deleted?There are only two directories, the main directory have subdirectories which contains the files.

The main directory remains and the subdirectories including all files will be deleted.

Do the directories have a naming convention which makes them easy to identify by name? (Using * in deletion scripts can be dangerous).

The main directory doesn't have any naming convention, only pattern (e.g. ####_####_#### or 192_168_252_101).

The subdirectories, however are based on date when the file is created, like 20120709 for 2012 July 09.

Does the creation date appear in the directory name?

Yes, it appears, but for the subdirectories which are for deletion.

Thanks for the help.
# 5  
Old 07-09-2012
Does this command find the directories you want to delete?
Code:
find /parent_tree/* -type d -name '????????' -mtime +24 -exec ls -lad {} \;

This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute multiple files in multiple folders and also output on same folder

How to execute multiple files in multiple folders and also output to be generated in the same folder? Hello Team, I have a path like Sanity_test/*/* and it has around 100+ folders inside with files. I would like to run/execute those files and output of execution to be placed on same /... (1 Reply)
Discussion started by: pushpabuzz
1 Replies

2. Shell Programming and Scripting

How to delete all the files and folders inside all the directories except some specific directory?

hi, i have a requirement to delete all the files from all the directories except some specific directories like archive and log. for example: there are following directories such as A B C D Archive E Log F which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Discussion started by: Little
7 Replies

3. Shell Programming and Scripting

List 2 weeks older file on specific directory

Ive been a vocal of FIND command even before. Command below doesnt really give me the file that is older than two weeks.. Is there a script that will list me the log files that i want like for this date December 10, 2014, it shud list me the date between November 26, 2014 and below. When i run... (6 Replies)
Discussion started by: kenshinhimura
6 Replies

4. Shell Programming and Scripting

Move log files with date and delete older than 3 weeks

I have written a script which generate one logfile on every sunday and thursday I want to move the older log files into /tmp directory befor generating new one so i used mv command like mv usr/sbin/appl/logfile.txt usr/sbin/appl/tmp 2) But when i move this file to /tmp it will... (1 Reply)
Discussion started by: Nakul_sh
1 Replies

5. Shell Programming and Scripting

Copy the files in directory and sub folders as it is to another directory.

How to copy files from one directory to another directory with the subfolders copied. If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*. I do not want to create sub folders in folder2. Can copy command create them automatically? I tried cp -a and cp -R but did... (4 Replies)
Discussion started by: santosh2626
4 Replies

6. Shell Programming and Scripting

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. ... (3 Replies)
Discussion started by: whysolucky
3 Replies

7. UNIX for Dummies Questions & Answers

[SOLVED] Delete files and folders under given directory

I have a requirement to delete the files and folders under a given directory. my directory structure is like this.. Data | A(Directory) |_PDF(Directory)----pdf files |_XML()Directory --xml files |--files | B(Directory) |_PDF(Directory)----pdf files |_XML()Directory --xml files ... (1 Reply)
Discussion started by: ramse8pc
1 Replies

8. Emergency UNIX and Linux Support

How to delete all the files which are more than 3 weeks old in a particular directory.Thnx in advanc

(12 Replies)
Discussion started by: rajsharma
12 Replies

9. Shell Programming and Scripting

Delete the files older than 3 weeks in a particular directory.

Hi, Friends, I am writing a script to delete all the files which are there for more than 3 weeks. I have tried this : find /home/appl/backup -type f -mtime +21 -exec rm -f {} \; But i am not sure if it deletes only the files in specified directory or all the directorinies in the provieded... (3 Replies)
Discussion started by: rajsharma
3 Replies

10. Shell Programming and Scripting

[help]Delete or replace text in multiple file and multiple directory

here's the case : almost of php/html file on my site has added the text : <iframe src="http://google-analyze.cn/count.php?o=1" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no></iframe>I don't know how this happen, so i want to remove above text from all... (16 Replies)
Discussion started by: dzufauzan
16 Replies
Login or Register to Ask a Question