[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -ls0

From: James Youngman
Subject: Re: -ls0
Date: Fri, 30 Dec 2011 11:45:20 +0000

On Fri, Dec 30, 2011 at 12:35 AM, Karl Berry <address@hidden> wrote:
> James or anyone,
> I've been in the habit of using find -ls to record all files in a given
> hierarchy.  Of course, parsing the output of that becomes problematic
> when a file name contains a newline or other special characters.  So
> what I really want is -ls0, where the entries are delimited with nulls
> instead of newlines.

Why not just use \0 in the format specification?

~$ f="hello
~$ echo "$f" | od -c
0000000   h   e   l   l   o      \n   w   o   r   l   d  \n
~$ touch "$f"
~$ find . -maxdepth 1 -name 'hello*' -printf '[%p]\0'
[./hello ?world]~$ find . -maxdepth 1 -name 'hello*' -printf '[%p]\0'|cat
world]~$ find . -maxdepth 1 -name 'hello*' -printf '[%p]\0'|od -c
0000000   [   .   /   h   e   l   l   o      \n   w   o   r   l   d   ]
0000020  \0
~$ rm "$f"

> In the case of symlinks, I think the " -> " suffices to separate the
> symlink name from the target name.  That is, I'm willing to accept the
> lossage if a filename contains that string.  Less likely than a newline,
> anyway, and anything involving nulls would greatly complicate the
> parsing of the output.  Oh, maybe it should be \n->\n, that would be
> even less probable.

Alternatively, emit the symlinks into a separate file with -fprintf.

> I thought I would be able to use -printf to get the equivalent, but this
> appears to be impossible.  Aside from formatting trivialities, I don't
> see a directive or option or other setting to print the exact filename
> the way that -print0 does.  Am I missing something obvious?  Is there a
> way for -printf to print the raw file name?  Or the escaped (as in -ls)
> filename, for that matter?

Unprintable/unusual characters are escaped only when the output is
going to a tty.  See the info node "Unusual Characters in File Names"
in the GNU find manual.

> Also, I don't see a way to get the " -> " in symlink entries (without
> running a separate find for symlinks only), but I guess it's ok for my
> purposes to just unconditionally use %l.

You could use \( -type l -fprintf symlinks "$format" \) -o \( -fprintf
nonsymlinks "$format" \)

> The closest I could get was this:
>  find -printf "%i %k %M %n %u %g %s %T+ %p\n->\n%l\0"
> BTW, if/when there is an equivalent way to do it using -printf, I think
> it would be good to state it in the manual (Node: Print File
> Information), as well as mentioning `ls -dils'.

This email is intended solely for the use of its addressee, sender,
and any readers of a mailing list archive in which it happens to
appear.   If you have received this email in error, please say or type
three times, "I believe in the utility of email disclaimers," and then
reply to the author correcting any spellings (and, optionally, any
incorrect spellings), accompanying these with humorous jests about the
author's parentage.   If you are not the addressee, you are
nevertheless permitted to both copy and forward this email since
without such permissions email systems are unable to transmit email to
anybody, intended recipient or not.  To those still reading by this
point, the author would like to apologise for being unable to maintain
a consistent level of humour throughout this disclaimer.  Contents may
settle during transit.  Do not feed the animals.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]