How to rename multiple files in Bash Scripting? [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Suppose i want to rename 3 files in the same directory.
Example:
test1.gzip
test2.gzip
test3.gzip
Now want to rename all the above files to something like,
test1_20180518.gzip
test2_20180518.gzip
test3_20180518.gzip
Now how can get the result? Someone please help!!
Please tell me, how to do that in bash scripting?
bash shell-script shell scripting bash-functions
closed as unclear what you're asking by Jeff Schaller, Kusalananda, Isaac, G-Man, GAD3R May 29 at 8:58
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. 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.
 |Â
show 5 more comments
up vote
0
down vote
favorite
Suppose i want to rename 3 files in the same directory.
Example:
test1.gzip
test2.gzip
test3.gzip
Now want to rename all the above files to something like,
test1_20180518.gzip
test2_20180518.gzip
test3_20180518.gzip
Now how can get the result? Someone please help!!
Please tell me, how to do that in bash scripting?
bash shell-script shell scripting bash-functions
closed as unclear what you're asking by Jeff Schaller, Kusalananda, Isaac, G-Man, GAD3R May 29 at 8:58
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. 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.
4
What happened when you tried? What are the zip file names? You know you can only rename one file at a time?
â Jeff Schaller
May 28 at 16:22
2
In the title you say âÂÂgunzipâ but in the body you say âÂÂzipâ â what are they?
â Jeff Schaller
May 28 at 16:23
1
Also, gunzip is a verb; it expands the contents of a gzip file. Are you trying to do that, or rename, or what?
â Jeff Schaller
May 28 at 16:23
2
You might also want to read How do I ask a good question?
â glenn jackman
May 28 at 16:40
3
Search this site for "rename multiple files" and you'll find lots of similar questions.
â glenn jackman
May 28 at 16:46
 |Â
show 5 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Suppose i want to rename 3 files in the same directory.
Example:
test1.gzip
test2.gzip
test3.gzip
Now want to rename all the above files to something like,
test1_20180518.gzip
test2_20180518.gzip
test3_20180518.gzip
Now how can get the result? Someone please help!!
Please tell me, how to do that in bash scripting?
bash shell-script shell scripting bash-functions
Suppose i want to rename 3 files in the same directory.
Example:
test1.gzip
test2.gzip
test3.gzip
Now want to rename all the above files to something like,
test1_20180518.gzip
test2_20180518.gzip
test3_20180518.gzip
Now how can get the result? Someone please help!!
Please tell me, how to do that in bash scripting?
bash shell-script shell scripting bash-functions
edited May 28 at 18:05
asked May 28 at 16:15
Red Phoenix
13
13
closed as unclear what you're asking by Jeff Schaller, Kusalananda, Isaac, G-Man, GAD3R May 29 at 8:58
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. 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 unclear what you're asking by Jeff Schaller, Kusalananda, Isaac, G-Man, GAD3R May 29 at 8:58
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. 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.
4
What happened when you tried? What are the zip file names? You know you can only rename one file at a time?
â Jeff Schaller
May 28 at 16:22
2
In the title you say âÂÂgunzipâ but in the body you say âÂÂzipâ â what are they?
â Jeff Schaller
May 28 at 16:23
1
Also, gunzip is a verb; it expands the contents of a gzip file. Are you trying to do that, or rename, or what?
â Jeff Schaller
May 28 at 16:23
2
You might also want to read How do I ask a good question?
â glenn jackman
May 28 at 16:40
3
Search this site for "rename multiple files" and you'll find lots of similar questions.
â glenn jackman
May 28 at 16:46
 |Â
show 5 more comments
4
What happened when you tried? What are the zip file names? You know you can only rename one file at a time?
â Jeff Schaller
May 28 at 16:22
2
In the title you say âÂÂgunzipâ but in the body you say âÂÂzipâ â what are they?
â Jeff Schaller
May 28 at 16:23
1
Also, gunzip is a verb; it expands the contents of a gzip file. Are you trying to do that, or rename, or what?
â Jeff Schaller
May 28 at 16:23
2
You might also want to read How do I ask a good question?
â glenn jackman
May 28 at 16:40
3
Search this site for "rename multiple files" and you'll find lots of similar questions.
â glenn jackman
May 28 at 16:46
4
4
What happened when you tried? What are the zip file names? You know you can only rename one file at a time?
â Jeff Schaller
May 28 at 16:22
What happened when you tried? What are the zip file names? You know you can only rename one file at a time?
â Jeff Schaller
May 28 at 16:22
2
2
In the title you say âÂÂgunzipâ but in the body you say âÂÂzipâ â what are they?
â Jeff Schaller
May 28 at 16:23
In the title you say âÂÂgunzipâ but in the body you say âÂÂzipâ â what are they?
â Jeff Schaller
May 28 at 16:23
1
1
Also, gunzip is a verb; it expands the contents of a gzip file. Are you trying to do that, or rename, or what?
â Jeff Schaller
May 28 at 16:23
Also, gunzip is a verb; it expands the contents of a gzip file. Are you trying to do that, or rename, or what?
â Jeff Schaller
May 28 at 16:23
2
2
You might also want to read How do I ask a good question?
â glenn jackman
May 28 at 16:40
You might also want to read How do I ask a good question?
â glenn jackman
May 28 at 16:40
3
3
Search this site for "rename multiple files" and you'll find lots of similar questions.
â glenn jackman
May 28 at 16:46
Search this site for "rename multiple files" and you'll find lots of similar questions.
â glenn jackman
May 28 at 16:46
 |Â
show 5 more comments
2 Answers
2
active
oldest
votes
up vote
1
down vote
Check your "rename" version with rename -V
. If you see:
"
util-linux
" thenrename .gzip _$(date "+%Y%m%d").gzip *.gzip
"
File::Rename
" thenrename 'chomp(my $date = `date "+%Y%m%d"`); s/.gzip/_$date.gzip/' *.gzip
add a comment |Â
up vote
0
down vote
Posible solution (you need chose one in loop body):
#!/bin/bash
pattern="pattern"
i=0
for file in `find <your_path> -type f -name '*.zip'`
do
extension="$file##*."
filename="$file%.*"
# without extenstion
mv "$file" "$filename-$pattern.$extension"
# whole filename
mv "$file" "$pattern-$i"
i=$((i + 1))
done
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Check your "rename" version with rename -V
. If you see:
"
util-linux
" thenrename .gzip _$(date "+%Y%m%d").gzip *.gzip
"
File::Rename
" thenrename 'chomp(my $date = `date "+%Y%m%d"`); s/.gzip/_$date.gzip/' *.gzip
add a comment |Â
up vote
1
down vote
Check your "rename" version with rename -V
. If you see:
"
util-linux
" thenrename .gzip _$(date "+%Y%m%d").gzip *.gzip
"
File::Rename
" thenrename 'chomp(my $date = `date "+%Y%m%d"`); s/.gzip/_$date.gzip/' *.gzip
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Check your "rename" version with rename -V
. If you see:
"
util-linux
" thenrename .gzip _$(date "+%Y%m%d").gzip *.gzip
"
File::Rename
" thenrename 'chomp(my $date = `date "+%Y%m%d"`); s/.gzip/_$date.gzip/' *.gzip
Check your "rename" version with rename -V
. If you see:
"
util-linux
" thenrename .gzip _$(date "+%Y%m%d").gzip *.gzip
"
File::Rename
" thenrename 'chomp(my $date = `date "+%Y%m%d"`); s/.gzip/_$date.gzip/' *.gzip
answered May 28 at 16:54
glenn jackman
45.7k265100
45.7k265100
add a comment |Â
add a comment |Â
up vote
0
down vote
Posible solution (you need chose one in loop body):
#!/bin/bash
pattern="pattern"
i=0
for file in `find <your_path> -type f -name '*.zip'`
do
extension="$file##*."
filename="$file%.*"
# without extenstion
mv "$file" "$filename-$pattern.$extension"
# whole filename
mv "$file" "$pattern-$i"
i=$((i + 1))
done
add a comment |Â
up vote
0
down vote
Posible solution (you need chose one in loop body):
#!/bin/bash
pattern="pattern"
i=0
for file in `find <your_path> -type f -name '*.zip'`
do
extension="$file##*."
filename="$file%.*"
# without extenstion
mv "$file" "$filename-$pattern.$extension"
# whole filename
mv "$file" "$pattern-$i"
i=$((i + 1))
done
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Posible solution (you need chose one in loop body):
#!/bin/bash
pattern="pattern"
i=0
for file in `find <your_path> -type f -name '*.zip'`
do
extension="$file##*."
filename="$file%.*"
# without extenstion
mv "$file" "$filename-$pattern.$extension"
# whole filename
mv "$file" "$pattern-$i"
i=$((i + 1))
done
Posible solution (you need chose one in loop body):
#!/bin/bash
pattern="pattern"
i=0
for file in `find <your_path> -type f -name '*.zip'`
do
extension="$file##*."
filename="$file%.*"
# without extenstion
mv "$file" "$filename-$pattern.$extension"
# whole filename
mv "$file" "$pattern-$i"
i=$((i + 1))
done
answered May 28 at 16:56
Yurij Goncharuk
2,2582521
2,2582521
add a comment |Â
add a comment |Â
4
What happened when you tried? What are the zip file names? You know you can only rename one file at a time?
â Jeff Schaller
May 28 at 16:22
2
In the title you say âÂÂgunzipâ but in the body you say âÂÂzipâ â what are they?
â Jeff Schaller
May 28 at 16:23
1
Also, gunzip is a verb; it expands the contents of a gzip file. Are you trying to do that, or rename, or what?
â Jeff Schaller
May 28 at 16:23
2
You might also want to read How do I ask a good question?
â glenn jackman
May 28 at 16:40
3
Search this site for "rename multiple files" and you'll find lots of similar questions.
â glenn jackman
May 28 at 16:46