Skip to main content
Quick Tip

Show Hidden Files With ls Command in Linux

By default, the ls command does not show hidden files and directories. They are hidden from normal view. Here's how to show them.

Abhishek Prakash

Warp Terminal

The ls command in Linux is used for listing files and directories. It is one of the most popular Linux commands and has plenty of options to display listings.

By default, the ls command does not show hidden files and directories. They are hidden from normal view.

You can display hidden files along with other files using the -a option of the ls command:

ls -a

There is another way to show hidden files with the ls command. Not many Linux users know about it. You can use the option -A instead of -a.

ls -A

The only difference here is that you won't see the . and .. special directories with -A.

Let me show this with proper examples.

Show all hidden files

Here's what the ls command shows by default in my test directory.

abhishek@LHB:~/test$ ls
export.json         line.txt        sample.txt

Now, I use the -a option to include the hidden files in the display.

ls -a

And you can see that the display now includes ., .. and .some_config directories.

abhishek@LHB:~/test$ ls -a
.   export.json         line.txt        sample.txt  .some_config

In case you didn't know already, any file or directory with its name starting with a dot (.) is hidden from the normal view. They are called dot files.

You can combine it with other options like:

  • ls -la
  • ls -lat
  • ls -lart
Include hidden files in Linux with ls command
Include hidden files in Linux with ls command
📄
The . and .. are special directories in Linux. . means current directory and .. means its parent directory. They are present in all the directories.

Show hidden files but exclude . and ..

Don't like to see the omnipresent hidden directories . and ..? You can use the option -A.

ls -A

As you can notice, it shows the .same_config hidden file but not the . and .. directories.

Display hidden files with ls command

This -A too can be combined with other options.

  • ls -lA
  • ls -lAt
  • ls -lArt

Show only hidden files and nothing else

The above-discussed methods show hidden files along with the normal files. What if you want to display only the hidden files and nothing else?

While there is no specific option in the ls command for this purpose, you can combine a few commands with pipe to get the desired result.

There are various ways you can achieve that. One of them is:

ls -a | grep "^\."
Only display hidden files in Ubuntu

Conclusion

Here's a fun fact. In the early days of UNIX, a code change was made to hide the necessary but not of much use . and .. directories. The code change was simple. File name starting with . was hidden. While this was introduced to hide . and .., it introduced a bug that any file starting with a . becomes hidden. With time, this bug became an essential feature in UNIX and later in Linux.

I hope you like this quick little tip on displaying hidden files with ls command.

Abhishek Prakash