Delete directory on date base


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete directory on date base
# 1  
Old 11-10-2013
Delete directory on date base

Hi,

I have below directories

Code:
Direct 2013-08-12 23123
Direct 2013-08-13 24121
Direct 2013-08-14 34513

Direct 2013-08-31 15435
...........

Direct 2013-09-12 53145
Direct 2013-09-30 65234

Direct 2013-09-30 89642

My task is to delete all directories which are four days old as per below format but before that i want to list it.

so i will see following directories

Code:
Direct 2013-11-10 53354
Direct 2013-11-09 13454
Direct 2013-11-08 51325
Direct 2013-11-07 53515

Code:
I don't know how i can merge it my task.
find ./ -type d -mtime +4 -exec rm -rf {} \;

# 2  
Old 11-10-2013
You can have multiple -exec actions in your find command. Try adding -exec ls {} \;.
# 3  
Old 11-10-2013
Quote:
Originally Posted by RudiC
You can have multiple -exec actions in your find command. Try adding -exec ls {} \;.
ls option i know but to grep pattern that show only four day old directory.
# 4  
Old 11-10-2013
Sorry?
# 5  
Old 11-10-2013
Code:
find . -ls -exec rm \{\} \;


Last edited by Scott; 11-10-2013 at 01:48 PM.. Reason: Code tags
# 6  
Old 11-10-2013
I am confuse.

Let me rephrase.

I have below pattern directories, i want to keep just 4 days old directories as per below pattern and wants to delete all old directories which is having below pattern and comes under 4 days old.

Code:
Direct 2013-11-10 53354
Direct 2013-11-09 13454
Direct 2013-11-08 51325
Direct 2013-11-07 53515

# 7  
Old 11-10-2013
Doesn't the -mtime +4 test do the job for you?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

2. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

3. Shell Programming and Scripting

How to append date to filename, but base it on yesterday's date?

Hello, I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead. Here's what I... (5 Replies)
Discussion started by: nbsparks
5 Replies

4. Shell Programming and Scripting

Massive Copy With Base Directory

I have a script that I am using to copy around 40-70k files to a NFS NAS. I have posted my code below in hopes that someone can help me figure out a faster way of achieving this. At the end of the script i need to have all the files in the list, copied over to the nas with source directory... (8 Replies)
Discussion started by: nitrobass24
8 Replies

5. Shell Programming and Scripting

Needs to delete particular date files in a directory

Hi Guys, I need help on deleting particular date files in a directory. I have to delete thousands of files with respect to particular date. Could anyone help on this to delete particular date files at a time? Thanks in Advance (2 Replies)
Discussion started by: teddy2882
2 Replies

6. Shell Programming and Scripting

Base directory of the package

Hello, I have an RPM package for which I need to know the base directory /opt/appdir. But if the package is relocated, then it will be different. I need to get the value dynamically. I tried to query the RPM with INSTPREFIXES but couldn't get the value. The only way I see is to do 'rpm -ql RPM... (2 Replies)
Discussion started by: chiru_h
2 Replies

7. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

8. Shell Programming and Scripting

script to delete contents in a directory by date

Hi , I am trying to make a cron job to delete the contents of a directory in a linux environment.The contents created before 2 days should get deleted by this job.Here is what i have written : /usr/bin/find / -name *.log -ctime +2 -exec /bin/rm -f {} \; Is it correct....If not so,please... (9 Replies)
Discussion started by: d8011
9 Replies

9. Solaris

Missing Base Directory

Hey all, I'm attempting to migrate a zone from one system to another, but I noticed that on the new system ssl BASEDIR was missing. I was wondering if creating the directory path for this would fix the issue when I migrate files over. SSL is installed on the new system but does not show a... (1 Reply)
Discussion started by: em23
1 Replies

10. UNIX for Dummies Questions & Answers

Find command to run only in the base directory

Hi. I'm trying to get my find command to only search in the directory i tell it to, but i don't want it to search in the sub directories as well... For example, i have a /data/files/ and /data/files/old I want to search for all .sav files within /data/files but i don't want it to drill... (4 Replies)
Discussion started by: Stephan
4 Replies
Login or Register to Ask a Question