LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-21-2011, 06:08 AM   #1
swathikumar
LQ Newbie
 
Registered: May 2011
Posts: 9

Rep: Reputation: Disabled
Thumbs up How to find the directory and remove the directory


Hi All,

As per my requirement, I have to find the directory names contains "numbers" and i have to remove it was created 3 days before.

For example i have the root directory and it contains the sub directory names like 55 40 57 60 65
here i have to find which directory was created 3 days before and i have to delete the directory and the files.

Now i am using the below command but it does not work

swathi$ find . -regex './[0-9][0-9]' -type d -mtime +0 -exec rm -rf {} \;

Please give the proper command.

Thanks
SwathiKumar
 
Old 11-21-2011, 08:29 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
That command should work with one exception. You have mtime stating you want it to delete files that were created 24 hours ago and older. So if you just created the files they wouldn't be deleted.

And based on your description you said you wanted it to delete folders which where created 3 days before which I assume means 3 days and older. In that case you should be telling find -mtime +3.

If you want to test it you can modify the mtimes using touch and tell it to use an older date.

Code:
touch -d '2007-01-31 8:46:26' some_file_or_folder
SAM
 
Old 11-21-2011, 09:46 AM   #3
swathikumar
LQ Newbie
 
Registered: May 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
HI
As per i know the below command, will remove some other directories also which is created 3 days before. But it should not delete other directories.
find -mtime +3

It should find the directory which contains number and should remove.

Please provide me the proper unix command.

Thanks
SwathiKUmar
 
Old 11-21-2011, 12:38 PM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
You already have the proper Unix command. It is your original command and then modify the value I specified. What don't you understand? Perhaps you should read the find man page to better understand what I did. Not sure how I could more clearly represent it for you. I wasn't giving you a find command I was telling you to modify your command.

Quote:
In that case you should be telling find -mtime +3.
In this case I am using find as part of the sentence, not a command.

SAM

Last edited by sag47; 11-21-2011 at 12:41 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rm: cannot remove directory `ff': Directory not empty blancs Linux - General 17 08-29-2011 01:47 PM
Find directory older than x and mv directory with sub files command ajhart Linux - Newbie 4 07-15-2011 05:24 AM
help how to remove directory blackman890 Mandriva 6 11-09-2004 06:06 PM
remove directory?? KaktusKnight Linux - General 8 05-31-2003 01:26 PM
Remove a Directory RedHatMN Linux - Newbie 2 12-05-2001 02:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration