开发者

How Can i Rename All Files in a Directory using For Loop?

开发者 https://www.devze.com 2023-01-06 06:57 出处:网络
Here 开发者_JAVA技巧is my snippet: #!/bin/sh for fname in * do if [! -d \"$fname\"] then WHAT CAN I DO

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

精彩评论

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