千家信息网

linux、unix中的批量文件重命名

发表于:2024-10-01 作者:千家信息网编辑
千家信息网最后更新 2024年10月01日,我要把gzip压缩后的文件的后缀.gz去掉:方法一:[root@test mysql]#touch test1 test2 test3[root@test mysql]#gzip *[root@tes
千家信息网最后更新 2024年10月01日linux、unix中的批量文件重命名我要把gzip压缩后的文件的后缀.gz去掉:
方法一:
[root@test mysql]#touch test1 test2 test3
[root@test mysql]#gzip *
[root@test mysql]#ls
test1.gz test2.gz test3.gz
[root@test mysql]#ls -l *.gz|xargs rename .gz ""
[root@test mysql]# ls -l *.gz
ls: *.gz: 没有那个文件或目录
[root@test mysql]ls
test1 test2 test3
这个方法在HP-unix中会提示xargs的参数rename是无效的,怎么办呢,别急,请看下一个方法。
方法二:
[root@test mysql]#touch test1 test2 test3
[root@test mysql]#gzip *
[root@test mysql]#ls
test1.gz test2.gz test3.gz
[root@test mysql]#ls -l *.gz |awk '{oldname=$9;sub(/.gz$/,"");print oldname,$9 }'|xargs -n2 mv
[root@test mysql]#ls *.gz
ls: *.gz: 没有那个文件或目录
[root@test mysql]#ls
test1 test2 test3 注:这里传给xargs的参数-n2是关键,它指示xargs每次从标准输入中取出两个Field,传递给待执行的命 令作为参数。否则它会一直从标准输入中取,一直取到命令行刚好不超过LINE_MAX为止。 ok,第二种方法解决了在hp-unix中的批量文件重命名问题;
0