7.20 使用 Shell 删除文件的多种方法 ================================== |image0| 1. 当前目录下的文件 ------------------- 最经典的方法,删除当前目录下的所有类型的文件 .. code:: shell rm -f \* 用find命令查找普通文件并删除or用find命令的处理动作将其删除 .. code:: shell find . -type f -delete # 或者 find . -type f -exec rm -f {} \ 用于参数列表过长;要删除的文件太多 .. code:: shell find . -type f | xargs rm -f 删除全部普通文件 .. code:: shell rm-f `find . -type f` 用for循环语句删除当前目录下的所有类型的文件 .. code:: shell for delete in `ls -l`;do rm -f \* ;done 2. 指定目录下的文件 ------------------- 两种方法 1. 把上面的 ``.`` 全部改为指定的目录 2. 在上面的命令之前,都加上 ``cd ${dest_dir};`` ,并且命令后,加上 ``cd -`` .. |image0| image:: http://image.iswbm.com/20200602135014.png