Here is a bash script helps you to rename files *.c.gz to new files *.c.

Code snippet:

#! /bin/bash
cmd1=$(ls |grep c.gz)
cmd2=$(ls |grep c.gz |sed 's/\.gz//g')
array1=()
len1=0
for i in $cmd1; do
    array1[$len1]=$i
    len1=$(expr $len1 + 1)
done

array2=()
len2=0
for i in $cmd2; do
    array2[$len2]=$i
    len2=$(expr $len2 + 1)
done

for(( i=0;i<$len1;i++)); do
    echo ${array1[$i]}"==>"${array2[$i]}
    mv ${array1[$i]} ${array2[$i]}
done

Run it in the terminal.

weiyang@WeiMac > ~/code/test/dir > ls
1.c.gz 2.c    3.c.gz 4.c

weiyang@WeiMac > ~/code/test/dir > bash run.sh
1.c.gz==>1.c
3.c.gz==>3.c

weiyang@WeiMac > ~/code/test/dir > ls
1.c    2.c    3.c    4.c    run.sh
Categories: Shell

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X
0
Would love your thoughts, please comment.x
()
x