Operating System - HP-UX
1752651 Members
5622 Online
108788 Solutions
New Discussion юеВ

Re: How to traverse sub. dirs?

 
SOLVED
Go to solution
Michael Steele_2
Honored Contributor

Re: How to traverse sub. dirs?

Yes, that is closer to the solution. Now, how to traverse each of the other sub dirs in /u5/data?

The following doesn't work with net perms.

cat file | while read a
do
net perms /u5/data/$a/*
done

Where file = ls -d /u5/data/* > file
Support Fatherhood - Stop Family Law
Patrick Wallek
Honored Contributor

Re: How to traverse sub. dirs?

OK, now I'm totally confused!

You have files in subdirs that you need to run the 'net perm' command against.

Which files in which subdirs need this?

Are all of the sub-dirs under /u5/data? So you have megax, tomx, etc.? Or are the subdirs under /u5/data/megax?

I'm really confused about exactly what you are trying to accomplish.
Patrick Wallek
Honored Contributor

Re: How to traverse sub. dirs?

How about this:

You have a list of subdirs under /u5/data that you want to process and this list is in the file /u5/data/subdirs.

# cat /u5/data/subdirs
tomx
megax

You then write a script that reads from that file and does what you want:

#!/usr/bin/sh

for i in `cat /u5/data/subdirs`
do
find /u5/data/$i -exec net perm {} \;
done



That will run the find command for all dirs in /u5/data/subdirs execute whatever it is you need in each of the subdirs.
Darrell Allen
Honored Contributor

Re: How to traverse sub. dirs?

Maybe you need something like:

cd /u5/data
# assuming there are only directories in /u5/data
for dir in *
do
find $dir -xdev -exec chmod 777 {} \;
done

That way you'll traverse all sub-dirs of /u5/data one at a time.

If you have files in /u5/data you could change the "for" statement to:
for dir in `ll | awk '/^d/ {print $NF}'`

Is this closer to what you need?

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Michael Steele_2
Honored Contributor

Re: How to traverse sub. dirs?

All the 2.5 million files are under /u5/data.

There are 49 sub dirs. under /u5/data.

How to traverse one of 49 sub dirs under /u5/data without crossing over into another sub dir?
Support Fatherhood - Stop Family Law
Jon Mattatall
Esteemed Contributor

Re: How to traverse sub. dirs?

I'm not understanding this.

if you have /u5/data/1, /u5/data/2, ... /u5/data/400,
and you cd to /u5/data, then a simple find 2 will give you only the files/dirs under /u5/data/2/*.

If you just want files listed, not directories, use the type f option.

ie: find 2 -type f (pwd=/u5/data)

Jon
A little knowledge is dangerous - none is absolutely terrifying!!!
Patrick Wallek
Honored Contributor

Re: How to traverse sub. dirs?

Are you saying that the subdirs have subdirs?

Like /u5/data/megax/someotherdir

and you DON'T want to go into the someotherdir directory under megax?
Sajid_1
Honored Contributor

Re: How to traverse sub. dirs?

hello,

you can write a script for doing this. first get a list of all sub-dirs, then:

for s in `cat sub_dir_list`
do
find /u5/data/$i -depth -exec net perms {} \;
done

This will do each dir. seperately and if you want you can add more lines for more functions.
learn unix ..
Sajid_1
Honored Contributor

Re: How to traverse sub. dirs?

oops.. it should be:

find /u5/data/$s ..

actually, are you trying to give different settings for different sub-dirs?
learn unix ..
Michael Steele_2
Honored Contributor

Re: How to traverse sub. dirs?

The closest was Darrell and Sajid which are restatements of each other. Darrel had the following for instance.

cd /u5/data
# assuming there are only directories in /u5/data

for dir in *
do
find $dir -exec net perms {} \;
done

But I'm going to have to substitute an inner loop for the find command above in order to break apart the data and write output to 49 separate files for all 49 dirs.

I think that will do it.

Thanks
Support Fatherhood - Stop Family Law