Linux/UNIX:Bash查找和删除所有隐藏文件目录

时间:2020-01-09 10:37:23  来源:igfitidea点击:

如何找到UNIX或Linux下所有隐藏的文件和目录(以.字符开头)并使用bash或ksh shell删除它们?
使用以下命令列出/path/to/dest /目录中的所有隐藏文件

$ find /path/to/dest/ -iname ".*" -maxdepth 1 -type f

要列出所有隐藏目录,请使用以下命令:

$ find /path/to/dest/ -iname ".*" -maxdepth 1 -type d

要删除UNIX或Linux下的所有隐藏文件,请使用以下命令:

$ find /path/to/dest/ -iname ".*" -maxdepth 1 -type f -delete

或者

$ find /path/to/dest/ -iname ".*" -maxdepth 1 -type f -exec rm {} \;

要删除UNIX或Linux下的所有隐藏目录,请使用以下命令:

$ find /path/to/dest/ -iname ".*" -maxdepth 1 -type d -exec rm -rf {} \;

如果删除了-maxdepth 1,它将找到所有子目录并将其也删除。