当前位置 博文首页 > 小小之食人魔:利用find命令进行批量操作
文档转码命令:iconv -f GBK -t UTF-8 file1 -o file2
将file1从GBK转为UTF-8,并输出为file2。
于是我发现了find命令的一个exec参数。
[root@iZrzyv77duj240Z ~]# ls /mnt/
test.txt
[root@iZrzyv77duj240Z ~]# find /mnt -type f -exec ls -l {} \;
-rw-r--r-- 1 root root 6691 Sep 27 14:20 /mnt/test.txt
在/mnt下搜索,类型为文件,{}表示find的搜索结果。
固定格式为:“find 路径 -exec 命令 {} \;”
意思是查找/mnt下的所有文件,并对每个文件执行ls -l命令。
所以我的操作命令是:
[root@iZrzyv77duj240Z ~]# find /txt/ -type f -exec iconv -f gbk -t utf8 {} -o {} \;