Unix Technical Forum

find command and excluding files under specific directories

This is a discussion on find command and excluding files under specific directories within the AIX Operating System forums, part of the Unix Operating Systems category; --> Help with find and excluding files under specific directories. For these specific dirs, I want to exclude all files ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2008, 07:03 AM
shpot4@yahoo.com
 
Posts: n/a
Default find command and excluding files under specific directories


Help with find and excluding files under specific directories.
For these specific dirs, I want to exclude all files under, but keep
the directory names.

/opt/2004/jan
/opt/2004/feb/logs
/opt/2004/mar/outs

Could someone please tell me the correct syntax I should use for my
find command? And don't tell me to read the man pages, because I've
done that!

Cheers!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-05-2008, 07:03 AM
Sun
 
Posts: n/a
Default Re: find command and excluding files under specific directories


you can try this

find /opt/2004 -type d -print

-SR

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 07:03 AM
shpot4@yahoo.com
 
Posts: n/a
Default Re: find command and excluding files under specific directories


Sun,
That will exclude the entire directory /opt/2004 and everything under
it. I need to keep the directory structure, and remove files "under".

Cheers!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 07:03 AM
Laurenz Albe
 
Posts: n/a
Default Re: find command and excluding files under specific directories

shpot4@yahoo.com wrote:
>>> Help with find and excluding files under specific directories.
>>> For these specific dirs, I want to exclude all files under, but keep
>>> the directory names.

>>
>> find /opt/2004 -type d -print

>
> That will exclude the entire directory /opt/2004 and everything under
> it. I need to keep the directory structure, and remove files "under".


First, please keep some of what you are referring to when replying!
It makes reading so much easier.

Second, That will NOT exclude the entire directory /opt/2004. Did you try
it?

Maybe the response was not what you needed, but it is hard to tell as you
do not make yourself clear:

- What exactly do you want to find?
- What are 'specific directories'?
- Is a directory a file?

If you cannot explain it, maybe you can provide an example (before/after)
detailed enough so we can guess what you want.

Yours,
Laurenz Albe
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-05-2008, 07:03 AM
Sun
 
Posts: n/a
Default Re: find command and excluding files under specific directories

if you want remove only files, you can use this find command

find /opt/2004 -type f -exec rm {} \;

or

find /opt/2004 -type f -print | xargs rm -f

-SR

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-05-2008, 07:03 AM
Don Davis
 
Posts: n/a
Default Re: find command and excluding files under specific directories



shpot4@yahoo.com wrote:

> Help with find and excluding files under specific directories.
> For these specific dirs, I want to exclude all files under, but keep
> the directory names.
>
> /opt/2004/jan
> /opt/2004/feb/logs
> /opt/2004/mar/outs
>
> Could someone please tell me the correct syntax I should use for my
> find command? And don't tell me to read the man pages, because I've
> done that!
>
> Cheers!


read man pages
concentrate on -type f and the -prune options

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-05-2008, 07:03 AM
Stephane Gassies
 
Posts: n/a
Default Re: find command and excluding files under specific directories

A simple way is
find /opt | egrep -v '/opt/(jan|feb/logs|mar/outs)/'

But it uses two commands and a pipe sigh!
OBS: the trailing / does mots of the job ...

> shpot4@yahoo.com wrote:
>
> > Help with find and excluding files under specific directories.
> > For these specific dirs, I want to exclude all files under, but keep
> > the directory names.
> >
> > /opt/2004/jan
> > /opt/2004/feb/logs
> > /opt/2004/mar/outs
> >
> > Could someone please tell me the correct syntax I should use for my
> > find command? And don't tell me to read the man pages, because I've
> > done that!
> >
> > Cheers!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-05-2008, 07:03 AM
shpot4@yahoo.com
 
Posts: n/a
Default Re: find command and excluding files under specific directories


Thanks Stephane! That works!

Cheers!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:34 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com