You are not logged in.

#1 2009-11-20 21:32:07

futuremonkey
Member
Registered: 2009-02-28
Posts: 49

[SOLVED] shell script to get names of subdirectories?

I have a directory /foo that regularly has new subdirectories created in it.  I want to create a script that will see what those subdirs are and then allow me to put their full pathnames in a variable.  I can do this already, but I want to exclude /foo.

I'm sorry I can't come up with a clearer way to explain what I mean.

I'm currently using:

for DIRS in $(find /foo -type d); do echo $DIRS; done

That results in:

/foo
/foo/bar
/foo/blah
/foo/poo
/foo/zoo
(etc)

I want all of those EXCEPT the first line.  How can I strip the first line out of that result?

Last edited by futuremonkey (2009-11-20 22:05:43)

Offline

#2 2009-11-20 21:33:34

kazuo
Member
From: São Paulo/Brazil
Registered: 2008-03-18
Posts: 413
Website

Re: [SOLVED] shell script to get names of subdirectories?

Pass -mindepth 1 to find

Offline

#3 2009-11-20 21:33:46

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] shell script to get names of subdirectories?

man find; look for mindepth.

also just the find command will print the dirs, you don't need to put echo in a for loop.

/edit blurg, my rtfm was too slow...

Last edited by brisbin33 (2009-11-20 21:34:23)

Offline

#4 2009-11-20 22:05:15

futuremonkey
Member
Registered: 2009-02-28
Posts: 49

Re: [SOLVED] shell script to get names of subdirectories?

Thanks, -mindepth was the thing.

I actually DID read the man page, believe it or not, and I saw mindepth/maxdepth but completely failed to understand what they meant.

Also, I intend to do something other  than just print the names with the FOR loop.  That was just for the sake of example.

Thanks again.

Offline

Board footer

Powered by FluxBB