How to Show Hidden Files in Linux

Channel: Linux
Abstract: . .. account .bash_history .bash_logout .bash_profile .bashrc devops .DIR .mycat.png scripts .viminfo For listing hidden files in a long li

Like Windows and MAC support hidden file, Linux and Unix like operating systems allow users to hide files. In this tutorial, I will show you how to hide files and directories and show hidden files and directories in Linux.

If any file or directory name starts with a . prefix (for example .test) then that file or folder is hidden.

The most common command to list file and directories in Linux is ls command and we check how to use ls command to display show hidden files.

How to unzip zip files in Linux

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

How to unzip zip files in Linux How to show hidden files

When we use ls command without any options it will not display hidden files. In order to reveal hidden files, you have to use -a or -A option with ls command.

The difference between -a and -A option is that -a option displays hidden files and directories with current directory (.) and parent directory (..) where -A won't show it.

Below I have listed my home directory where .bash_history, .bash_logout, .bash_profile and .bashrc files are created as hidden by default in Linux. The .DIR and .mycat are my personal directory and file which are hidden.

$ ls -a
.  ..  account  .bash_history  .bash_logout  .bash_profile  .bashrc  devops  .DIR  .mycat.png  scripts  .viminfo


For listing hidden files in a long list use the following command:

$ ls -al
total 44
drwx------. 5 linoxide linoxide 4096 Feb 28 09:32 .
drwxr-xr-x. 3 root     root     4096 Feb  7 00:45 ..
drwxrwxr-x. 2 linoxide linoxide 4096 Feb  8 08:04 account
-rw-------. 1 linoxide linoxide  375 Feb 15 11:06 .bash_history
-rw-r--r--. 1 linoxide linoxide   18 May 11  2019 .bash_logout
-rw-r--r--. 1 linoxide linoxide  141 May 11  2019 .bash_profile
-rw-r--r--. 1 linoxide linoxide  312 May 11  2019 .bashrc
drwxrwxr-x. 2 linoxide linoxide 4096 Feb 28 09:32 devops
drwxrwxr-x. 2 linoxide linoxide 4096 Feb 28 09:31 .DIR
-rw-rw-r--. 1 linoxide linoxide    0 Feb 28 09:32 .mycat.png
-rw-rw-r--. 1 linoxide linoxide   33 Feb 20 03:21 scripts
-rw-------. 1 linoxide linoxide  961 Feb 20 03:21 .viminfo

Some users love to use ll command.

$ ll -a
total 44
drwx------. 5 linoxide linoxide 4096 Feb 28 09:32 .
drwxr-xr-x. 3 root     root     4096 Feb  7 00:45 ..
drwxrwxr-x. 2 linoxide linoxide 4096 Feb  8 08:04 account
-rw-------. 1 linoxide linoxide  375 Feb 15 11:06 .bash_history
-rw-r--r--. 1 linoxide linoxide   18 May 11  2019 .bash_logout
-rw-r--r--. 1 linoxide linoxide  141 May 11  2019 .bash_profile
-rw-r--r--. 1 linoxide linoxide  312 May 11  2019 .bashrc
drwxrwxr-x. 2 linoxide linoxide 4096 Feb 28 09:32 devops
drwxrwxr-x. 2 linoxide linoxide 4096 Feb 28 09:31 .DIR
-rw-rw-r--. 1 linoxide linoxide    0 Feb 28 09:32 .mycat.png
-rw-rw-r--. 1 linoxide linoxide   33 Feb 20 03:21 scripts
-rw-------. 1 linoxide linoxide  961 Feb 20 03:21 .viminfo

Let's check the sample output of ls with -A option as follows:

$ ls -A
account  .bash_history  .bash_logout  .bash_profile  .bashrc  devops  .DIR  .mycat.png  scripts  .viminfo

or

$ ll -A
total 36
drwxrwxr-x. 2 linoxide linoxide 4096 Feb  8 08:04 account
-rw-------. 1 linoxide linoxide  375 Feb 15 11:06 .bash_history
-rw-r--r--. 1 linoxide linoxide   18 May 11  2019 .bash_logout
-rw-r--r--. 1 linoxide linoxide  141 May 11  2019 .bash_profile
-rw-r--r--. 1 linoxide linoxide  312 May 11  2019 .bashrc
drwxrwxr-x. 2 linoxide linoxide 4096 Feb 28 09:32 devops
drwxrwxr-x. 2 linoxide linoxide 4096 Feb 28 09:31 .DIR
-rw-rw-r--. 1 linoxide linoxide    0 Feb 28 09:32 .mycat.png
-rw-rw-r--. 1 linoxide linoxide   33 Feb 20 03:21 scripts
-rw-------. 1 linoxide linoxide  961 Feb 20 03:21 .viminfo
How to create hidden files

Just like regular files, we can create hidden files using touch command,  vi or nano editors. The only difference is to create with dot (.) in front of file or directory name.

Create a single hidden file

$ touch .testfile.txt

or

$ vi .test.txt

Create multiple hidden files

$ touch .file1 .file2 .file3

Create a hidden directory

$ mkdir .hiddndir

Hide existing file

Let's check how to change a regular file to a hidden file. We can simply use mv command to rename the files.

Let suppose we have already created file 'info.txt' and directory 'nike' and we will hide this file and directory as below

$ ll
total 4
-rw-r--r--. 1 root root 0 May 3 19:11 info.txt
drwxr-xr-x. 2 root root 4096 May 3 19:11 nike
$ mv info.txt .info.txt
$ mv nike .nike
$ ll -A
total 12
-rw-r--r--. 1 root root 0 May 3 19:11 .info.txt
drwxr-xr-x. 2 root root 4096 May 3 19:11 .nike

To unhide files you can follow the reverse process.

Conclusion

Above listed command work from the terminal for any Linux distributions like Ubuntu, Debian, Redhat, and CentOS. From this tutorial, we learned very simple commands to show hidden files in Linux. If you have any questions or feedback, feel free to leave a comment.

Ref From: linoxide
Channels:

Related articles