M
M
Michael2012-04-24 21:11:55
linux
Michael, 2012-04-24 21:11:55

How to rename folders using i+100 pattern?

There are many folders named 200, 201,202... You need to rename them to 300, 301,302 and so on. How can this be done with bash?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dair_Targ, 2012-04-24
@Dair_Targ

mkdir tmp/
mv {200..100500} tmp/
for i in {200..100500}; do mv tmp/$i ./$(expr $i + 100); done
rm tmp/

B
barker, 2012-04-24
@barker

I didn’t understand what bash has to do with it and why there are some loops for this, perl scripts in 10 (O_o) lines, etc., if there are 100500 one-line solutions with different standard external utilities. And in this case, you can generally rename it simply with the rename command:

rename 2 3 2??

V
Vyacheslav Golovanov, 2012-04-24
@SLY_G

If perl suits, then here is a program for renaming, the first digit in the name increases by one.
The first parameter is a directory, like
rename.pl /path/to/dir

#!/usr/bin/perl

$dir = $ARGV[0];
exit if ( !-d $dir );
opendir DIR, $dir;
for $old ( grep -d "$dir/$_", readdir DIR ) {
  next unless ( $old =~ /^(\d)(\d+)/ );
  $new = ( $1 + 1 )."$2";
  rename( "$dir/$old", "$dir/$new" );
}

V
VN, 2014-09-22
@kavabangaungava

Tell me, how to batch rename files so that the last character is not affected. For example, you need to rename filname[x] to new[x]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question