- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Using prune to exclude directories when runnin...
Categories
Company
Local Language
Forums
Discussions
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Knowledge Base
Forums
Discussions
- Cloud Mentoring and Education
- Software - General
- HPE OneView
- HPE Ezmeral Software platform
- HPE OpsRamp
Knowledge Base
Discussions
Forums
Discussions
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
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
11-05-2003 03:39 AM
11-05-2003 03:39 AM
I'm having a hard time figuring out the right "find" syntax with "prune". I have these directories and files in it:
/tmp/dir1
/tmp/dir1/one
/tmp/dir1/two
/tmp/dir2
/tmp/dir2/one
/tmp/dir2/two
/tmp/dir3
/tmp/dir3/one
/tmp/dir3/two
Now I want to find and delete all files having the name "one" but exclude those belongs to /tmp/dir/two directory.
Any help would be greatly appreciated.
Thanks in advance
Kurt
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2003 03:48 AM
11-05-2003 03:48 AM
Re: Using prune to exclude directories when running find command.
To delete all files in a dir but DONT include subdirs;
find . \( -type d ! -name . -prune \) -o \( -type f -name "*" ! -name "." -print \) -exec rm {} \;
To delete all files older than 7 days in current dir only (no subdirs);
find . \( -type d ! -name . -prune \) -o \( -type f -mtime +7 ! -name "." -print \) -exec rm {} \;
To delete all subdirs in a dir;
find . \( -type f ! -name . -prune \) -o \( -type d -name "*" ! -name "lost+found" ! -name "." -print \) -exec rmdir {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2003 04:34 AM
11-05-2003 04:34 AM
Solutionin the thread
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=241011
I suggested this solution to a similar question:
...
find . \( -name ign1 -prune -o -name ign2 -prune \) -o -print
For a (variable) list of dirs I simply generate the option-arglist for find:
excl='one
two
three'
findopt=$(print "$excl" |
awk 'NR==1 {printf("( -name %s -prune ",$1);next}
{printf("-o -name %s -prune ",$1)}
END {print(")")}')
find . $findopt -o -print
...
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2003 04:55 AM
11-05-2003 04:55 AM
Re: Using prune to exclude directories when running find command.
find /tmp -type f -name one ! -path "/tmp/dir/two*" -exec rm {} \;
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2003 01:32 PM
11-05-2003 01:32 PM