How to Find Hidden Files and Directories in Linux Using the Command Line

Uncovering the Invisible Files on Your System

In the Linux operating system, any file or directory that begins with a simple period (e.g., .bashrc or .config) is automatically classified as a “hidden” file. By default, these files are completely invisible when you browse through your folders using a graphical file manager or the standard command line.

This is not a security measure designed to keep hackers out; it is simply an organisational feature designed to keep your workspace clean. Most hidden files are configuration files, user preferences, or system logs that you rarely need to interact with on a daily basis. However, when you need to troubleshoot a software issue or customise your terminal environment, you must know how to reveal them.

Here is how to find and list hidden files and directories in Linux using the terminal.

Using the ls Command (The Quick Method)

The ls command is the standard way to list the contents of a directory. By default, it ignores anything starting with a dot. To force it to show absolutely everything, you simply add the -a (all) flag.

Open your terminal and type:

ls -a

This will output a simple list of all files, including the hidden ones. However, this basic list can be difficult to read. For a much more useful view, combine the -a flag with the -l (long format) flag:

ls -la

This provides a detailed vertical list showing every visible and hidden file, along with critical information such as file permissions, ownership, file size, and the date it was last modified.

Ignoring the Current and Parent Directories

When you use ls -a, you will always see two special hidden directories at the very top of the list: . (which represents the current directory) and .. (which represents the parent directory). If you find these annoying and want to see only the actual hidden files, use the capital -A (almost all) flag instead:

ls -lA

Filtering for Only Hidden Files

If you are looking at a directory that contains hundreds of normal files (like your Documents or Downloads folder), using ls -la will still force you to scroll through a massive list to find the few hidden files mixed in.

To list only the hidden files and ignore the normal visible files, you can use a wildcard pattern to tell the terminal to only show items that start with a dot:

ls -ld .*

(Note: The -d flag is crucial here. Without it, the command will not only list the hidden directories, but it will also dump the entire contents of those directories onto your screen, creating a massive, unreadable wall of text).

Using the find Command (The Advanced Method)

The ls command is perfect for looking inside your current folder, but what if you need to search your entire hard drive for a specific hidden configuration file?

The find command allows you to recursively search through complex folder structures. To find every single hidden file and directory starting from your current location and digging down into all subdirectories, use this command:

find . -name ".*"

Let’s break down how this works:

  • find: The command itself.
  • .: Tells the command to start searching in the current directory (you can replace this with a specific path, like /var/log).
  • -name “.*”: Tells the command to only return results where the file name begins with a dot.

Finding Specific Hidden File Types

You can make the find command incredibly specific. For example, if you want to find only hidden directories (and ignore hidden files), you can add the -type d flag:

find . -type d -name ".*"

Conversely, if you only want to find hidden files, use the -type f flag:

find . -type f -name ".*"

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.