Operating System - HP-UX
1751701 Members
5625 Online
108781 Solutions
New Discussion юеВ

Re: How to traverse sub. dirs?

 
SOLVED
Go to solution
Michael Steele_2
Honored Contributor

How to traverse sub. dirs?

Hi Everyone: From a starting point of /u5/data/ I would like traverse down each subdirectory without crossing into another. For example, /u5/data/tomx/*, but not /u5/data/megax/*. This would be similar to find /u5/data/* -xdev. ( But not. )
Support Fatherhood - Stop Family Law
25 REPLIES 25
Patrick Wallek
Honored Contributor

Re: How to traverse sub. dirs?

I assume you are using find?

Are there certain sub-dirs you want to go into and others you don't?

Can you not just specify 'find /u5/data/tomx -name filename'

Michael Steele_2
Honored Contributor

Re: How to traverse sub. dirs?

Yes I am using find.
The problem is not limited to one file but 2.5 million files spread out across 49 sub dir.s under /u5/data. Each file requires that a command be run against it, i.e, find /u5/data/megax/* -xdev -exec chmod 777 {} \;
Support Fatherhood - Stop Family Law
Sajid_1
Honored Contributor

Re: How to traverse sub. dirs?

hello,

may be this will:
# find /u5/data/megax -xdev -print
learn unix ..
Patrick Wallek
Honored Contributor

Re: How to traverse sub. dirs?

If all files in a sub-dir need a chmod command run against them, why are you using find?

Why not something like:

# cd /u5/data
# chmod -R 777 megax

If you need the megax directory itself to be some other permissions then you could do:

# chmod 555 megax

Michael Steele_2
Honored Contributor

Re: How to traverse sub. dirs?

Sorry. I should have not used chmod 777 as an example. In reality the command is the following: find /u5/data -xdev -exec net perms {} \;

And again, chmod -R is a recursive command that will cross over into other sub directories.

The solution to this problem is not to cross over into another sub dir from a starting point of: /u5/data/megax, for example.

I.e, find /u5/data -(something here) -exech net perms {} \;
Support Fatherhood - Stop Family Law
Sajid_1
Honored Contributor

Re: How to traverse sub. dirs?

hello,

try this:
# find /u5/data/tomx -xdev -exec chmod 777 {} \;

You can also try chmod -R
learn unix ..
Gregory Fruth
Esteemed Contributor

Re: How to traverse sub. dirs?

It's still not clear to me why the previous poster's
suggestion wouldn't work.

If you are trying to exclude certain directories from
the find command, you can use the ! operator:

find /u5/data \! -path '/u5/data/megax*' -exec ...

You can use the () and -a operators if you have
multiple directories you want to exclude.

HTH

Michael Steele_2
Honored Contributor

Re: How to traverse sub. dirs?

find xdev only works on mount points. Substitute mount point with sub dir for the correct answer.

find /u5/data/!, etc. omits one of the 49 sub dir.s only.
Support Fatherhood - Stop Family Law
Sajid_1
Honored Contributor

Re: How to traverse sub. dirs?

hello,

start your find from /u5/data/tomx and not /u5/data. this will search only that directory.
learn unix ..