简体   繁体   English

Bash脚本-隐藏目录中的所有文件

[英]Bash script - make all files in Directory hidden

I'm using the following script to make all files in a directory hidden by adding a dot "." 我正在使用以下脚本通过添加点“”来隐藏目录中的所有文件。 at the beginning. 一开始。

GLOBIGNORE=".:.."
for file in *; do
     mv -n "$file" ".$file";
done

How can I exclude the already hidden files? 如何排除已经隐藏的文件?

Thanks for your help! 谢谢你的帮助!

The wildcard already doesn't match any hidden files, unless you have separately enabled dotglob . 除非已单独启用dotglob ,否则通配符已不与任何隐藏文件匹配。

If you have configured dotglob to include hidden files, you can momentarily turn it off with 如果已将dotglob配置为包括隐藏文件,则可以使用以下命令暂时将其关闭

shopt -u dotglob

Using GLOBIGNORE enables dotglob so maybe the simplest fix is to take that out. 使用GLOBIGNORE可以启用dotglob因此最简单的解决方法是将其删除。 You could also change it to 您也可以将其更改为

GLOBIGNORE='.*'

but this is effectively the same as unsetting it. 但这实际上与取消设置相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM