Set relabeling documents

I have a directory site packed with photos:

image0001.png
image0002.png
image0003.png
...

And also I would certainly such as a one-liner to rename them to (claim).

0001.png
0002.png
0003.png
...

Just how do I do this?

0
2019-05-05 18:51:40
Source Share
Answers: 6

zmv

The zsh shell has an effective set rename command called zmv.

First you require to enable the zmv command as adheres to (this can enter into your ~/.zshrc).

autoload zmv

The standard syntax is zmv PATTERN REPLACEMENT. The pattern is a shell chunk expression. Components of the pattern can be bordered by parentheses. The substitute message can have $1, $2, etc to describe the Nth parenthesised team in the pattern. As an example :

zmv 'image(*.png)' '$1'

You can additionally ask zsh to instantly specify $1, $2, etc to match the wildcard personalities in the pattern :

zmv -w 'image*.png' '$1.png'
0
2019-05-08 12:10:11
Source

I such as Perl so :

perl -nlE '$old=$_; s/image//; qx(mv $old $_)'

You can additionally make use of the very same pattern for various other jobs like replicating the documents to an additional directory site :

perl -nlE '$old=$_; s(image)(/path/to/new/dir/); qx(mv $old $_)'
0
2019-05-08 12:05:06
Source

ls *png | while read - r f ; do f2 = "' resemble $f | sed - e's/ photo//''" ; mv $f $f2 ; done

0
2019-05-08 11:50:27
Source

On Debian and also by-products, Perl's rename functions in a similar way to sed similar to this :

  rename -v 's/image//' *.png
.

There's additionally the rename from util-linux that functions similar to this, rather :

  rename image '' *.png
.
0
2019-05-08 08:20:50
Source

I generally make use of the wonderful and also straightforward mmv (man page) energy for this usecase :

$ mmv "image*.png" "#1.png"
.

will certainly execute your job.

The #1 in the target pattern will certainly be replaced with whatever matches the wildcard in the resource pattern. This additionally benefits numerous wildcards and also can be made use of as an example to scuff of components of filenames. You can additionally conveniently do more difficult points like transforming lower instance to upper instance letters.

See to it to shield the patterns from the shell by pricing estimate.

0
2019-05-08 08:12:54
Source

If you are making use of Bash or various other POSIX - suitable shell :

for f in *.png; do
    mv -- "$f" "${f#image}"
done
.
0
2019-05-08 07:26:13
Source