Skip to content

为了安全考虑,删除前需要判断文件是否是软链接,非软链接文件再执行删除命令,可以使用如下命令

bash
find /path/to/directory ! -type l -delete

也可以使用

bash
find /path/to/directory ! -type l -exec rm -rf {} +
  • /path/to/directory: 您要操作的目录的路径。
  • ! -type l: 查找不属于符号链接类型的文件和目录。 ! 代表 “非”。
  • -exec rm -rf {} +: 对找到的结果执行 rm -rf 命令。 {} 代表找到的文件或目录,+ 会将多个文件或目录传递给一个 rm 命令执行,提高效率。

Released under the MIT License.