开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