如何在Linux中显示隐藏文件
时间:2020-03-05 15:26:24 来源:igfitidea点击:
与Windows和Mac支持隐藏文件一样,Linux和Unix等操作系统允许用户隐藏文件。
在本教程中,将介绍如何隐藏文件和目录并在Linux中显示隐藏的文件和目录。
如果任何文件或者目录名称以.
前缀(例如.test
)开始,那么隐藏该文件或者文件夹。
列出Linux中的文件和目录的最常用命令是ls命令,我们检查如何使用ls命令显示显示隐藏文件。
如何显示隐藏文件
当我们使用LS命令而没有任何选项时,它将不会显示隐藏文件。
为了揭示隐藏文件,我们必须使用ls命令使用-a
或者-A
选项。
-a
和-A
选项之间的区别是-a
选项显示带有当前目录(。
)和父目录(..)的隐藏文件和目录,其中-A
不会显示它。
下面我列出了我的家庭目录,其中.bash_history
,.bash_logout
,.bash_profile
和.bashrc
文件在Linux中被创建为隐藏。
".dir"和".mycat"是我的个人目录和文件。
$ls -a . .. account .bash_history .bash_logout .bash_profile .bashrc devops .DIR .mycat.png scripts .viminfo
有关在长列表中列出隐藏文件,请使用以下命令:
$ls -al total 44 drwx------. 5 theitroad theitroad 4096 Nov 28 09:32 . drwxr-xr-x. 3 root root 4096 Nov 7 00:45 .. drwxrwxr-x. 2 theitroad theitroad 4096 Nov 8 08:04 account -rw-------. 1 theitroad theitroad 375 Nov 15 11:06 .bash_history -rw-r--r--. 1 theitroad theitroad 18 Jan 11 2019 .bash_logout -rw-r--r--. 1 theitroad theitroad 141 Jan 11 2019 .bash_profile -rw-r--r--. 1 theitroad theitroad 312 Jan 11 2019 .bashrc drwxrwxr-x. 2 theitroad theitroad 4096 Nov 28 09:32 devops drwxrwxr-x. 2 theitroad theitroad 4096 Nov 28 09:31 .DIR -rw-rw-r--. 1 theitroad theitroad 0 Nov 28 09:32 .mycat.png -rw-rw-r--. 1 theitroad theitroad 33 Nov 20 03:21 scripts -rw-------. 1 theitroad theitroad 961 Nov 20 03:21 .viminfo
有些用户喜欢使用ll
命令。
$ll -a total 44 drwx------. 5 theitroad theitroad 4096 Nov 28 09:32 . drwxr-xr-x. 3 root root 4096 Nov 7 00:45 .. drwxrwxr-x. 2 theitroad theitroad 4096 Nov 8 08:04 account -rw-------. 1 theitroad theitroad 375 Nov 15 11:06 .bash_history -rw-r--r--. 1 theitroad theitroad 18 Jan 11 2019 .bash_logout -rw-r--r--. 1 theitroad theitroad 141 Jan 11 2019 .bash_profile -rw-r--r--. 1 theitroad theitroad 312 Jan 11 2019 .bashrc drwxrwxr-x. 2 theitroad theitroad 4096 Nov 28 09:32 devops drwxrwxr-x. 2 theitroad theitroad 4096 Nov 28 09:31 .DIR -rw-rw-r--. 1 theitroad theitroad 0 Nov 28 09:32 .mycat.png -rw-rw-r--. 1 theitroad theitroad 33 Nov 20 03:21 scripts -rw-------. 1 theitroad theitroad 961 Nov 20 03:21 .viminfo
让我们查看LS的输出示例,如下所示:
$ls -A account .bash_history .bash_logout .bash_profile .bashrc devops .DIR .mycat.png scripts .viminfo
或者
$ll -A total 36 drwxrwxr-x. 2 theitroad theitroad 4096 Nov 8 08:04 account -rw-------. 1 theitroad theitroad 375 Nov 15 11:06 .bash_history -rw-r--r--. 1 theitroad theitroad 18 Jan 11 2019 .bash_logout -rw-r--r--. 1 theitroad theitroad 141 Jan 11 2019 .bash_profile -rw-r--r--. 1 theitroad theitroad 312 Jan 11 2019 .bashrc drwxrwxr-x. 2 theitroad theitroad 4096 Nov 28 09:32 devops drwxrwxr-x. 2 theitroad theitroad 4096 Nov 28 09:31 .DIR -rw-rw-r--. 1 theitroad theitroad 0 Nov 28 09:32 .mycat.png -rw-rw-r--. 1 theitroad theitroad 33 Nov 20 03:21 scripts -rw-------. 1 theitroad theitroad 961 Nov 20 03:21 .viminfo
如何创建隐藏文件
就像常规文件一样,我们可以使用触摸命令,vi或者nano编辑器创建隐藏文件。
唯一的区别是在文件或者目录名称中使用点(.
)创建。
创建一个隐藏文件
$touch .testfile.txt or $vi .test.txt
创建多个隐藏文件
$touch .file1 .file2 .file3
创建一个隐藏目录
$mkdir .hiddndir
隐藏现有文件
让我们检查如何将常规文件更改为隐藏文件。
我们可以简单地使用mv命令重命名文件。
假设我们已经创建了文件'info.txt'和目录'nike',我们将隐藏此文件和目录如下
$ll total 4 -rw-r--r--. 1 root root 0 Jan 3 19:11 info.txt drwxr-xr-x. 2 root root 4096 Jan 3 19:11 nike
$mv info.txt .info.txt $mv nike .nike
$ll -A total 12 -rw-r--r--. 1 root root 0 Jan 3 19:11 .info.txt drwxr-xr-x. 2 root root 4096 Jan 3 19:11 .nike
为了取消隐藏文件,我们可以遵循反向操作。