Which command is used to list out all the hidden files along with other files in Unix?

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

1. Introduction

In this article, we’ll take a look at hidden files and directories in Linux, including their purpose and some common misconceptions.

We’ll also see how we can use simple flags to show hidden files and directories on the command line and explore some special-purpose hidden files.

2. Purpose of Hidden Files

In some instances, we may want to hide specific files or directories inside another directory. For example:

  • User preferences
  • Operating system files
  • Project-specific files (e.g., Eclipse configuration in an Eclipse project)
  • Repository-specific files (e.g., Git configuration in a Git repository)

To hide a file, we prepend a dot to its name.

Thus, we can create a hidden file named .hidden.sh using touch:

$ touch .hidden.sh

We can also create a hidden directory by prepending a dot to the directory name.

For example, we can create a hidden directory named .preferences using mkdir:

$ mkdir .preferences

To differentiate between hidden and visible files, we also create a visible file using touch:

$ touch visible.sh

If we display the files in the current directory using the ls -l command, we only see visible.sh — we don’t see our hidden file or directory:

$ ls -l
-rw-rw-rw- 1 jalbano jalbano 0 Jan  4 09:53 visible.sh

Since we have hidden our .hidden.sh file and .preferences directory, ls only displays our visible.sh file by default.

A common misconception, though, is that hidden files can be used as a means of security. Obscurity is not security, so hidden files should not be used as a means of security. As we will see below, we can easily display hidden files and directories using ls and, therefore, hidden files provide no protection from unwanted eyes.

3. Display Hidden Files

To display hidden files or directories, we include the a flag in our ls command.

The a flag instructs the ls command to include all files — and not ignore files starting with a dot.

Therefore, we can display the hidden files and directories we created by executing ls -al:

$ ls -al
drwxrwxrwx 1 jalbano jalbano 512 Jan  4 09:53 .
drwxr-xr-x 1 jalbano jalbano 512 Jan  3 22:37 ..
-rw-rw-rw- 1 jalbano jalbano   0 Jan  3 22:37 .hidden.sh
drwxrwxrwx 1 jalbano jalbano 512 Jan  3 22:37 .preferences
-rw-rw-rw- 1 jalbano jalbano   0 Jan  4 09:53 visible.sh

Using this command, we can now see both the hidden and visible files in the current directory.

4. Special-Purpose Hidden Files

Besides .hidden.sh and .preferences, our ls -al command also lists the current directory (.) and the parent directory (..).

These two directories are included in all directories by default and act as references that allow us to navigate relative to our current directory.

For example, if we wish to navigate to the parent of the directory we are currently in, we can execute:

$ cd ..

To hide these two directories while displaying all other hidden files and directories, we use the A flag in our ls command.

This command displays almost all files and directories, including hidden ones, except for the current and parent directories.

If we execute ls -Al, we’ll see:

$ ls -Al
-rw-rw-rw- 1 jalbano jalbano   0 Jan  3 22:37 .hidden.sh
drwxrwxrwx 1 jalbano jalbano 512 Jan  3 22:37 .preferences
-rw-rw-rw- 1 jalbano jalbano   0 Jan  4 09:53 visible.sh

This allows us to view all of the files and directories we have created — ignoring the default hidden directories — thus removing clutter.

5. Conclusion

In this tutorial, we looked at the purpose of hidden files, how to create them, and how to view them.

We also explored some of the special-purpose hidden directories included in Linux by default.

As noted above, we should use hidden files as a mechanism for reducing clutter and not as a means of securing a file or directory.

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

The Linux operating system consists of hundreds of files and folders that are hidden by default. Such files are known as hidden files or dot files because they always begin with a dot (.). Let's explore how you can view these hidden files on your Linux system.

The concept of hidden files is simple yet very important in Linux. They are mainly used for storing configuration files or user settings. Usually, these files are used by your system services, scripts, or other programs. For example, the .bash_logout script is executed whenever you log out of your Bash sessions. Another great example is the .gitignore file used by Git to exclude certain files from being pushed to your remote repository.

Sometimes the concept of hidden files can be used to hide certain files from the prying eyes of mostly non-advanced users.

The ls command is a widely used Linux command. In its simplest form, the command lists files and folders within a directory. However, ls doesn't list hidden files by default.

To show hidden files you must use the -a option, which commands ls to list "all" files and folders (including hidden ones).

Navigate to your home directory with the cd command and do a listing of all files using ls.

ls -a

Output:

ls command showing hidden files and folders

As you can see, there are several files that start with a dot (.). If you just run the ls command without the -a option, the output will not include hidden files.

If you do not have any hidden files in your home directory, you can create one using the touch command as follows:

touch .sample_hidden_file.txt

You can also create hidden folders with the mkdir command. You just have to make sure you use the dot at the beginning of the folder name.

You can tell the ls command not to list a certain file or folder. For example, given that you are in your home folder, you can run the following command to not list the Desktop directory in the command output:

ls --hide=Desktop

In addition to ls, you can use the find command as an alternative way of listing hidden files and folders on Linux. The find command searches for files within a folder hierarchy.

To list or find all hidden files, you have to explicitly tell the find command to list all files whose names start with a dot (.).

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

Run the following command to find and list only hidden folders or directories:

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

You can also view hidden files from the GUI using your default file manager. GNOME's Files is the default file manager on Ubuntu Desktop. Previously, the Files program was known as Nautilus.

You can launch Files by pressing the Super key and then typing "Files" in the search input that appears. Click on the Files program and it will show files in the Home folder by default.

By default, your file manager doesn't display all hidden files. Click on the Menu icon located in the upper-right corner and select Show Hidden Files. Your hidden files and folders will now be visible.

viweing hidden files and folders on Linux

Alternatively, you can use the keyboard shortcut Ctrl + H to view hidden files on Linux as well.

Although you can't view hidden files and folders by default, you can still interact with them just like other normal files. In fact, at some point, you might have to make configuration changes in a hidden file.

Finding Files and Folders on a Linux System

Knowing how to list and view all files including hidden files and folders is beneficial if you're considering Linux as your daily driver. Dot files play an important role in the Linux operating system as they're usually used to store configuration settings for programs.

In addition to files, the find command can also efficiently locate directories on Linux. But there are a few flags and options that you'll have to learn to do so.

Which command is used to list out all the hidden files along with other files?

ls -a will list all files including hidden files (files with names beginning with a dot). ls -F gives a full listing, indicating what type files are by putting a slash after directories and a star after executable files (programs you can run).

How do you list the hidden files in Unix?

To show hidden files you must use the -a option, which commands ls to list "all" files and folders (including hidden ones). Navigate to your home directory with the cd command and do a listing of all files using ls. As you can see, there are several files that start with a dot (.).

What is the command to find hidden files?

View hidden files and folders in Windows.
Open File Explorer from the taskbar..
Select View > Options > Change folder and search options..
Select the View tab and, in Advanced settings, select Show hidden files, folders, and drives and OK..

How do I list hidden files in Linux?

To display only the hidden files and directories, the simplest approach is to show the hidden files with ls -a and then use grep to filter only the entries that start with a . (dot). ls -a | grep "^\."