Linux Commands

How to Find the Hidden Files from the Linux Command Line

Hidden files in any operating system work to store your important data and hide them so that a user can’t delete them quickly. Linux also contains hidden files to prevent essential data like other operating systems.

However, some users always look for ways to check the hidden files to make changes. Although we don’t recommend any Linux users to change the hidden files, if you want to find the hidden files, this guide is for you. Here, we will explain how to find the hidden files from the Linux command line.

How to Find the Hidden Files from the Linux Command Line

Let’s divide this section into multiple parts to explain everything about the simple commands to display the hidden files:

Ls Command

The ls is the most common command to list the folders and files within the directories. This command does not show the hidden files by default, so you must use the -a option.

ls -a

You can also add the grep with “^\” in the ls command to filter out all files that start with dot (.):

ls -a | grep "^\."

Use the following command to list the hidden files in a specific directory:

ls –a /<directory_path>

To get more verbose output via the list mode, run the following command:

ls -al

Use the following command to list the folders and files through the directory path:

ls -al /etc

Note: In all the previous commands, you can use the -A option instead of -a to show the hidden files without “.” and “..” files.

To view the exclusively hidden files, use the following command:

ls -d .[^.]*

You can also list the exclusively hidden files through the following command:

ls -al -d .[^.]*

Use the following command to display only the hidden files and directories in the listing format:

ls -dl .*

Use the following command to display just the hidden files without their respective directories:

ls -dl .* |grep -v ^d

You can also display the directories without “.” and “..” files.

ls -dl .!(|.)

Once you run the previous command, the terminal displays the files that have a dot (.) before their names. So, these are the hidden files which are also known as the dot files.

Bonus Tip: You can also find the hidden files inside a directory. For this, you have to use the “dir” command instead of the “ls” command similarly.

Find Command

Finding the hidden files and folders in all partitions using the ls command is tricky. Alternatively, you can also find the hidden files in Linux with the help of the “find” command. This command searches for files within a folder hierarchy.

To find and list all hidden files with the find command, you have to explicitly instruct the command to show all the files whose names begin with a dot (.).

find . -name ".*" -maxdepth 1 2> /dev/null

Moreover, run the following command to list only the hidden files and folders:

find . -name ".*" -maxdepth 1 -type d 2> /dev/null

You can also use the “find” command to display hidden files in a specific location.

find  /<directory_path>/ -type f  -name '.*'

Or you can use the following command:

find $<directory_name> -name ".*" -ls

Conclusion

As a Linux user, listing all the hidden files is simple but make sure that you do not make any changes. You use both GUI and CLI approaches to display the hidden files. However, we specifically explained the command line approaches to find the hidden files in Linux. You can use these commands with the given options to display the hidden files more specifically without getting many hidden and unhidden files.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.