PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > listing directories
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

listing directories

Réponse
 
LinkBack Outils de la discussion
Vieux 19/08/2006, 10h21   #1
JyotiC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut listing directories

hi,

i wanna write a shell script which will list all the directories in
that folder,
it should only output dir no other file.
is there a command to do so

thanx
Jyoti

  Réponse avec citation
Vieux 19/08/2006, 10h46   #2
Frank Terbeck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

JyotiC <jyoti.chhabra@gmail.com> wrote:
> i wanna write a shell script which will list all the directories in
> that folder,
> it should only output dir no other file.
> is there a command to do so


find . -type d -print

Regards, Frank

--
There are no threads in alt.binaries.pictures.erotica,
so there's no gain in using a threaded news reader.
-- unknown source
  Réponse avec citation
Vieux 19/08/2006, 10h47   #3
Stephan 'smg' Grein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

JyotiC wrote:
> hi,
>
> i wanna write a shell script which will list all the directories in
> that folder,
> it should only output dir no other file.
> is there a command to do so
>
> thanx
> Jyoti
>


find "$MY_DIR" -type d

man find

i.A.,
- --
Stephan 'smg' Grein, <stephan at stephan minus rockt dot de>
http://stephangrein.de
GnuPG-Key-ID: 0xF8C275D4
FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
Geek by nature, Linux by choice.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iQIVAwUBRObePo1LAjD4wnXUAQKYlg/9HA67rqiEBY10aunic1RrjjCLEv8N6Akf
Di3Vb479h6j1QASntku5zEKQUT7+RE6RlE2fFO1z6PLQU85H4S qOIFgHbtVBBwrO
ZUG2Ft9LOcDytuJn9om/3LQP9dxHc/EnJTz+InfDWQjUNK/5xI3TlLtRcVOdeg92
5HK5nxTw//QXOErkH1E4blXwdMoLW5XQBMXTayCqP8adIkxtHYIpiyYTHiEI ncWM
lM2QsPF6fYF1js9CCPLto2YJdhy20sVodTxDd4pNAi7mMEjuy3 IH8PLxbVpvxM1U
nJjDyg0uBX/4QgyTrV5aW1/hL32J7+DBi2woCKdPhLjaUZW8R3E6gpG7Sxl4BoLe
EpHA0h6cp6GbD42YnqmhVRKI+2kJb3ftnnGKUhRPwzCY0aIFTd F684KqRfh8ciSw
J5eAXelXgNNjKMNKnHt9+oOCr3pIfFBoBXbzeDKd/VBgDgmYtGV9q7FS8L0bKPWY
5JnnQzS5MXoDKSaesrcPAi004SL9YhmBTVGx/nbThQS8UZrJPF7t14lYxJcyr8L0
U3EpsVZwv8QtMslVJ8hfYP4W51yZRpDz5ELzCg/rR+bzRsplcQC3kwnNQrOTQEe8
eaDD4qZ8PVKkOgb6W/uBkKBcoesCpnJuj8raFd+2Nx1wDBMJecQvUtZzHJMMpFtU
1EP0rKewVj0=
=l3qd
-----END PGP SIGNATURE-----
  Réponse avec citation
Vieux 19/08/2006, 11h11   #4
JyotiC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

thanx for ur
with find -type d
it's recursively going inside the directory and giving all the
subdirectories
is there a way through with i get only top directories, not the sub-dir

thanx
Jyoti

  Réponse avec citation
Vieux 19/08/2006, 11h38   #5
Michael Heiming
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

In comp.unix.shell JyotiC <jyoti.chhabra@gmail.com>:
> thanx for ur
> with find -type d
> it's recursively going inside the directory and giving all the
> subdirectories
> is there a way through with i get only top directories, not the sub-dir


Sure just check the fine manual 'man find' on howto restrict
'find' to descend only how deep you want.

Good luck

BTW
Since you might be new to usenet, this is *NOT* a groups.google
forum, even if it looks like this to you, please quote context:

"Google Groups users please read - Howto reply properly"
http://groups.google.com/support/bin...y?answer=14213

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
#bofh excuse 28: CPU radiator broken
  Réponse avec citation
