在 Linux 中,“隐藏文件/目录”通常是通过**在名称前加一个点(.)**来实现的。下面按常见场景说明:
touch .hiddenfile
mkdir .hiddendir
mv file.txt .file.txt
mv dir .dir
ls -a
或
ls -la
mv .file.txt file.txt
mv .dir dir
有时不想改文件名,只想在 ls 时不显示:
alias ls='ls --ignore="secret*"'
⚠️ 这只是视觉隐藏,不是真正隐藏。
如果是为了防止别人看到内容,应使用权限或加密:
chmod 600 .secret
chown user:user .secret
gpg -c secret.txt
生成 secret.txt.gpg,原文件可删除。
. 开头 = 隐藏. 和 .. 是系统自动存在的目录,不能删除如果你是想:
可以告诉我具体使用场景,我可以给你更合适的方案。