如果你有大批的文件需要重命名,但有那么一点规律可循,那你可以简单的用shell来处理
下面举个例子,假设我有 xx-abc.txt 的文件,都要去掉前面的xx-

[root@aslibra www.aslibra.com]# ll
total 0
[root@aslibra www.aslibra.com]# touch a-b.txt
[root@aslibra www.aslibra.com]# touch a-c.txt
[root@aslibra www.aslibra.com]# ls
a-b.txt  a-c.txt
#说明:文件已经创建
[root@aslibra www.aslibra.com]# ls | awk -F '-' '{print "mv "$0" "$2}'
mv a-b.txt b.txt
mv a-c.txt c.txt
#说明:用awk整理好命令,用-作为分隔符,打印出命令即可
[root@aslibra www.aslibra.com]# ls | awk -F '-' '{print "mv "$0" "$2}'| /bin/bash
#说明:测试无误则可以用管道方式交给bash执行啦
[root@aslibra www.aslibra.com]# ll
total 0
-rw-r--r--  1 root root 0 Jul 12 12:57 b.txt
-rw-r--r--  1 root root 0 Jul 12 12:57 c.txt


完成了,很简单吧~
awk整理命令的编程可以处理更加复杂的任务,自己可以灵活处理


原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
Tags: , ,
发表评论
表情
emotemotemotemotemotemotemotemotemotemotemotemotemot
emotemotemotemotemotemotemotemotemotemotemotemot
打开HTML 打开UBB 打开表情 隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写
 

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