Quantcast
Channel: How to zero pad numbers in file names in Bash? - Stack Overflow
Browsing latest articles
Browse All 11 View Live

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 Article



Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article


Answer 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 Article

How 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
Browsing latest articles
Browse All 11 View Live




Latest Images