Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


LinkBack Search this Thread
Old 02-08-2007, 10:43 AM   #1
Registered: Aug 2006
Posts: 100

Rep: Reputation: 15
about subdirectories

hi folks,
i want to know a shell command that enables me to check that my current directory have some directories or not
and asolutly their names if possible?

i have tried test command but i cant do it.

thanks in advance.
Old 02-08-2007, 11:23 AM   #2
Senior Member
Registered: Nov 2005
Distribution: Debian
Posts: 2,307

Rep: Reputation: 767Reputation: 767Reputation: 767Reputation: 767Reputation: 767Reputation: 767Reputation: 767
find . -maxdepth 1 -mindepth 1 -type d
for file in * .*; do if [ -d "$file" ] ; then echo "$file"; fi; done
Old 02-08-2007, 04:02 PM   #3
Registered: Aug 2006
Posts: 100

Original Poster
Rep: Reputation: 15
thank u for wonderful answer
it is really so useful for me ,
i have used find command u sent but,
i want to save the result into a shell array variable

thanks in advance
Old 02-08-2007, 04:09 PM   #4
Registered: Aug 2006
Posts: 100

Original Poster
Rep: Reputation: 15
when i tried the following:

directories=`find . -maxdepth 1 -mindepth 1 -type d`
echo $directories

i got ./folder1 ./folder2

but i want to access each of (folder1 and folder2)alone,how can i do that
i.e. i want to assign ./folder1 to a variable while
./folder2 to another variable
Old 02-08-2007, 06:18 PM   #5
Registered: Oct 2006
Distribution: debian
Posts: 124

Rep: Reputation: 15
Here's a generic solution for getting the arguments one at a time. You can then put them into array cells, run code on them, whatever you please.


find . -maxdepth 1 -mindepth 1 -type d |\
while read dirname
    echo "Find number $i is called $dirname"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert encoding through subdirectories? dl7und Linux - Software 2 04-16-2006 01:06 AM
Makefile and subdirectories pycoucou Programming 4 08-18-2005 04:43 AM
list all contains and subdirectories' contains babis Linux - Newbie 2 10-22-2004 09:40 PM
Unzipping all .gz files in all subdirectories darin3200 Linux - General 10 04-24-2004 09:58 PM
email and subdirectories hiertjou123 Linux - Newbie 5 07-16-2003 01:08 PM

All times are GMT -5. The time now is 11:38 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration