bugfindutils - Bugs: bug #15037, [Wishlist] find -ls isn't flexible...


bug #15037: [Wishlist] find -ls isn't flexible enough but can't be emulated via -printf

Submitter:  Lenny Foner <foner>
Submitted:  Tue 22 Nov 2005 08:51:17 PM UTC
Category:  find Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  jay
Originator Name:  Open/Closed:  Open
Release:  4.2.26 Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Wed 01 Jun 2011 10:43:07 AM UTC, comment #3: 

I guess this wishlist item is old enough now that perhaps the original use case has gone away.   Anyway, as I'm sure is obvious by now, this item hasn't been a high priority.  

Other folks with similar needs though might find something like "rsync --only-write-batch" to be useful.

James Youngman <jay>
Group administrator
Wed 23 Nov 2005 07:47:18 AM UTC, comment #2: 

Yikes, I hadn't even considering the symlink case, probably because the scripts I was using couldn't handle symlinks anyway and were ignoring them---hence the whole problem didn't come up.

Assuming that I haven't forgotten anything else, I see two ways to do this:

(a) create two new format directives, one of which prints timestamps exactly as -ls does (should be trivial, since you can just reuse the same code), and one which handles the symlink case (either your idea of expanding into " -> foo" or nothing, or possibly something that prints the entire pathname, e.g., it prints either "bar" or "bar -> foo", depending on whether or not bar is a symlink).

(b) start adding options to -ls, e.g., for numeric uid/gid, for octal instead of symbolic modes, etc.  This isn't as flexible as (a) but might be easier to use in the case that originally bit me, namely needing to get those numeric uid/gid's into -ls output.

I'm not exactly sure what behavior you're implying in your paragraph about %{foo}, so I'm not sure if that sounds reasonable to me.  A compromise in complexity might be to do what was done with printing bits and pieces of times and dates, namely two-character format directives; in that case, %p might be "pathname" and %pl might be "pathname or pathname pointing at symlink" (or perhaps %pl might be "null or  '-> foo'", so you'd write something like %p%pl in the format string).

As for printing times in the same format as -ls, maybe that could be yet another second-letter option to %T?  That's not terribly orthogonal to the others (each of which is a tiny little chunk of a complete timestamp), so maybe there's a better way of doing that.  I hope so.

Lenny Foner <foner>
Wed 23 Nov 2005 06:26:16 AM UTC, comment #1: 

Off the top of my head, the other thing that makes it difficult to emulate -ls with -printf is the fact that there is no way to make it indicate the target of a symbolic link:

~$ rm -f foo bar; ln -s foo bar; find bar -ls
165262 0 lrwxrwxrwx 1 jay jay 3 Nov 22 22:17 bar -> foo

So we'd need something that expands to " -> foo" if a file is a symbolic link, and to nothing otherwise.

We're running out of letters for format directives. I'm toying with the idea of supporting %{word} format directives, but the idea is vague as yet. Please phrase your new support request in terms of what you'd like the new directives to expand to, don't worry for the moment about what we'll call them.

The attraction of %{foo} is that maybe we could also consider %{foo%%.jpg} and %{bar:-baz}, not to mention '-exec% foo %{ugh} ;'. Of course, the countervailing argument is that this would be a 10% increase in the size of the code (to pluck a number from thin air) for the convenience of 1% of the users.

James Youngman <jay>
Group administrator
Tue 22 Nov 2005 08:51:17 PM UTC, original submission:  

I was trying to emulate find -ls but with owner/group written numerically; this is essential when trying to compare output across machines which map uid/gid differently.  I needed the output to be in as close to the original format of -ls as possible, because it was going into scripts that had regexps carefully crafted to expect this format.  It would be really, really nice if -ls had some sort of modifier that made it possible to get this information in numeric form, without having to hand-craft a format string; I note that such hand-crafting might even be impossible, since it's not clear to me how to get file-time outputs that are identical with -ls's behavior given the format directives available---%t adds day-of-week and seconds, while %T and various modifiers don't appear to make it possible to switch formats between month-day-hour and month-day-year depending on the age of the file as -ls and the ls program do.  To really do this transparently might require invoking find -twice-, using two different format strings and filtering based on the files' ages.  Yucko.  Yet it would obviously be a trivial change to the -ls logic, assuming some agreement over how to name the option that invokes it (if numeric uid/gid, how about mode? I fear an explosion of modifiers), or a new directive could be added for printf so that it's possible to exactly emulate -ls -or- to tweak certain fields as I had to do; I -think- that simply emulating the way -ls prints dates might be sufficient, as I believe that everything else it does can be emulated via other format directives, but I haven't exhaustively investigated this.

And if another -printf mode is added, the entire thing should be mentioned in the worked examples, so users know how to do this; presumably it would approximate the format string I used (but with better date output), which was roughly -printf "%i %k %M %n %U %G %s %Th %Td %TH:%TM %p\n"


Lenny Foner <foner>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by jay (Posted a comment)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2005-11-23 jay Assigned toNone jay
    2005-11-22 foner Carbon-Copy- Added foner

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code