当前位置 博文首页 > 小小之食人魔:利用find命令进行批量操作

    小小之食人魔:利用find命令进行批量操作

    作者:[db:作者] 时间:2021-07-25 12:24

    前些天,我要把Linux上的几千个txt文档进行转码,需要用到iconv命令,可是我总不能 一个一个的去敲。

    文档转码命令: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 {} \;

    cs
    下一篇:没有了