Computing.Net > Forums > Unix > Delete Directories based on mtime

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Delete Directories based on mtime

Reply to Message Icon

Name: Sri123
Date: October 29, 2003 at 07:57:05 Pacific
OS: HP-UX11
CPU/Ram: How do I find the Process
Comment:

Hi,
I want to delete directories owned by ID1 if they are older than 2 days and also delete directories owned by rest of the ID's in the same directory, if they are older than 5 days.
I was able to seperate the list of directories by their ID. How do I compare these directories' modification time with the current time to decide on whether to delete or not?
Any Ideas...



Sponsored Link
Ads by Google

Response Number 1
Name: Frank
Date: October 29, 2003 at 08:11:58 Pacific
Reply:

Hi,

You should be carful to delete directories.

ok the statement below will delete all directorys of user ID1 including the content of the directory and sub dirs.

find /u/ID1 -type d -mtime +2 -user ID1 -exec rmdir -R {} \;

You know, make a copy of things which you delete.
tar -cf - -C /u/ID1 \
`find . -type d -mtime +2 -user ID1` \
|compress -C >> wech.tar.Z


NO RISK no Fun

Frank


0

Response Number 2
Name: Sri123
Date: October 29, 2003 at 09:52:24 Pacific
Reply:

Thanks for the info.. and your suggestion.

But, How do check the modification time of directories that doesn't belong to ID1 before deleting them?

Thanks


0

Response Number 3
Name: Frank
Date: October 31, 2003 at 05:43:13 Pacific
Reply:

Hi,

just don't ask for the userId.
If you delete 1 all directory's of ID1 which are older than 2 day's and than delete all directorys from all users (including ID1) which are older than 5 days than it is not nessecary to extract directorys of user ID1, because they was already deletet.


find /u/ID1 -type d -mtime +5 -exec rmdir -R {} \;



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Delete Directories based on mtime

renaming files based on date arguments www.computing.net/answers/unix/renaming-files-based-on-date-arguments/2499.html

delete directory www.computing.net/answers/unix/delete-directory/2414.html

Delete files from textfile listing? www.computing.net/answers/unix/delete-files-from-textfile-listing/7218.html