|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
-----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----- |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
"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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
-----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----- |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
-----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----- |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
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----- |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
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 ../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 |
|
![]() |
| Outils de la discussion | |
|
|