[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: rename command
From: |
Sami Kerola |
Subject: |
Re: rename command |
Date: |
Sat, 2 Jul 2011 17:56:39 +0200 |
On Tue, Jun 28, 2011 at 23:37, James Youngman <address@hidden> wrote:
> If we're going to implement a "rename" command, can we make one that
> copes with internal newlines (IIRC "rename" does not) and doesn't
> force the user to assume path names are text[1]?
>
> [1] UNIX-like kernels mostly think path names are byte sequences
> terminated by '\0', possibly including one or more instances of '/'.
> In particular, filesystems routinely contain files with a multiplicity
> of character encodings.
Sounds reasonable. After hearing what you and others has said I made
couple modifications to the command.
o Support recursion.
o Support input from stdin, and have a switch for null terminated
names. That will allow find -print0 | rename combination to rock.
o Add upper & lower casing options, which needs to obey locale.
o Add --test option. If this option is really wanted I need assistance
how to make test work properly. The current copy.h flags does not
support test and I feel reluctant to add such. Secondly this is not
even that simple. With --sed one can do such wacky renames that
expressing how the situation will look like after a run might be very
difficult.
o Add --sed to do complicated name manipulations (only an idea).
Assuming this is desired should I simply copy all necessary code from
sed to be a coreutils/src/sed_functions.c? Perhaps sed style string
manipulations should be part of gnulib. Perhaps something other,
better and maintainer acceptable?
See bellow snapshot of a usage output after latest modifications. Same
can be found in rough and functionally broken patch attachment.
-- snip
$ ./rename --help
Usage: ./rename [OPTION]... EXPRESSION REPLACEMENT FILE...
or: ./rename [OPTION]... FILE...
or: ./rename [OPTION]...
Rename lots of files in directory.
--files0-from=FILE read rename entries from NUL-terminated file
-r, -R, --recursive rename in directories recursively
-D, --dereference-args dereference only symlinks that are listed on the
command line
-L, --dereference dereference all symbolic links
-x, --one-file-system skip directories on different file systems
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
-S, --suffix=SUFFIX override the usual backup suffix
-f, --force do not prompt before overwriting
-i, --interactive prompt before overwrite
-n, --no-clobber do not overwrite an existing file
If you specify more than one of -f, -i, -n, only the final one takes effect.
--sed=s/regexp/replacement/
use sed regular expression replace syntax FIXME
-u, --uppercase upper case the names FIXME
-l, --lowercase lower case the names FIXME
-t, --test show a dry-run print out FIXME
-v, --verbose explain what is being done
--help display this help and exit
--version output version information and exit
-- snip
p.s. I will away keyboard for next week so finalization of the command
needs to wait a bit. Good side is that a pause of a week will give
plenty of time to discuss about the utility.
--
Sami Kerola
http://www.iki.fi/kerolasa/
0001-rename-move-command-from-util-linux-to-coreutils-packa.txt
Description: Text document
- Re: rename command,
Sami Kerola <=