How Can i Rename All Files in a Directory using For Loop?
Here 开发者_JAVA技巧is my snippet:
#!/bin/sh
for fname in *
do
if [! -d "$fname"]
then
WHAT CAN I DO
fi
done
All new named files has to have this format O.fname - as you see preceeded by O. Can you please help? I know i have to use mv somewhere.
Files are renamed using mv, so just do
mv "$fname" "O.$fname"
in the loop.
Just use the mv inside the loop. Also, in the if statement, there is a space between the [
and the !
for fname in *
do
if [ ! -d "$fname" ]
then
mv "$fname" "O.$fname"
fi
done
精彩评论