0% found this document useful (0 votes)
3 views2 pages

Rename Files Starting with 'c' in Shell

The document provides a shell script that renames files in the home directory that start with the letter 'c'. It generates a new name by appending '111' to the original filename while preserving the file extension. Two variations of the script are presented, both achieving the same renaming functionality.

Uploaded by

for11trade
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Rename Files Starting with 'c' in Shell

The document provides a shell script that renames files in the home directory that start with the letter 'c'. It generates a new name by appending '111' to the original filename while preserving the file extension. Two variations of the script are presented, both achieving the same renaming functionality.

Uploaded by

for11trade
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Script No .

Definition:
Write a shell script to get all files of home directory and rename them if their names
start with c.
Newname = oldname111
Script:
clear
for i in `ls c*`
do
name=`echo $i |cut -d '.' -f1`
echo $name
str="111"
ext=`echo $i | cut -d '.' -f2`
new=$name$str
echo new filename
echo $new.$ext
mv $i $new.$ext
done

OR
Newname = oldname111

OR
for file in c*
do
if [ -f "$file" ]
then
newname="${file}111"
mv "$file" "$new_name"
echo "Renamed: $file to $new_name"
fi
done

You might also like