renaming a number of files by increasing their trailing number by a constant using bash script [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have these files in a directory:



mmm.1
mmm.2
mmm.3
.
.
.
.
.


i want to rename them as:



mmm.31
mmm.32
mmm.33
.
.
.


Just adding the number '30' to the trailing number in each file name.







share|improve this question














closed as too broad by G-Man, Shadur, Satō Katsura, Timothy Martin, Archemar Mar 17 at 9:37


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    Please do some research (our site has a search function, and there are many good search engines on the web) and try to solve this yourself.   Then edit your question to show what you tried and explain where you’re stuck.
    – G-Man
    Mar 16 at 6:15














up vote
0
down vote

favorite












I have these files in a directory:



mmm.1
mmm.2
mmm.3
.
.
.
.
.


i want to rename them as:



mmm.31
mmm.32
mmm.33
.
.
.


Just adding the number '30' to the trailing number in each file name.







share|improve this question














closed as too broad by G-Man, Shadur, Satō Katsura, Timothy Martin, Archemar Mar 17 at 9:37


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    Please do some research (our site has a search function, and there are many good search engines on the web) and try to solve this yourself.   Then edit your question to show what you tried and explain where you’re stuck.
    – G-Man
    Mar 16 at 6:15












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have these files in a directory:



mmm.1
mmm.2
mmm.3
.
.
.
.
.


i want to rename them as:



mmm.31
mmm.32
mmm.33
.
.
.


Just adding the number '30' to the trailing number in each file name.







share|improve this question














I have these files in a directory:



mmm.1
mmm.2
mmm.3
.
.
.
.
.


i want to rename them as:



mmm.31
mmm.32
mmm.33
.
.
.


Just adding the number '30' to the trailing number in each file name.









share|improve this question













share|improve this question




share|improve this question








edited Mar 16 at 10:32









Jeff Schaller

31.2k846105




31.2k846105










asked Mar 16 at 6:08









9pp

31




31




closed as too broad by G-Man, Shadur, Satō Katsura, Timothy Martin, Archemar Mar 17 at 9:37


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as too broad by G-Man, Shadur, Satō Katsura, Timothy Martin, Archemar Mar 17 at 9:37


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Please do some research (our site has a search function, and there are many good search engines on the web) and try to solve this yourself.   Then edit your question to show what you tried and explain where you’re stuck.
    – G-Man
    Mar 16 at 6:15












  • 1




    Please do some research (our site has a search function, and there are many good search engines on the web) and try to solve this yourself.   Then edit your question to show what you tried and explain where you’re stuck.
    – G-Man
    Mar 16 at 6:15







1




1




Please do some research (our site has a search function, and there are many good search engines on the web) and try to solve this yourself.   Then edit your question to show what you tried and explain where you’re stuck.
– G-Man
Mar 16 at 6:15




Please do some research (our site has a search function, and there are many good search engines on the web) and try to solve this yourself.   Then edit your question to show what you tried and explain where you’re stuck.
– G-Man
Mar 16 at 6:15










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










MODIFIED: After you informed us that you are dealing with ~300 files, the answers need to be modified. In the edited answer below, replace the number 300 with the exact upper-bound number for the pre-existing files.



for file in mmm.300..1 ; do mv "$file" "$file%.*.$((30+$file#*.))" ; done


This answer is very efficient because it does everything within bash using bash native abilities, and doesn't need external programs or launching of sub-processes.



  1. $file%.* returns the prefix of filename before the period.


  2. `$((..)) is bash's math operation idiom.


  3. $file#*. returns the suffix of filename after the period. If you are concerned that you might have filenames with more than one embedded period, replace the # with ##.


See man bash for further details and many other very cool native features.






share|improve this answer






















  • @nikki: This answer now accounts for the overwrites.
    – user1404316
    Mar 16 at 7:02










  • Yes, it does. But there should be a dot after these: mv "$file" "$file%.*.
    – 9pp
    Mar 16 at 7:27










  • @9pp. quite right. corrected.
    – user1404316
    Mar 16 at 7:57

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










MODIFIED: After you informed us that you are dealing with ~300 files, the answers need to be modified. In the edited answer below, replace the number 300 with the exact upper-bound number for the pre-existing files.



for file in mmm.300..1 ; do mv "$file" "$file%.*.$((30+$file#*.))" ; done


This answer is very efficient because it does everything within bash using bash native abilities, and doesn't need external programs or launching of sub-processes.



  1. $file%.* returns the prefix of filename before the period.


  2. `$((..)) is bash's math operation idiom.


  3. $file#*. returns the suffix of filename after the period. If you are concerned that you might have filenames with more than one embedded period, replace the # with ##.


See man bash for further details and many other very cool native features.






share|improve this answer






















  • @nikki: This answer now accounts for the overwrites.
    – user1404316
    Mar 16 at 7:02










  • Yes, it does. But there should be a dot after these: mv "$file" "$file%.*.
    – 9pp
    Mar 16 at 7:27










  • @9pp. quite right. corrected.
    – user1404316
    Mar 16 at 7:57














up vote
1
down vote



accepted










MODIFIED: After you informed us that you are dealing with ~300 files, the answers need to be modified. In the edited answer below, replace the number 300 with the exact upper-bound number for the pre-existing files.



for file in mmm.300..1 ; do mv "$file" "$file%.*.$((30+$file#*.))" ; done


This answer is very efficient because it does everything within bash using bash native abilities, and doesn't need external programs or launching of sub-processes.



  1. $file%.* returns the prefix of filename before the period.


  2. `$((..)) is bash's math operation idiom.


  3. $file#*. returns the suffix of filename after the period. If you are concerned that you might have filenames with more than one embedded period, replace the # with ##.


See man bash for further details and many other very cool native features.






share|improve this answer






















  • @nikki: This answer now accounts for the overwrites.
    – user1404316
    Mar 16 at 7:02










  • Yes, it does. But there should be a dot after these: mv "$file" "$file%.*.
    – 9pp
    Mar 16 at 7:27










  • @9pp. quite right. corrected.
    – user1404316
    Mar 16 at 7:57












up vote
1
down vote



accepted







up vote
1
down vote



accepted






MODIFIED: After you informed us that you are dealing with ~300 files, the answers need to be modified. In the edited answer below, replace the number 300 with the exact upper-bound number for the pre-existing files.



for file in mmm.300..1 ; do mv "$file" "$file%.*.$((30+$file#*.))" ; done


This answer is very efficient because it does everything within bash using bash native abilities, and doesn't need external programs or launching of sub-processes.



  1. $file%.* returns the prefix of filename before the period.


  2. `$((..)) is bash's math operation idiom.


  3. $file#*. returns the suffix of filename after the period. If you are concerned that you might have filenames with more than one embedded period, replace the # with ##.


See man bash for further details and many other very cool native features.






share|improve this answer














MODIFIED: After you informed us that you are dealing with ~300 files, the answers need to be modified. In the edited answer below, replace the number 300 with the exact upper-bound number for the pre-existing files.



for file in mmm.300..1 ; do mv "$file" "$file%.*.$((30+$file#*.))" ; done


This answer is very efficient because it does everything within bash using bash native abilities, and doesn't need external programs or launching of sub-processes.



  1. $file%.* returns the prefix of filename before the period.


  2. `$((..)) is bash's math operation idiom.


  3. $file#*. returns the suffix of filename after the period. If you are concerned that you might have filenames with more than one embedded period, replace the # with ##.


See man bash for further details and many other very cool native features.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 16 at 7:57

























answered Mar 16 at 6:16









user1404316

2,314520




2,314520











  • @nikki: This answer now accounts for the overwrites.
    – user1404316
    Mar 16 at 7:02










  • Yes, it does. But there should be a dot after these: mv "$file" "$file%.*.
    – 9pp
    Mar 16 at 7:27










  • @9pp. quite right. corrected.
    – user1404316
    Mar 16 at 7:57
















  • @nikki: This answer now accounts for the overwrites.
    – user1404316
    Mar 16 at 7:02










  • Yes, it does. But there should be a dot after these: mv "$file" "$file%.*.
    – 9pp
    Mar 16 at 7:27










  • @9pp. quite right. corrected.
    – user1404316
    Mar 16 at 7:57















@nikki: This answer now accounts for the overwrites.
– user1404316
Mar 16 at 7:02




@nikki: This answer now accounts for the overwrites.
– user1404316
Mar 16 at 7:02












Yes, it does. But there should be a dot after these: mv "$file" "$file%.*.
– 9pp
Mar 16 at 7:27




Yes, it does. But there should be a dot after these: mv "$file" "$file%.*.
– 9pp
Mar 16 at 7:27












@9pp. quite right. corrected.
– user1404316
Mar 16 at 7:57




@9pp. quite right. corrected.
– user1404316
Mar 16 at 7:57


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay