Skip to Content

2 ways to list hidden files in Linux

In Linux, there are two types of files: regular files and hidden files. Hidden files are those that start with a dot (“.”). By default, Linux does not show hidden files when you list the contents of a directory. In this blog post, we will discuss three ways to list hidden files in Linux.

what are hidden files in Linux

Hidden files are files that are not normally displayed. They are hidden from view for a variety of reasons, such as to protect the privacy of the user or to keep the contents of the file from being accidentally modified. The name of the hidden files usually starts with a period(.).

An example of a hidden file in Linux is the .bash_history file. This is a file that contains a list of all the commands that have been entered in the Bash shell. It’s hidden because it’s a system file and you don’t need to see it unless you’re troubleshooting a problem.

Why would I want to list hidden files in Linux?

There are a few reasons why you might want to list hidden files in Linux. For example, you may want to view or edit a configuration file that is normally hidden. Or, you may be trying to troubleshoot an issue on your system and need to view log files that are hidden.

Another reason you might want to list hidden files in Linux is to protect the privacy of the user. Some hidden files may contain sensitive information that the user doesn’t want others to see.

For example, the .bash_history file mentioned earlier contains a list of all the commands that have been entered in the Bash shell. If someone else got access to this file, they would be able to see all of your command history.

List hidden files with ls command in Linux

The easiest way to list hidden files in Linux is to use the ls command with the -a option. This will show all files, including hidden ones.

$ ls -a

The output of this command will show all files in the current directory, including hidden ones.

If you want to list the contents of a specific directory, you can specify the path to that directory. For example, to list the contents of the /etc/ directory, you would use the following command:

$ ls -a /etc

The output of this command will show all files in the /etc/ directory, including hidden ones.

If you want to see more information about the files, such as file size and when they were last modified, you can use the -l option. For example:

$ ls -al /etc

This command will show a long listing of all files in the /etc/ directory, including hidden ones.

Procedure to list hidden files in Linux

  • Open the terminal.
  • Type ls -a and press Enter. This will show you all of the files in the current directory, including hidden files.
  • To view hidden files in a different directory, type ls -a /path/to/directory and press Enter.
  • To view only hidden files, type ls -ld .* and press Enter.

 

List hidden files with find command in Linux

Another way to list hidden files in Linux is to use the find command with -name and -type option. The find command can be used to search for files in a directory hierarchy. To list hidden files, use the -name option with a dot (“.*”) as the argument.

$ find . -type f -name “.*”

  • The -type option tells find which type of files you want to find. The most common type of file is a regular file, which is denoted by f . But there are other types of files, such as directories ( d ), symbolic links ( l ), and so on.
  • The -name option tells find to search through the directories for files that have the specific word in their name. In this case, we are using a dot (“.*”) as the pattern, which will match all files that start with a dot.

 

The output of this command will show all hidden files in the current directory and its subdirectories.

If you want to list the contents of a specific directory, you can specify the path to that directory. For example, to show all hidden files in the /etc/ directory and its subdirectories, you would use the following command:

$ find /etc -type f -name “.*”

These are two effective ways to list hidden files in Linux. Try them out and see which one works best for you. Thanks for reading!