[root@localhost zhouyu]# a="i am zhouyu"
[root@localhost zhouyu]# echo ${#a}
11
[root@localhost zhouyu]# echo $a | wc -m
12
[root@localhost zhouyu]# echo ${a:2}
am zhouyu
[root@localhost zhouyu]# echo ${a:2:3}
am
[root@localhost zhouyu]# echo $a | cut -b 3-4
am
[root@localhost zhouyu]# echo ${a#i am}
zhouyu
[root@localhost zhouyu]# echo ${a##i am}
zhouyu
[root@localhost zhouyu]# echo ${a%zhouyu}
i am
[root@localhost zhouyu]# echo ${a%%zhouyu}
i am
[root@localhost zhouyu]# echo ${a/i am/you are}
you are zhouyu
[root@localhost zhouyu]#
下面我们写一个脚本让1_zhouyu.txt 2_zhouyu.txt 3_zhouyu.txt这三个文件的名字改名为1.txt 2.txt 3.txt文件,怎么更改呢。可以参考我写的下面文件
有什么更好的方法还请大牛给点意见
vim /root/zhouyu/1.sh内容为
cd /root/zhouyu
for i in `ls *.zhouyu.txt`;
do
mv $i ${i/_zhouyu.txt/.txt}
done
这样就去执行就成功了
下面说一下专门用于更改文件名的命令rename,其用法如下:
rename 想改的部分 改成什么 改变的源文件,下面是例子
[root@localhost zhouyu]# ls
1.txt 2.txt 3.txt zhouyu.sh
[root@localhost zhouyu]# rename .txt .TXT /root/zhouyu/*
[root@localhost zhouyu]# ls
1.TXT 2.TXT 3.TXT zhouyu.sh
[root@localhost zhouyu]#