zsh-users
 help / color / mirror / code / Atom feed
* "ls" output like find ... -print0 anyhow ???
@ 2014-01-25  5:54 meino.cramer
  2014-01-25 11:07 ` Han Pingtian
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: meino.cramer @ 2014-01-25  5:54 UTC (permalink / raw)
  To: zsh-users

Hi,

is there a way to temporary convince 'ls' to act that way, that I can
use '| xargs -0' with it?

Thank ypu very much in advance for any help!

Best regards,
mcc




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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-25  5:54 "ls" output like find ... -print0 anyhow ??? meino.cramer
@ 2014-01-25 11:07 ` Han Pingtian
  2014-01-25 11:51   ` Moritz Bunkus
  2014-01-25 12:11 ` nyuszika7h
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Han Pingtian @ 2014-01-25 11:07 UTC (permalink / raw)
  To: zsh-users

On Sat, Jan 25, 2014 at 06:54:11AM +0100, meino.cramer@gmx.de wrote:
> Hi,
> 
> is there a way to temporary convince 'ls' to act that way, that I can
> use '| xargs -0' with it?
> 
> Thank ypu very much in advance for any help!
> 
> Best regards,
> mcc
> 
You can use 'find' to list files which you want to list by 'ls' I think.

Something like this:

find . -maxdepth 1 -path './.*' -prune -o -printf "%P\0"
> 


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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-25 11:07 ` Han Pingtian
@ 2014-01-25 11:51   ` Moritz Bunkus
  0 siblings, 0 replies; 11+ messages in thread
From: Moritz Bunkus @ 2014-01-25 11:51 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

Hey,

another option is to let xargs separate on newlines instead of spaces with
its »--delimiter« option. That way you can still use ls:

[0 mosu@sweet-chili ~/tmp] ls | xargs -d '\n' ls -l
-rw-rw-r-- 1 mosu vj 0 25. Jan 12:50 Another file with spaces.txt
-rw-rw-r-- 1 mosu vj 0 25. Jan 12:50 Hello World.txt

Kind regards,
mosu
​

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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-25  5:54 "ls" output like find ... -print0 anyhow ??? meino.cramer
  2014-01-25 11:07 ` Han Pingtian
@ 2014-01-25 12:11 ` nyuszika7h
  2014-01-25 12:13 ` Atom Smasher
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: nyuszika7h @ 2014-01-25 12:11 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 71 bytes --]

Try this:

    \ls -b -1 | tr '\n' '\0' | tr '\\n' '\n'

--
nyuszika7h

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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-25  5:54 "ls" output like find ... -print0 anyhow ??? meino.cramer
  2014-01-25 11:07 ` Han Pingtian
  2014-01-25 12:11 ` nyuszika7h
@ 2014-01-25 12:13 ` Atom Smasher
  2014-01-25 18:26 ` Bart Schaefer
  2014-01-27  1:59 ` Phil Pennock
  4 siblings, 0 replies; 11+ messages in thread
From: Atom Smasher @ 2014-01-25 12:13 UTC (permalink / raw)
  To: meino.cramer; +Cc: zsh-users

On Sat, 25 Jan 2014, meino.cramer@gmx.de wrote:

> is there a way to temporary convince 'ls' to act that way, that I can 
> use '| xargs -0' with it?
================

here's how i do it...

ls /path | tr '\n' '\0'


-- 
         ...atom

  ________________________
  http://atom.smasher.org/
  762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
  -------------------------------------------------

 	"Think of the press as a great keyboard on which the
 	 government can play."
 		-- Joseph Goebbels, Nazi Propaganda Minister.


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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-25  5:54 "ls" output like find ... -print0 anyhow ??? meino.cramer
                   ` (2 preceding siblings ...)
  2014-01-25 12:13 ` Atom Smasher
@ 2014-01-25 18:26 ` Bart Schaefer
  2014-01-27  1:59 ` Phil Pennock
  4 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2014-01-25 18:26 UTC (permalink / raw)
  To: zsh-users

On Jan 25,  6:54am, meino.cramer@gmx.de wrote:
}
} is there a way to temporary convince 'ls' to act that way, that I can
} use '| xargs -0' with it?

My first reaction to this is to think you're probably asking the wrong
question.  If you need to use -print0 then you're anticipating that the
file names contain "dangerous" characters, but "ls" will already have
processed the file names, so now you're concerned with what the output
of "ls" looks like, which may have replaced some of those characters
with "?" ... sounds like a recipe for problems.

If using xargs -d $'\n' as Moritz suggested will not work, I suggest
you try using the -ls option of "find".  It can be combined with -print0
which may give you what you need.

    find foo ... -print0 -ls | xargs -0 ...


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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-25  5:54 "ls" output like find ... -print0 anyhow ??? meino.cramer
                   ` (3 preceding siblings ...)
  2014-01-25 18:26 ` Bart Schaefer
@ 2014-01-27  1:59 ` Phil Pennock
  2014-01-27  3:49   ` Mikael Magnusson
  2014-01-27  4:20   ` Bart Schaefer
  4 siblings, 2 replies; 11+ messages in thread
From: Phil Pennock @ 2014-01-27  1:59 UTC (permalink / raw)
  To: meino.cramer; +Cc: zsh-users

On 2014-01-25 at 06:54 +0100, meino.cramer@gmx.de wrote:
> is there a way to temporary convince 'ls' to act that way, that I can
> use '| xargs -0' with it?
> 
> Thank ypu very much in advance for any help!

I'd use the print builtin of zsh, so that there are no argv length
limitations, combined with zsh's very powerful glob operators.

  print -N **/*.c(mM-1) | xargs -0 ...

The `print -N` uses NUL characters between arguments, for compatibility
with `xargs -0`, and the example glob finds all .c files anywhere under
the current directory which were modified in the past month.

-Phil


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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-27  1:59 ` Phil Pennock
@ 2014-01-27  3:49   ` Mikael Magnusson
  2014-01-27  4:20   ` Bart Schaefer
  1 sibling, 0 replies; 11+ messages in thread
From: Mikael Magnusson @ 2014-01-27  3:49 UTC (permalink / raw)
  To: meino.cramer, Zsh Users

On 27 January 2014 02:59, Phil Pennock
<zsh-workers+phil.pennock@spodhuis.org> wrote:
> On 2014-01-25 at 06:54 +0100, meino.cramer@gmx.de wrote:
>> is there a way to temporary convince 'ls' to act that way, that I can
>> use '| xargs -0' with it?
>>
>> Thank ypu very much in advance for any help!
>
> I'd use the print builtin of zsh, so that there are no argv length
> limitations, combined with zsh's very powerful glob operators.
>
>   print -N **/*.c(mM-1) | xargs -0 ...
>
> The `print -N` uses NUL characters between arguments, for compatibility
> with `xargs -0`, and the example glob finds all .c files anywhere under
> the current directory which were modified in the past month.
>
> -Phil

If you use the print builtin, make sure to also use -r to not do
backslash expansions.

-- 
Mikael Magnusson


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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-27  1:59 ` Phil Pennock
  2014-01-27  3:49   ` Mikael Magnusson
@ 2014-01-27  4:20   ` Bart Schaefer
  2014-01-27  4:27     ` Kurtis Rader
  2014-01-27 10:10     ` Atom Smasher
  1 sibling, 2 replies; 11+ messages in thread
From: Bart Schaefer @ 2014-01-27  4:20 UTC (permalink / raw)
  To: zsh-users

On Jan 26,  8:59pm, Phil Pennock wrote:
}
} I'd use the print builtin of zsh, so that there are no argv length
} limitations, combined with zsh's very powerful glob operators.

Meino mentioned in private email that he has particular reasons for
using "ls" instead of "find".  If the options of "ls" are important
(rather than just the file names) and you don't need to worry too
much about CPU consumption:

  print -N -- **/*(.e:'reply=("$(ls -l "$REPLY")")':) | xargs -0 ...

That's going to run "ls -l" once for each plain file (.) below the
current directory, so it's a lot more process-intensive than a single
"ls -lR", and it may not sort in the order you expect, but it will
give you "ls" output with $'\0'-terminated lines.


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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-27  4:20   ` Bart Schaefer
@ 2014-01-27  4:27     ` Kurtis Rader
  2014-01-27 10:10     ` Atom Smasher
  1 sibling, 0 replies; 11+ messages in thread
From: Kurtis Rader @ 2014-01-27  4:27 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1069 bytes --]

I recognize that your example is artificial but it does not support
arbitrary "ls" options. It seems to me that ~meino is asking the wrong
question.


On Sun, Jan 26, 2014 at 8:20 PM, Bart Schaefer <schaefer@brasslantern.com>wrote:

> On Jan 26,  8:59pm, Phil Pennock wrote:
> }
> } I'd use the print builtin of zsh, so that there are no argv length
> } limitations, combined with zsh's very powerful glob operators.
>
> Meino mentioned in private email that he has particular reasons for
> using "ls" instead of "find".  If the options of "ls" are important
> (rather than just the file names) and you don't need to worry too
> much about CPU consumption:
>
>   print -N -- **/*(.e:'reply=("$(ls -l "$REPLY")")':) | xargs -0 ...
>
> That's going to run "ls -l" once for each plain file (.) below the
> current directory, so it's a lot more process-intensive than a single
> "ls -lR", and it may not sort in the order you expect, but it will
> give you "ls" output with $'\0'-terminated lines.
>



-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

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

* Re: "ls" output like find ... -print0 anyhow ???
  2014-01-27  4:20   ` Bart Schaefer
  2014-01-27  4:27     ` Kurtis Rader
@ 2014-01-27 10:10     ` Atom Smasher
  1 sibling, 0 replies; 11+ messages in thread
From: Atom Smasher @ 2014-01-27 10:10 UTC (permalink / raw)
  To: zsh-users

On Sun, 26 Jan 2014, Bart Schaefer wrote:

> Meino mentioned in private email that he has particular reasons for 
> using "ls" instead of "find".
=============

in that case, this won't work. but for the archives and anyone taking an 
interest in this thread, "zargs" would be worth looking into.


-- 
         ...atom

  ________________________
  http://atom.smasher.org/
  762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
  -------------------------------------------------

 	"Everyone has the right to freedom of opinion and expression;
 	 this right includes freedom to hold opinions without
 	 interference and to seek, receive and impart information and
 	 ideas through any media and regardless of frontiers."
 		-- Article 19, Universal Declaration of Human Rights,
 		United Nations


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

end of thread, other threads:[~2014-01-27 10:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-25  5:54 "ls" output like find ... -print0 anyhow ??? meino.cramer
2014-01-25 11:07 ` Han Pingtian
2014-01-25 11:51   ` Moritz Bunkus
2014-01-25 12:11 ` nyuszika7h
2014-01-25 12:13 ` Atom Smasher
2014-01-25 18:26 ` Bart Schaefer
2014-01-27  1:59 ` Phil Pennock
2014-01-27  3:49   ` Mikael Magnusson
2014-01-27  4:20   ` Bart Schaefer
2014-01-27  4:27     ` Kurtis Rader
2014-01-27 10:10     ` Atom Smasher

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).