- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find command...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:02 AM
05-07-2004 03:02 AM
I have a directory that has a bunch of directories. I want to remove all directories inside that directory that are older than 90 days, using the timestamp of that directory. Example:
# ll /maindir
drwxrwsr-x 4 speclive live 8192 Aug 17 2003 dir1
drwxrwsr-x 4 spxlive live 8192 May 7 09:32 dir2
drwxrwsr-x 4 spxlive live 8192 May 3 05:33 dir3
drwxrwsr-x 2 spxlive live 96 Jan 24 14:59 dir4
Therefore I would want dir1 and dir4 deleted, with all the contents under them.
Also, I would first want to list which directories I selected, then remove them (these can be in two different find commands). Here is what I have so far, but it's working right:
find /maindir -name * +mtime +90 -exec ll {} \;
find /maindir -name * +mtime +90 -exec rm {} \;
I've also tried playing with -prune, but it doesn't do what I want.
10 points to the person who can help me solve this! Thanks!
-Hazem
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:06 AM
05-07-2004 03:06 AM
Re: find command...
I think you're close but you need to specify the directory option:
find /maindir -type d -name * +mtime +90 -exec ll {} \;
find /maindir -type d -name * +mtime +90 -exec rm {} \;
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:08 AM
05-07-2004 03:08 AM
Re: find command...
1. * is evaluated by your shell when launching so it will only find dirs that are in your start dir ".". You should put
-name "*" instead so that * is evaluated each time
2. -name "*" is what is done by default if you don't put -name.
So your command could be :
find /maindir -type d +mtime +90 -exec ll {} \;
regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:09 AM
05-07-2004 03:09 AM
Re: find command...
yes, the "-type d" is what you want, but
to list the acutal directories found do:
use: "-exec ls -ld {} \;"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:15 AM
05-07-2004 03:15 AM
Re: find command...
find: missing conjunction
I also tried it without the -name option.
-Hazem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:15 AM
05-07-2004 03:15 AM
Re: find command...
using "ll {}\;" will list the content of each directory found. you should use -d option to see the directory itself.
So it will look :
find /maindir -type d +mtime +90 -exec ll -d {} \;
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:17 AM
05-07-2004 03:17 AM
Re: find command...
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:26 AM
05-07-2004 03:26 AM
Re: find command...
find /maindir -type d -mtime +90 -exec ll -d {} \;
Good catch on the -mtime Fred, that was one of my problems. Also, it did not like it when I specified -name *, so another good catch on that one Fred.
However, it is giving me all directories under /maindir, including the sub-directores under the directories in /maindir. So it is still recursively going down the directory structure. It is however giving me the directores older than 90 days that are directly under /maindir.
Any ideas how to stop it from going further down the directory structure?
-Hazem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:27 AM
05-07-2004 03:27 AM
Re: find command...
about the concept this time. It's not because your dir has a modification date older than 90 days that all of its subdirs will be older than 90 days.
Once you'll run the find with ll, take the answers, and do the same find with "-mtime -90" on them...
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:34 AM
05-07-2004 03:34 AM
Re: find command...
-Hazem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 03:56 AM
05-07-2004 03:56 AM
Re: find command...
#find /etc -type d -mtime +90 -prune -exec ls -ld {} \;
dr-xr--r-- 4 bin bin 96 Nov 15 2000 /etc/ftpd
dr-xr-xr-x 11 bin bin 8192 Jan 14 07:41 /etc/vx
dr-xr-xr-x 2 bin bin 8192 Jan 14 07:17 /etc/hpC2400
dr-xr-xr-x 2 bin bin 96 Nov 15 2000 /etc/local
dr-xr-xr-x 2 bin bin 96 Jan 14 07:59 /etc/default
dr-xr-xr-x 2 bin bin 96 Nov 15 2000 /etc/hparray
drwxr-xr-x 4 root sys 96 Nov 15 2000 /etc/vhelp
drwxr-xr-x 3 bin bin 8192 Nov 15 2000 /etc/ppp
dr-xr-xr-x 3 bin bin 8192 Jan 14 17:49 /etc/sam
drwxr-xr-x 12 root bin 8192 Jan 14 07:57 /etc/opt
drwxr-xr-x 2 bin bin 96 Nov 15 2000 /etc/gss
drwxr-xr-x 2 bin bin 96 Nov 15 2000 /etc/acct
drwxr-xr-x 3 bin bin 96 Nov 15 2000 /etc/asx
drwxr-xr-x 8 lp bin 8192 Nov 15 2000 /etc/lp
dr-xr-xr-x 2 bin bin 8192 Nov 15 2000 /etc/uucp
drwxr-xr-x 8 root sys 8192 Jan 14 07:57 /etc/X11
drwxr-xr-x 3 bin bin 96 Nov 15 2000 /etc/vue
drwxr-xr-x 5 bin bin 96 Nov 15 2000 /etc/net
drwxr-xr-x 4 bin bin 96 Jan 14 07:53 /etc/dt
dr-xr-xr-x 2 bin bin 96 Jan 14 07:17 /etc/switch
dr-xr-xr-x 2 bin bin 8192 Jan 14 07:17 /etc/eisa
drwxr-xr-x 3 root root 96 Jan 14 07:23 /etc/.java
dr-xr-xr-x 3 bin bin 96 Jan 14 07:41 /etc/cmcluster
drwxr-xr-x 2 root sys 96 Jan 14 07:54 /etc/ximian
Difference with or whitout -prune :
#find /etc -type d -mtime +90 -prune -exec ls -ld {} \; | wc -l
24
#find /etc -type d -mtime +90 -exec ls -ld {} \; | wc -l
187
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 04:39 AM
05-07-2004 04:39 AM
Re: find command...
-Hazem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 04:42 AM
05-07-2004 04:42 AM
Re: find command...
# find /etc -type d -mtime +90 -exec ls -d {} \; |wc
175 175 4468
# find /etc -type d -mtime +90 -prune -exec ls -d {} \; |wc
46 46 680
Now - as far as rm, it won't delete directory's if they have contents - unless you do a rm -rf and that is dangerous!
I would be more inclined to find all dirs over 90 days, list their contents, then delete the files under them - just to be safe....
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2004 04:46 AM
05-07-2004 04:46 AM
Re: find command...
Congratulations on your new hat Fred!!! I hope your first hat feels good!:)
-Hazem