Re: rename v. script

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

 



On 5/19/05, THUFIR HAWAT <hawat.thufir@xxxxxxxxx> wrote:
> given:
> 
> bash-3.00$ ls -al
> total 984
> drwxr-xr-x   2 thufir thufir  4096 May 16 02:18 .
> drwx------  15 thufir thufir  4096 May 16 02:18 ..
> -rw-r--r--   1 thufir thufir 12354 May 14 22:30 1151154
> -rw-r--r--   1 thufir thufir 12955 May 14 22:16 1199229
> -rw-r--r--   1 thufir thufir 13639 May 14 22:22 1238181
> -rw-r--r--   1 thufir thufir 13996 May 14 22:24 1268816
> -rw-r--r--   1 thufir thufir 12176 May 14 22:37 1276032
> ...
> 
> and then:
> 
> bash-3.00$ mv 1151154 1151154.html
> bash-3.00$ mv 1199229 1199229.html
> bash-3.00$ mv 1238181 1238181.html
> 
> each file can be changed.  however, there are many files and that is
> very tedious.  can the above three commands (or 50, or 100) be written
> with a single rename command?

Not with just one mv command, but almost as simple,

  for f in *[0-9] ; do mv $f $f.html ; done

If you have hundreds of files, or if there are any unusual filenames
(such as containing spaces or nonprintable characters), a more
robust but longer command is (on two lines here for readability),

  find . -type f -name '*[0-9]' -print0 | \
    xargs -0 --replace mv -- {} {}.html

The "0" in -print0 and -0 is a digit-zero, not a letter Oh.

Note, the *[0-9] pattern is there to match only those filenames that
end in a digit (as in your example), so it doesn't match any other
files.
-- 
Deron Meranda


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux