|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello all! Hope this is not a faq. My question seems easy, but the only solution I found is a bit complicate. To list folders only, I have had first the idea % ls | grep ^d which is not working here! I am on Macintosh OS 10.4.11 and my shell is tcsh. Also quoting did not : % ls | grep "^d" Why? Ok! Then I tried these following perl solutions, which is a bit complicate: % ls -s | perl -e 'while (<>) {print if (/^\s*0/)}' and this is working too: % ls -l | perl -e 'while (<>) {print if (/^\s*d/)}' is there a more elegant solution to this problem? happy Eastern to all marek |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2008-03-24, Marek <mstep@podiuminternational.org> wrote:
> > > Hello all! > > > > Hope this is not a faq. My question seems easy, but the only solution > I found is a bit complicate. To list folders only, I have had first > the idea > > % ls | grep ^d > > which is not working here! I am on Macintosh OS 10.4.11 and my shell > is tcsh. Also quoting did not : > > % ls | grep "^d" > > Why? Ok! Then I tried these following perl solutions, which is a bit > complicate: > > % ls -s | perl -e 'while (<>) {print if (/^\s*0/)}' > > and this is working too: > > % ls -l | perl -e 'while (<>) {print if (/^\s*d/)}' > > is there a more elegant solution to this problem? > In bash: $ ls -d */ or as I prefer: $ ls -1d */ -- Salve |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Salve Håkedal wrote: > On 2008-03-24, Marek <mstep@podiuminternational.org> wrote: >> >> I found is a bit complicate. To list folders only >> [...] >> is there a more elegant solution to this problem? >> > In bash: > $ ls -d */ > or as I prefer: > $ ls -1d */ or $ ls -1d .*/ */ -- Best regards | Monica Lewinsky's X-Boyfriend's Cyrus | Wife for President |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Cyrus Kriticos wrote:
> > Salve Håkedal wrote: >> On 2008-03-24, Marek <mstep@podiuminternational.org> wrote: >>> >>> I found is a bit complicate. To list folders only >>> [...] >>> is there a more elegant solution to this problem? >>> >> In bash: >> $ ls -d */ >> or as I prefer: >> $ ls -1d */ > > or > > $ ls -1d .*/ */ or $ find . -type d -maxdepth 1 -ls -- Best regards | Monica Lewinsky's X-Boyfriend's Cyrus | Wife for President |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Mar 24, 11:37 am, Salve Håkedal <ikkjespam.sa...@slogedalen.no>
wrote: > > In bash: > $ ls -d */ > or as I prefer: > $ ls -1d */ > > -- > Salve Wow! this was a quick answer :-) And it is working too in my tcsh! And now I realize, why my suggestion of % ls | grep ^d was not working! It needs the switch of -l of course! % ls -l | grep ^d Sorry for the noise! And thanks to Salve marek |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Cyrus Kriticos wrote:
> > Salve Håkedal wrote: >> On 2008-03-24, Marek <mstep@podiuminternational.org> wrote: >>> >>> I found is a bit complicate. To list folders only >>> [...] >>> is there a more elegant solution to this problem? >>> >> In bash: >> $ ls -d */ >> or as I prefer: >> $ ls -1d */ > > or > > $ ls -1d .*/ */ or with GNU find $ find . -type d -maxdepth 1 -ls -- Best regards | Monica Lewinsky's X-Boyfriend's Cyrus | Wife for President |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Marek <mstep@podiuminternational.org> writes:
> % ls | grep ^d Here's a couple of aliases alias lsd '/bin/ls -aF | grep /$ | xargs /bin/ls -Cd' alias ldir '/bin/ls -l|/bin/grep "^d"' alias dir 'set d = `ls -1F \!* |grep /`; if ($#d) echo "$d:gh";unset d' |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Marek wrote:
> > Hope this is not a faq. My question seems easy, but the only solution > I found is a bit complicate. To list folders only, I have had first > the idea > > % ls | grep ^d > > which is not working here! I am on Macintosh OS 10.4.11 and my shell > is tcsh. Also quoting did not : > > % ls | grep "^d" > > Why? Ok! Then I tried these following perl solutions, which is a bit > complicate: > > % ls -s | perl -e 'while (<>) {print if (/^\s*0/)}' > > and this is working too: > > % ls -l | perl -e 'while (<>) {print if (/^\s*d/)}' > > is there a more elegant solution to this problem? perl -le'-d&&print for<*>' John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
Marek <mstep@podiuminternational.org> writes:
> Hope this is not a faq. My question seems easy, but the only solution > I found is a bit complicate. To list folders only, I have had first > the idea > > % ls | grep ^d You have some good answers to your question already, but you might get an even better answer if you say what you want a list of folders for. I often find that a shell command is awkward not because of some deficiency in the UNIX environment, but because the user requirement is poorly understood. So what do you need this folder list for? Cheers, - Joel |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
2008-03-24, 05:37(-05), Salve Håkedal:
[...] > In bash: > $ ls -d */ should be ls -d -- */ > or as I prefer: > $ ls -1d */ It works in most shells, not only bash. But note that it lists directories and symlinks to directories, it also adds a / to the end of every file name. zsh has globbing qualifiers to select files of certain types or with certain attributes: ls -ld -- *(/) will select directories only. ls -ld -- *(-/) for directories or symlinks to directories. ls -ld -- *(D-/) also includes dot-dirs (hidden directories). ls -ld -- *(oND-/) to disable the sorting done by zsh (ls does the sorting already anyway) With find: find . ! -name . -prune ! -name '.*' -type d -print Or: find . ! -name . -prune ! -name '.*' -follow -type d -print (to include symlinks to directories) or: find . ! -name . -prune -follow -type d -print (to include hidden dirs). -- Stéphane |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
On Mar 24, 2:50 pm, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> > -- > Stéphane Merci Stéphane, très rafraîchissant tes suggestions :-) Pleins des choses à apprendre! -prune je connaissais pas encore avec "find". Thank you all, for your answers ... Have to read many man-pages again :-) Greetings from Munich marek |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
Maxwell Lol wrote:
> Marek <mstep@podiuminternational.org> writes: > >> % ls | grep ^d > > Here's a couple of aliases > > alias lsd '/bin/ls -aF | grep /$ | xargs /bin/ls -Cd' > alias ldir '/bin/ls -l|/bin/grep "^d"' > alias dir 'set d = `ls -1F \!* |grep /`; if ($#d) echo "$d:gh";unset d' "if" without "then" and "fi"? -- Best regards | Monica Lewinsky's X-Boyfriend's Cyrus | Wife for President |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
pk <pk@pk.invalid> writes:
> Cyrus Kriticos wrote: > > >> alias dir 'set d = `ls -1F \!* |grep /`; if ($#d) echo "$d:gh";unset d' > > > > "if" without "then" and "fi"? > > I think that's tcsh syntax. Which is what the OP mentioned.... |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
Maxwell Lol wrote: > pk <pk@pk.invalid> writes: > >> Cyrus Kriticos wrote: >> >>>> alias dir 'set d = `ls -1F \!* |grep /`; if ($#d) echo "$d:gh";unset d' >>> "if" without "then" and "fi"? >> I think that's tcsh syntax. > > Which is what the OP mentioned.... thanks for this hint -- Best regards | Monica Lewinsky's X-Boyfriend's Cyrus | Wife for President |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
Cyrus Kriticos wrote:
>> alias dir 'set d = `ls -1F \!* |grep /`; if ($#d) echo "$d:gh";unset d' > > "if" without "then" and "fi"? I think that's tcsh syntax. tcsh> if (10 == 10) echo "ok" ok -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome. |
|
![]() |
| Outils de la discussion | |
|
|