renaming a number of files by increasing their trailing number by a constant using bash script [closed]
Clash 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.
bash rename filenames
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.
add a comment |Â
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.
bash rename filenames
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
add a comment |Â
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.
bash rename filenames
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.
bash rename filenames
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
add a comment |Â
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
add a comment |Â
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.
$file%.*
returns the prefix of filename before the period.`$((..)) is bash's math operation idiom.
$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.
@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
add a comment |Â
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.
$file%.*
returns the prefix of filename before the period.`$((..)) is bash's math operation idiom.
$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.
@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
add a comment |Â
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.
$file%.*
returns the prefix of filename before the period.`$((..)) is bash's math operation idiom.
$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.
@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
add a comment |Â
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.
$file%.*
returns the prefix of filename before the period.`$((..)) is bash's math operation idiom.
$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.
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.
$file%.*
returns the prefix of filename before the period.`$((..)) is bash's math operation idiom.
$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.
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
add a comment |Â
@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
add a comment |Â
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