Vieux 19/08/2006, 12h37   #6
Bruce Barnett
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

"JyotiC" <jyoti.chhabra@gmail.com> writes:

> hi,
>
> i wanna write a shell script which will list all the directories in
> that folder,
> it should only output dir no other file.
> is there a command to do so


Here's another quick solution (besides find) if you can deal with ls -l

ls -l | grep '^d'


--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
  Réponse avec citation
Vieux 19/08/2006, 12h39   #7
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

2006-08-19, 03:11(-07), JyotiC:
> thanx for ur
> with find -type d
> it's recursively going inside the directory and giving all the
> subdirectories
> is there a way through with i get only top directories, not the sub-dir

[...]

find . \! -name . -prune -type d -print

Or with most shells:

printf '%s\n' */

With zsh:

print -rl -- *(/)

--
Stéphane
  Réponse avec citation
Vieux 19/08/2006, 13h21   #8
Steve Youngs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

* Stephane CHAZELAS <this.address@is.invalid> writes:

> 2006-08-19, 03:11(-07), JyotiC:
>> thanx for ur
>> with find -type d
>> it's recursively going inside the directory and giving all the
>> subdirectories
>> is there a way through with i get only top directories, not the sub-dir

> [...]


> find . \! -name . -prune -type d -print


find . -type d -maxdepth 1

Seems a little easier.

> Or with most shells:


> printf '%s\n' */


> With zsh:


> print -rl -- *(/)


Neither of those would list the dot-directories. How about good ol'
ls(1)...

ls -d */ # just ordinary directories
ls -d .*/ # just dot-directories
ls -d .*/ */ # both

Add `1' (one) to the options (ls -d1) if you need a single column.

--
|---<Steve Youngs>---------------<GnuPG KeyID: A94B3003>---|
| Te audire no possum. |
| Musa sapientum fixa est in aure. |
|----------------------------------<steve@youngs.au.com>---|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (GNU/Linux)
Comment: The SXEmacs Project <http://www.sxemacs.org>
Comment: Eicq - The SXEmacs ICQ Client <http://www.eicq.org/>

iEYEARECAAYFAkTnAi8ACgkQHSfbS6lLMANCtQCg1PdqUrREIm XKj8DloHyq+99a
64AAoNacdLImlE2MuxVR4A/0JDowOgw6
=3pPB
-----END PGP SIGNATURE-----
  Réponse avec citation
Vieux 19/08/2006, 13h40   #9
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

2006-08-19, 22:21(+10), Steve Youngs:
>
> * Stephane CHAZELAS <this.address@is.invalid> writes:
>
> > 2006-08-19, 03:11(-07), JyotiC:
> >> thanx for ur
> >> with find -type d
> >> it's recursively going inside the directory and giving all the
> >> subdirectories
> >> is there a way through with i get only top directories, not the sub-dir

> > [...]

>
> > find . \! -name . -prune -type d -print

>
> find . -type d -maxdepth 1
>
> Seems a little easier.


But is not Unix. Only in GNU and some BSDs.


> > Or with most shells:

>
> > printf '%s\n' */

>
> > With zsh:

>
> > print -rl -- *(/)

>
> Neither of those would list the dot-directories. How about good ol'
> ls(1)...
>
> ls -d */ # just ordinary directories
> ls -d .*/ # just dot-directories
> ls -d .*/ */ # both


It's the shells that provide with the list, ls only displays
them, so printf is just as good for that.

With zsh:

print -rl -- *(D/)

Will still ommit "." and "..".

print -rl -- . .. *(D/)

if you need them.

Also, assuming the filenames don't contain newline characters:

ls -Fa | grep /

--
Stéphane
  Réponse avec citation
Vieux 20/08/2006, 00h53   #10
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

Steve Youngs wrote:
> ls -d */ # just ordinary directories
> ls -d .*/ # just dot-directories
> ls -d .*/ */ # both
> Add `1' (one) to the options (ls -d1) if you need a single column.


If one only wants single-column output, then do
not fork an entire process just to do it:

print -r -- .*/. */.

P.S.:

RTFM for shell option modifiers that can affect
the above behavior:

set -m & set -o markdirs
set -n & set -o noglob

BUG: Unfortunately, in ksh(1), the converse does
NOT emit only non-directory files:

print -r -- !(*/.) # doesn't work!

=Brian

  Réponse avec citation
Vieux 20/08/2006, 05h37   #11
Steve Youngs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

* Stephane CHAZELAS <this.address@is.invalid> writes:

> 2006-08-19, 22:21(+10), Steve Youngs:
>>
>> * Stephane CHAZELAS <this.address@is.invalid> writes:
>> > find . \! -name . -prune -type d -print

>>
>> find . -type d -maxdepth 1
>>
>> Seems a little easier.


> But is not Unix. Only in GNU and some BSDs.


OK. I've been spoiled too much by GNU/find. :-) However, I do think
it is probably a safe bet that the OP is using GNU/find.


--
|---<Steve Youngs>---------------<GnuPG KeyID: A94B3003>---|
| Te audire no possum. |
| Musa sapientum fixa est in aure. |
|----------------------------------<steve@youngs.au.com>---|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (GNU/Linux)
Comment: The SXEmacs Project <http://www.sxemacs.org>
Comment: Eicq - The SXEmacs ICQ Client <http://www.eicq.org/>

iEYEARECAAYFAkTn5xwACgkQHSfbS6lLMAMllwCgrdVTtR9LjF t4oDnsppuKar09
ApYAmwZTKxUfAdTH8uOHX73vN7/IAOYI
=rOYU
-----END PGP SIGNATURE-----
  Réponse avec citation
Vieux 20/08/2006, 09h34   #12
JyotiC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

thanx a lot for all .
It seems there are lot of options to do one thing.

Steve Youngs wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> NotDashEscaped: You need GnuPG to verify this message
>
> * Stephane CHAZELAS <this.address@is.invalid> writes:
>
> > 2006-08-19, 22:21(+10), Steve Youngs:
> >>
> >> * Stephane CHAZELAS <this.address@is.invalid> writes:
> >> > find . \! -name . -prune -type d -print
> >>
> >> find . -type d -maxdepth 1
> >>
> >> Seems a little easier.

>
> > But is not Unix. Only in GNU and some BSDs.

>
> OK. I've been spoiled too much by GNU/find. :-) However, I do think
> it is probably a safe bet that the OP is using GNU/find.

I am kind of comfused as in how is using find a safe bet.
which is more useful and basic find or ls

>
>
> --
> |---<Steve Youngs>---------------<GnuPG KeyID: A94B3003>---|
> | Te audire no possum. |
> | Musa sapientum fixa est in aure. |
> |----------------------------------<steve@youngs.au.com>---|
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.4 (GNU/Linux)
> Comment: The SXEmacs Project <http://www.sxemacs.org>
> Comment: Eicq - The SXEmacs ICQ Client <http://www.eicq.org/>
>
> iEYEARECAAYFAkTn5xwACgkQHSfbS6lLMAMllwCgrdVTtR9LjF t4oDnsppuKar09
> ApYAmwZTKxUfAdTH8uOHX73vN7/IAOYI
> =rOYU
> -----END PGP SIGNATURE-----


  Réponse avec citation
Vieux 20/08/2006, 18h28   #13
secahtah@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: listing directories

Try using the find utility:

find . -type d -maxdepth 1

That shows all directories in current folder, only directories, only
one level of depth.

Example:

Hostname:~ user$ find . -type d -maxdepth 1
..
../.emacs.d
../.gimp-2.0
../.gimp-2.0-etc
../.MacOSX
../.mutt
../.ssh
../.subversion
../.Trash
../Desktop
../Documents
../Library
../Mail
../Movies
../Music
../Pictures
../Public
../Sites
Hostname:~ user$



JyotiC wrote:
> hi,
>
> i wanna write a shell script which will list all the directories in
> that folder,
> it should only output dir no other file.
> is there a command to do so
>
> thanx
> Jyoti


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h32.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17362 seconds with 21 queries