for i in *;
do new=`echo "$i" | sed -e 's/^./\U&/'`;
mv "$i" "$new";
done;
Would be the entire code broken down to make it easily viewable, I'll explain below.
First we have to make sure we process every file, the following line means: "Do the following as long as you can find files"
for i in *;
Then we have to load the current filname (which is stored in variable $i), replace the first letter by a capitalized version and store the new name (in variable $new).
The following command basically means:
Make variable $new (do new=
)
Load $i and forward it ("$i" |
)
to a function that replaces the first letter by a capitalized one. (sed -e 's/^./\U&/'
;`)
The sed manual page can be found here. It's used to perform basic text transformations. What is basically does is use a regular expression (the 's/^./\U&/'
part) (a way of detecting a certain pattern in a text) to detect first-characters that are uncapitalized and replace it with a capitalized version.
do new=echo "$i" | sed -e 's/^./\U&/';
After we've gotten the new name, it's time to rename the file with it's new capitalized name, the following command does that.
It says: move (same as rename) the old file foo.bar to the new Foo.bar.
mv "$i" "$new";
So we now have one file renamed and it's time to move to the next. The following concludes the for function, telling it it is now time to move on and process the next file.
done;