小智 29
尝试这个:
find . ! -type d -exec rm '{}' \;
Run Code Online (Sandbox Code Playgroud)
这将删除当前工作目录下的每个文件,不包括目录。使用此命令要格外小心。
如果find您机器上的版本支持,您也可以使用
find . ! -type d -delete
Run Code Online (Sandbox Code Playgroud)
您可以使用该命令find来定位每个文件但保持目录结构:
$ find /some/dir -type f -exec rm {} +
Run Code Online (Sandbox Code Playgroud)
根据此 Unix 和 Linux 问答题为:gnu find and masking the {} for some shells - 哪个?,{}使用单个刻度 ( ')转义似乎不再需要现代 shell,例如 Bash。