How to view hidden files and folders on Linux

The Linux operating system includes hundreds of files and folders that are hidden by default. Such files are called hidden files or dot files because they always start with a dot (.).

Let's explore how you can view these hidden files on your Linux system.

Why are there hidden files?

The concept of hidden files is simple but very important in Linux. Hidden files are mainly used to store configuration files or user settings. Typically, system services, scripts, or other programs use these files to store and read configurations.

For example, the .bash_logout script executes whenever you log out of your Bash session. Another great example is the .gitignore file , which is used by Git to exclude certain files from being pushed to your remote repository.

You can also use the concept of hidden files to hide certain files from the prying eyes of most non-expert users. A good example is the ~/.ssh directory or directory used to store SSH keys and configuration files.

View hidden files with ls . command

The ls command is a widely used Linux command. In its simplest form, the command lists the files and folders in a directory. However, ls does not list hidden files by default.

To show hidden files, you must use the -a option. This requires the ls command to list "all" files and directories including hidden files and directories, i.e. files that begin with a dot (.).

Navigate to your home directory with the cd command and check for hidden files using ls as follows:

 

ls -a

Output:

How to view hidden files and folders on Linux Picture 1How to view hidden files and folders on Linux Picture 1

As you can see, there are some files that start with a dot. If you just run the ls command without the -a option, the output will ignore hidden files.

If you don't have any hidden files in your home directory, you can create one with the touch command as follows:

touch .sample_hidden_file.txt

You can also create hidden directories with the mkdir command. You just need to make sure you use a period at the beginning of the folder name. For example, to create a hidden folder named secret in your home directory, run the command:

mkdir ~/.secrets

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

ls --hide=Desktop

Find hidden files on Linux with the find . command

In addition to ls, you can use the find command as another way to list or check for hidden files and directories on Linux. The find command searches for files in the specified directory hierarchy.

To list or find all hidden files, you must ask the find command to list all files whose names start with a period (.).

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

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

 

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

View hidden files using the GUI

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

You can launch the file by pressing the Super key and then typing the file  into the search input that appears. Click on the default Files program , the files in the Home folder will be displayed.

By default, your file manager does not show 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.

How to view hidden files and folders on Linux Picture 2How to view hidden files and folders on Linux Picture 2

You can also use the keyboard shortcut Ctrl + H to view hidden files on Linux.

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

Knowing how to list and view all files, including hidden files and folders, will come in handy if you use Linux every day. Dot files play an important role in the Linux operating system because they are often used to store configuration settings for programs.

In addition to files, the find command can also efficiently locate directories on Linux. But there are some flags and options that you will have to learn to do this.

4 ★ | 1 Vote