- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find files to remove but skip subdirectories
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
10-24-2006 11:36 PM
10-24-2006 11:36 PM
with a /tmp that has number (about 20)
of subdirectories like .oracle and .tivoli
and a couple of others , which I do not like to search for removal.
I want to cleanup all files older then 7 days
in /tmp but not in /tmp/.oracle and /tmp/.tivoli, /tmp/xxx/, /tmp/yyy etc..
find . -name "*" -type f -print -mtime +7 -exec rm {} \;
Will remove also files in the subdirectories
of /tmp when the files are older then 7 days.
Thanks for your input.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2006 11:46 PM
10-24-2006 11:46 PM
Re: find files to remove but skip subdirectories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2006 11:51 PM
10-24-2006 11:51 PM
Re: find files to remove but skip subdirectories
what about
find /tmp \( -name .oracle -prune \) \( -name .tivoli -prune \) -type f -print -mtime +7 -exec rm {} \;
or in case you like to search .oracle (et all) file in deep subdirectory
find . -name "*" -type f -mtime +7 -print |\
awk -F/ '$2 == ".oracle" { next }
$2 == ".tivoli" { next }
{printf "rm -f %s\n",$0 ;}' | ksh
Jean-Yves Picard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2006 11:54 PM
10-24-2006 11:54 PM
Re: find files to remove but skip subdirectories
# find /tmp |wc -l
79
# find /tmp -prune |wc -l
1
# find /tmp/* -prune |wc -l
69
# find /tmp/* |wc -l
69
So, following down through subdirectories, we come up with 79 entries. With prune, we only see /tmp itself. By changing the starting point and using prune, we come up with 69 entries. By changing the starting point and not bothering with prune, we still come up with 69 entries. It leads me to question what prune is really doing???????
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2006 12:01 AM
10-25-2006 12:01 AM
Re: find files to remove but skip subdirectories
# find /tmp -type f -mtime +7 ! -path "/tmp/.oracle/*" -a ! -path "/tmp/.tivoli/*" | xargs rm
Note the use of '! -path'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2006 12:09 AM
10-25-2006 12:09 AM
Solutionwhy use find, when you do not want to look for files recursivly?
Suggestion:
> date
Wed Oct 25 14:04:01 METDST 2006
> cd /tmp
> touch 10181405 .rmflag
> for f in *
do
[ -d $f -o $f -nt .rmflag ] && continue
rm -i $f
done
Drop the -i - flag if you are shure ...
If you need to create .rmflag dynamically, you'll have to do date arithmetics.
mfG Peter
date
touch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2006 02:35 AM
10-25-2006 02:35 AM
Re: find files to remove but skip subdirectories
from all your answers I constructed this
find command that works for me.
Please note I have over 20 subdirectories,
and I am very lazy typist so the answers
with ( !path .oracle ) are not for me.
find /tmp/* -type f -prune -mtime +3 -print -exec rm {} \;
this removes only files stricly in /tmp and
not in its subdirectories and it prints which ones were older then 3 days.