zsh-users
 help / color / mirror / code / Atom feed
* ls -l *(/)...
@ 2015-06-22  3:17 Meino.Cramer
  2015-06-22  5:25 ` lists
  0 siblings, 1 reply; 9+ messages in thread
From: Meino.Cramer @ 2015-06-22  3:17 UTC (permalink / raw)
  To: zsh-users

Hi,

I have a directory, which is filled with files and one addtional level
of directoriew. In these directories again there are files.

Being in the directory which contains one level of directories in
which....bla bla:
Being there I want to list all files in the directories in the
current directory which their full but relative paths.

I tried

ls -l *(/)

which gaves me an outout layout comparable to what I get when
doing a ls - Rl...which is not what I want.

Then I tried

ls -ld *(/)/.

which results in:
zsh: bad pattern: *(/)/*


hmmmm....

Any other way to accomplish, what I want - with zsh?

Thanks a lot for any help in advance!

Best regards,
Meino



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ls -l *(/)...
  2015-06-22  3:17 ls -l *(/) Meino.Cramer
@ 2015-06-22  5:25 ` lists
       [not found]   ` <20150622163654.GB4560@solfire>
  0 siblings, 1 reply; 9+ messages in thread
From: lists @ 2015-06-22  5:25 UTC (permalink / raw)
  To: Meino.Cramer, zsh-users

> Then I tried
> 
> ls -ld *(/)/.

Note that you do not need the '(/)' in the middle, because
ls -l */* will not match non-directories in the top-directory (only
difference I see, that it'll also match symbolic links to directories).

So: If you do not have symlinks to dirs in the topdir, ls */* is what
you are looking for :)

- René


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ls -l *(/)...
       [not found]   ` <20150622163654.GB4560@solfire>
@ 2015-06-22 17:59     ` lists
  2015-06-22 18:30       ` Bart Schaefer
  2015-06-22 19:08       ` Marc Chantreux
  0 siblings, 2 replies; 9+ messages in thread
From: lists @ 2015-06-22 17:59 UTC (permalink / raw)
  To: Meino.Cramer; +Cc: zsh-users

> ...unfortunately the command does not output eactly what I want...
> 
> ls */*
> 
> gives 
> 
> directory:
> file1
> file2
> file3
> 
> and I want
> 
> directory/file1
> directory/file2
> directory/file3
> 
> ...sorry I didn't mentioned that...
> 
> Any way to acchieve this?

Well, here, the output is exactly like how you want it (do you have `ls`
being some alias?).

BUT: As you require your `ls`-Output to be exactly adhering to some
format, I'd argue that `ls` is not what you want in the first place.
Best guess is, all you need is the '*/*' itself which just represents
the list of files as you want them:
echo */*

Of course you can also iterate over them:
for f in */*; echo $(basename $f)

Also: Instead of using `ls` to get lists of files when globbing itself
does not work (or gets too complicated), I'd recommend using `find`.
Besides having lots of ways to express queries for files, it also allows
very easily to pass the results on farther down the pipe.

Best regards,
René


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ls -l *(/)...
  2015-06-22 17:59     ` lists
@ 2015-06-22 18:30       ` Bart Schaefer
  2015-06-22 21:28         ` Bernd Steinhauser
  2015-06-22 19:08       ` Marc Chantreux
  1 sibling, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2015-06-22 18:30 UTC (permalink / raw)
  To: zsh-users

On Jun 22,  7:59pm, lists@necoro.eu wrote:
} Subject: Re: ls -l *(/)...
}
} > ls */*
} > 
} > gives 
} > 
} > directory:
} > file1
} > file2
} > file3
} 
} Well, here, the output is exactly like how you want it (do you have `ls`
} being some alias?).

I suspect Meino actually has more than one level of directory under the
current one, despite his original description.  Or he's not executing
the "ls" at the level of the heirarchy that we think he is.

    print -c */*

might be what is wanted here.  Or possibly

    ls -ld */*

or maybe even

    ls -ld */*/*

The problem description isn't very clear.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ls -l *(/)...
  2015-06-22 17:59     ` lists
  2015-06-22 18:30       ` Bart Schaefer
@ 2015-06-22 19:08       ` Marc Chantreux
  2015-06-22 19:26         ` lists
  1 sibling, 1 reply; 9+ messages in thread
From: Marc Chantreux @ 2015-06-22 19:08 UTC (permalink / raw)
  To: lists; +Cc: Meino.Cramer, zsh-users

> Of course you can also iterate over them:
> for f in */*; echo $(basename $f) 

print -l */*:t 

regards 

-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ls -l *(/)...
  2015-06-22 19:08       ` Marc Chantreux
