Answer by danday74 for How to zero pad numbers in file names in Bash?
This answer is derived from Chris Conway's accepted answer but assumes your files have an extension (unlike Chris' answer). Just paste this (rather long) one liner into your command line.for f in...
View ArticleAnswer by Victoria Stuart for How to zero pad numbers in file names in Bash?
To left-pad numbers in filenames (here numeric file names with alphabetic extensions, e.g. 1.abc):$ ls -ltotal 0-rw-r--r-- 1 victoria victoria 0 Mar 28 17:24 010-rw-r--r-- 1 victoria victoria 0 Mar 28...
View ArticleAnswer by AntonAL for How to zero pad numbers in file names in Bash?
My solution replaces numbers, everywhere in a stringfor f in * ; do number=`echo $f | sed 's/[^0-9]*//g'` padded=`printf "%04d" $number` echo $f | sed "s/${number}/${padded}/";doneYou can easily try...
View ArticleAnswer by Pioz for How to zero pad numbers in file names in Bash?
The oneline command that I use is this:ls * | cat -n | while read i f; do mv "$f" `printf "PATTERN""$i"`; donePATTERN can be for example:rename with increment counter: %04d.${f#*.} (keep original file...
View ArticleAnswer by KARASZI István for How to zero pad numbers in file names in Bash?
It's not pure bash, but much easier with the Perl version of rename:rename 's/\d+/sprintf("%05d",$&)/e' foo*Where 's/\d+/sprintf("%05d",$&)/e' is the Perl replace regular expression.\d+ will...
View ArticleAnswer by Michael Baltaks for How to zero pad numbers in file names in Bash?
I had a more complex case where the file names had a postfix as well as a prefix. I also needed to perform a subtraction on the number from the filename.For example, I wanted foo56.png to become...
View ArticleAnswer by Fritz G. Mehner for How to zero pad numbers in file names in Bash?
Pure Bash, no external processes other than 'mv':for file in foo*; do newnumber='00000'${file#foo} # get number, pack with zeros newnumber=${newnumber:(-5)} # the last five characters mv $file...
View ArticleAnswer by Chris Conway for How to zero pad numbers in file names in Bash?
In case N is not a priori fixed:for f in foo[0-9]*; do mv "$f" "$(printf 'foo%05d'"${f#foo}")"done
View ArticleAnswer by amrox for How to zero pad numbers in file names in Bash?
Here's a quick solution that assumes a fixed length prefix (your "foo") and fixed length padding. If you need more flexibility, maybe this will at least be a helpful starting point.#!/bin/bash# some...
View ArticleAnswer by dF. for How to zero pad numbers in file names in Bash?
The following will do it:for ((i=1; i<=N; i++)) ; do mv foo$i `printf foo%05d $i` ; doneEDIT: changed to use ((i=1,...)), thanks mweerden!
View ArticleHow to zero pad numbers in file names in Bash?
What is the best way, using Bash, to rename files in the form:(foo1, foo2, ..., foo1300, ..., fooN)With zero-padded file names:(foo00001, foo00002, ..., foo01300, ..., fooN)
View Article
More Pages to Explore .....