Press "Enter" to skip to content

Linux常见命令

查看某类文件的大小:
du -m 20140507155000* | awk '{sum += $1}; END{print sum}'
批量修改文件后缀
[root@iz2zecibr4bozfdvtbnvfkz test]# touch {1..10}.20160531
[root@iz2zecibr4bozfdvtbnvfkz test]# ll
total 0
-rw-r--r-- 1 root root 0 Apr 13 15:09 10.20160531
-rw-r--r-- 1 root root 0 Apr 13 15:09 1.20160531
-rw-r--r-- 1 root root 0 Apr 13 15:09 2.20160531
-rw-r--r-- 1 root root 0 Apr 13 15:09 3.20160531
-rw-r--r-- 1 root root 0 Apr 13 15:09 4.20160531
-rw-r--r-- 1 root root 0 Apr 13 15:09 5.20160531
-rw-r--r-- 1 root root 0 Apr 13 15:09 6.20160531
-rw-r--r-- 1 root root 0 Apr 13 15:09 7.20160531
-rw-r--r-- 1 root root 0 Apr 13 15:09 8.20160531
-rw-r--r-- 1 root root 0 Apr 13 15:09 9.20160531
[root@iz2zecibr4bozfdvtbnvfkz test]# find ./ -name "*.20160531" | awk -F "." '{print $2}' | xargs -i -t mv ./{}.20160531 ./{}.20160630
mv .//9.20160531 .//9.20160630
mv .//1.20160531 .//1.20160630
mv .//5.20160531 .//5.20160630
mv .//6.20160531 .//6.20160630
mv .//4.20160531 .//4.20160630
mv .//8.20160531 .//8.20160630
mv .//10.20160531 .//10.20160630
mv .//2.20160531 .//2.20160630
mv .//3.20160531 .//3.20160630
mv .//7.20160531 .//7.20160630
[root@iz2zecibr4bozfdvtbnvfkz test]# ll
total 0
-rw-r--r-- 1 root root 0 Apr 13 15:09 10.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 1.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 2.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 3.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 4.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 5.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 6.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 7.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 8.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 9.20160630
文件新增后缀
find . -type f |xargs -i mv {} {}.txt   ---新增后缀为.txt
文件去掉后缀
[root@iz2zecibr4bozfdvtbnvfkz test]# ll
total 0
-rw-r--r-- 1 root root 0 Apr 13 15:09 10.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 1.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 2.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 3.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 4.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 5.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 6.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 7.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 8.20160630
-rw-r--r-- 1 root root 0 Apr 13 15:09 9.20160630
[root@iz2zecibr4bozfdvtbnvfkz test]# find ./ -name "*.20160630" | awk -F "." '{print $2}' | xargs -i -t mv ./{}.20160630  ./{}
mv .//1.20160630 .//1 
mv .//2.20160630 .//2 
mv .//3.20160630 .//3 
mv .//4.20160630 .//4 
mv .//5.20160630 .//5 
mv .//6.20160630 .//6 
mv .//7.20160630 .//7 
mv .//8.20160630 .//8 
mv .//9.20160630 .//9 
mv .//10.20160630 .//10
[root@iz2zecibr4bozfdvtbnvfkz test]# ll
total 0
-rw-r--r-- 1 root root 0 Apr 13 15:09 10
-rw-r--r-- 1 root root 0 Apr 13 15:09 1
-rw-r--r-- 1 root root 0 Apr 13 15:09 2
-rw-r--r-- 1 root root 0 Apr 13 15:09 3
-rw-r--r-- 1 root root 0 Apr 13 15:09 4
-rw-r--r-- 1 root root 0 Apr 13 15:09 5
-rw-r--r-- 1 root root 0 Apr 13 15:09 6
-rw-r--r-- 1 root root 0 Apr 13 15:09 7
-rw-r--r-- 1 root root 0 Apr 13 15:09 8
-rw-r--r-- 1 root root 0 Apr 13 15:09 9

Be First to Comment

发表评论

电子邮件地址不会被公开。 必填项已用*标注