@ 2015-06-22 19:26         ` lists
  2015-06-22 20:31           ` Roman Neuhauser
  2015-06-23 11:30           ` Marc Chantreux
  0 siblings, 2 replies; 9+ messages in thread
From: lists @ 2015-06-22 19:26 UTC (permalink / raw)
  To: zsh-users

Am 22.06.2015 um 21:08 schrieb Marc Chantreux:
>> Of course you can also iterate over them:
>> for f in */*; echo $(basename $f) 
> 
> print -l */*:t 

Thanks, but I just intended the for-loop as a small one-line example :).
Because I thought that the original intention might have been something
along the lines of

for f in `ls */*`; ...

or

ls */* | ...

Also, while such short one-liners using different modificators and
qualifiers and what not are nice to show case the might of zsh, I often
find them confusing and actually like an explicit for-loop more (except
when the for-loop makes stuff more complicated). The reason is, that I
write longer zsh-scripts so seldom that I always forget what all those
magic letters are for. So I need either a lengthy comment or I always
have to read zsh manpages when I happen to stumble of the piece in
question again.

(Just for the record, though, :t is one of the very few things I
actually use :), though I'd probably do echo */*(:t))

Best,
René


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ls -l *(/)...
  2015-06-22 19:26         ` lists
@ 2015-06-22 20:31           ` Roman Neuhauser
  2015-06-23 11:30           ` Marc Chantreux
  1 sibling, 0 replies; 9+ messages in thread
From: Roman Neuhauser @ 2015-06-22 20:31 UTC (permalink / raw)
  To: lists; +Cc: zsh-users

# lists@necoro.eu / 2015-06-22 21:26:36 +0200:
> Am 22.06.2015 um 21:08 schrieb Marc Chantreux:
> >> Of course you can also iterate over them:
> >> for f in */*; echo $(basename $f) 
> > 
> > print -l */*:t 
> 
> Thanks, but I just intended the for-loop as a small one-line example :).
> Because I thought that the original intention might have been something
> along the lines of
> 
> for f in `ls */*`; ...

that's actually an antipattern.  first, the largely inconsequential
things: it forks an extra shell (and ls), and it's longer than

  for f in */*; ...

second, and this is the dealbreaker, pathnames with IFS characters in
them are going to break this code horribly.

% touch foo bar omg\ wtf
% for f in *; do print $f; done
bar
foo
omg wtf
% for f in `ls *`; do print $f; done 
bar
foo
omg
wtf

> I write longer zsh-scripts so seldom that I always forget what all
> those magic letters are for. So I need either a lengthy comment or I
> always have to read zsh manpages when I happen to stumble of the piece
> in question again.

the absolutee basics are quite easy to remember:

:t - tail
:h - head
:r - root
:a - absolute path
:A - absolute path, the grown-up version (uses realpath(3))

-- 
roman


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ls -l *(/)...
  2015-06-22 18:30       ` Bart Schaefer
@ 2015-06-22 21:28         ` Bernd Steinhauser
  0 siblings, 0 replies; 9+ messages in thread
From: Bernd Steinhauser @ 2015-06-22 21:28 UTC (permalink / raw)
  To: zsh-users

On 22/06/15 20:30, Bart Schaefer wrote:
> On Jun 22,  7:59pm, lists@necoro.eu wrote:
> } Subject: Re: ls -l *(/)...
> }
> } > ls */*
> } >
> } > gives
> } >
> } > directory:
> } > file1
> } > file2
> } > file3
> }
> } Well, here, the output is exactly like how you want it (do you have `ls`
> } being some alias?).
>
> I suspect Meino actually has more than one level of directory under the
> current one, despite his original description.  Or he's not executing
> the "ls" at the level of the heirarchy that we think he is.
>
>      print -c */*
I'd go for
     ls **/*(.)

but you're right, it's not clear what he really wants.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ls -l *(/)...
  2015-06-22 19:26         ` lists
  2015-06-22 20:31           ` Roman Neuhauser
@ 2015-06-23 11:30           ` Marc Chantreux
  1 sibling, 0 replies; 9+ messages in thread
From: Marc Chantreux @ 2015-06-23 11:30 UTC (permalink / raw)
  To: lists; +Cc: zsh-users

On Mon, Jun 22, 2015 at 09:26:36PM +0200, lists@necoro.eu wrote:
> Also, while such short one-liners using different modificators and
> qualifiers and what not are nice to show case the might of zsh, I often
> find them confusing and actually like an explicit for-loop more  

understandable. 

imho... i see all computer langages as langages (in a natural sense):

* it's ok to speak the baby version of it 
* you'll learn (and forget) all your live
* having a dictionnary (or a man page) is nice 
* learning new words by reading other authors is nice 

so why not using the power of zsh in zsh-users? 


cheers


-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-06-23 11:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-22  3:17 ls -l *(/) Meino.Cramer
2015-06-22  5:25 ` lists
     [not found]   ` <20150622163654.GB4560@solfire>
2015-06-22 17:59     ` lists
2015-06-22 18:30       ` Bart Schaefer
2015-06-22 21:28         ` Bernd Steinhauser
2015-06-22 19:08       ` Marc Chantreux
2015-06-22 19:26         ` lists
2015-06-22 20:31           ` Roman Neuhauser
2015-06-23 11:30           ` Marc Chantreux

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).