This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours
Bug 153132 - find needs better directory-stripping abilities in -printf
find needs better directory-stripping abilities in -printf
Status: CLOSED WONTFIX
Product: Fedora
Classification: Fedora
Component: coreutils (Show other bugs)
3
All Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-04-01 14:30 EST by Brian "netdragon" Bober
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-04-18 09:53:48 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Brian "netdragon" Bober 2005-04-01 14:30:03 EST
find has a %f, which is the filename, and %h which is like basename, but it
would be nice if you could specify more control

For instance, for /home/user/foo.txt, I might want to show any of the following:
home/user/foo.txt
user/foo.txt
foo.txt

I might want to specify the number of leading parts to strip, or specify a
string to strip.

I suggest a new formatting flag %m.nb where m specifies the number of leading
parts to strip, and n specifies the number of end parts to strip

I also suggest a new formatting flag %B(regexp, regexp, ...) that says to remove
any occurence of regexp

I also suggest a new formatting flag %m.nr that prints the pathname relative to
current directory (like pwd), along with %R(regexp, regexp, ...)

%RR and %BB would be like %R and %B respectively except they would only keep the
specified regular expressions

For instance:
file is /home/user/foo.txt
%f is foo.txt
%h is /home/user
%1.b is home/user/foo.txt
%2.b is user/foo.txt
%2.0b is user/foo.txt
%.1b is /home/user
%.2b is /home
%0.2b is /home
%2.1b is user
%B(^/home) is /user/foo.txt
%B(^/home,txt$) is /user/foo
If current directory is /home:
%r is ./user/foo.txt
If current directory is /home/user:
%r is ./foo.txt
If current directory is /home/user/data/documents:
%r is ../../foo.txt
%1.r is ../foo.txt
%.1r is ../..
%R(^../) is ../.txt
%R(../) is foo.txt
%R(/foo) is ../../.txt
%RR(foo.txt) is foo.txt
%RR(..) is ....
%RR(/,..) is ../../
%RR(../) is ../../
Comment 1 Sitsofe Wheeler 2005-04-02 05:53:31 EST
Hmm I wonder whether you are not better off using something like cut to modify a
filename so extensively rather than forcing find to do it all...
Comment 2 Tim Waugh 2005-04-18 09:53:48 EDT
Indeed -- I don't think this is really find's job.  The new -execdir flag
(upstream), on the other hand, might remove the need to do some of the things
you suggest altogether.

Note You need to log in before you can comment on or make changes to this bug.