How to View Hidden Files and Folders on Linux
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.
Why Do We Have Hidden Files?
The concept of hidden files is simple yet very important in Linux. Hidden files are mainly used for storing configuration files or user settings. Usually, system services, scripts, or other programs use these files for storing and reading configurations.
For example, the .bash_logout script executes 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.
You can also use the concept of hidden files to hide certain files from the prying eyes of mostly non-advanced users. A good example is the ~/.ssh directory or folder used for storing SSH keys and configuration files.
Viewing Hidden Files With the ls Command
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. This tells the ls command to list “all” files and folders including hidden ones, i.e. those starting with a dot (.).
Navigate to your home directory with the cd command and check for hidden files using ls as follows:
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 ignore hidden files.
If you do not have any hidden files in your home directory, you can create one using the touch command as follows:
You can also create hidden directories with the mkdir command. You just have to make sure you use a dot at the beginning of the folder name. For example, to create a hidden folder named secrets in your home directory, run the command:
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:
Finding Hidden Files on Linux Using find
In addition to ls, you can use the find command as an alternative way of listing or checking for hidden files and folders on Linux. The find command searches for files within a specified 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
Viewing 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 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 hidden files. Click on the Menu icon located in the upper-right corner and check off Show Hidden Files. Your hidden files and folders will now be visible.
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.