Home Learn Linux How to view hidden files and folders on Linux

How to view hidden files and folders on Linux

We will explain how to do this, using both command line and graphical methods.

by Arun Kumar
viewing hidden files in linux

I‘m sure you are here because you’re exploring the vibrant, vast universe of Linux, a personal favorite of mine for its flexibility, transparency, and community-oriented philosophy. Today, we’re going to delve into an interesting, if sometimes overlooked, aspect of the Linux filesystem: hidden files and folders. You know, the ones that quietly sit in your system, minding their own business, and often, working hard behind the scenes to ensure a smooth operation of your Linux system.

My experience with Linux goes way back to my college days when I first fell in love with its simplicity and open-source nature. The initial journey was intimidating, but gradually, the learning curve became a thrilling rollercoaster ride. Among my various explorations, the discovery of hidden files and folders was a revelation. But beware, just like me, you may find yourself strangely fascinated, or occasionally frustrated, by these stealthy system elements. So, without further ado, let’s get started on this intriguing journey.

What are hidden files and folders?

In Linux, files or folders that are prefixed with a dot (.) are classified as hidden. These include a wide range of entities, from configuration files (.bashrc, .gitconfig) to folders containing application data (.mozilla, .npm), and more. They are generally hidden to reduce clutter and prevent accidental modifications, as changes in these files could potentially disrupt the functioning of your system or certain applications.

Viewing hidden files and folders

Using the terminal

In order to view hidden files and folders via terminal, you can use the ls command, which stands for “list”. Typically, ls shows the visible files and folders, but coupled with the -a or -A option, it can reveal the hidden entities too.

Here’s how you do it:

Open a terminal window. The shortcut to open the terminal varies between Linux distributions, but it’s usually Ctrl+Alt+T.
Navigate to the directory you want to explore using the cd command. For instance:

cd ~/Documents

It will take you to your Documents directory.

Now, type ls -a and press enter.

ls -a
ls a option to display hidden files

ls -a option to display hidden files and folders

This should reveal all files and folders, including the hidden ones.

The -a option stands for “all”, which means it shows all files and folders, including . (current directory) and .. (parent directory). If you want to exclude these two, use ls -A.

Pro Tip: You can also use the ls -l option for a more detailed listing, showing file permissions, number of links, owner, group, size, and time of last modification. Note that the ls -l command doesn’t display hidden files and directories by default.

To view detailed information about hidden files, you need to use -l in combination with -a or -A. The command ls -al or ls -lA will list all files, including hidden ones, in a detailed list format.

ls -al
displaying hidden items with details

Displaying hidden items with details

Here’s what the command does:

  • ls: the “list” command.
  • -l: uses a long listing format to display additional info (file permissions, number of links, owner, group, size, and time of last modification).
  • -a: shows all files, including hidden ones.
  • -A: does the same as -a, but doesn’t list . (current directory) and .. (parent directory).

So, if you want to see a detailed listing of all files, including hidden ones, you should use ls -al or ls -lA.

Using a graphical file manager

If you’re more of a GUI person and feel more comfortable with a mouse than a terminal (although I must say, a Linux terminal is a delightful experience, once you get the hang of it), don’t worry, Linux has you covered.

Most graphical file managers, like Nautilus in Ubuntu or Dolphin in KDE, provide an option to view hidden files and folders. Here’s how:

Open your file manager.

Navigate to the directory you want to explore.

Look for a “View” option in the menu bar, then check “Show Hidden Files”. Alternatively, the shortcut Ctrl+H usually does the trick.

showing hidden files from files on pop! os

Showing Hidden Files from Files on Pop!_OS

Note: The exact steps might slightly differ based on the file manager you’re using, but the process remains largely the same.

Preventing the creation of hidden files and folders

It’s an intriguing question: can you prevent someone from creating hidden files or folders in a Linux system? Technically, the answer is complicated. Given the importance of hidden files in storing personal settings and system configuration data, you can’t completely disallow the creation of hidden files. However, you can implement measures to control the creation of hidden files by users or to monitor changes in specific directories.

File permissions and ownership

You can control who can create, modify, or delete files and folders in Linux by setting appropriate file permissions and ownership. Each file and directory has an associated set of permissions, which are divided into three groups: user (u), group (g), and others (o). These permissions define read (r), write (w), and execute (x) access.

For instance, if you want to restrict a user from creating files or folders (hidden or otherwise) in a certain directory, you can change the permissions of that directory so that the user doesn’t have write access.

To do this:

Open the terminal.
Navigate to the parent directory containing the directory you want to protect.
Use the chmod command to remove write permissions. For example, if you want to restrict access to a directory named ‘projects’, you’d type chmod -w projects.

chmod -w projects
checking existing permission and changing it

Checking existing permission and changing it

Note: You’d need appropriate permissions to execute this command. If you’re a system administrator, you can use sudo to get superuser permissions: sudo chmod -w projects. In the above screenshot, we first checked the existing permissions using ls-l, then changed the permissions of the folder “projects”.

Using system monitoring tools

Monitoring tools can’t prevent the creation of hidden files, but they can alert you when such files are created, modified, or deleted. A popular tool is inotify, which can monitor specific directories for changes.

Here’s how to set up inotify to monitor a directory:

Install inotify-tools with the command sudo apt-get install inotify-tools (for Debian/Ubuntu-based distributions).

sudo apt-get install inotify-tools

For Fedora, CentOS, or RHEL – These distributions use the dnf or yum package managers. So, you can use the following command to install inotify-tools:

sudo dnf install inotify-tools

If your version still uses yum, replace dnf with yum in the above command.

For Arch Linux and its derivatives (like Manjaro) – Arch Linux uses the pacman package manager. You can install inotify-tools using the following command:

sudo pacman -S inotify-tools

For OpenSUSE – OpenSUSE uses the zypper package manager. You can use the following command to install inotify-tools:

sudo zypper install inotify-tools

For Alpine Linux – Alpine uses the apk package manager. You can use the following command to install inotify-tools:

sudo apk add inotify-tools

These commands will install inotify-tools on most of the common Linux distributions.

Run the following command to monitor a directory (replace “directory_path” with the actual path):

inotifywait -m -r -e create,modify,delete directory_path

This command will monitor the specified directory for file creation, modification, or deletion, including hidden files. The -m option means “monitor indefinitely”, -r allows monitoring directories recursively, and -e specifies the events to watch for.

While these measures can’t absolutely prevent the creation of hidden files or folders, they can give you control over who has write access to certain directories and provide alerts when changes occur.

Remember that hidden files are a crucial part of Linux; tampering with them can have unintended effects. Always exercise caution and consult documentation or Linux experts when in doubt. Even after years of using Linux, I continue to learn new things, and I hope you’ll keep learning too. Always remember: with great power comes great responsibility, especially when wielding the might of Linux!

Common troubleshooting tips

Occasionally, despite our best efforts, things don’t go as planned. So, here are some common issues you might face, and their potential solutions:

  • Terminal doesn’t show hidden files: Make sure you’re using the correct option (-a or -A) with the ls command. A common mistake is using the capital -A option when you actually want to include “.” and “..”.
  • Can’t find a particular hidden file or folder: Remember, the Linux filesystem is case-sensitive. So, .File and .file are considered different. Make sure you’re typing the name exactly as it is.
  • Ctrl+H doesn’t work in the file manager: This shortcut might not work in every file manager. In this case, you’d have to manually go to the “View” option and select “Show Hidden Files”.

Pro tips

Here are some expert tips that will make you a Linux ninja in no time:

  • Use the autocomplete feature: When typing a file or folder name in the terminal, use the Tab key to autocomplete. This can save you a lot of time and prevent typos.
  • Make use of wildcards: If you’re unsure of the exact name, use the * wildcard. For example, ls .f* will list all hidden files/folders that start with ‘f’.
  • Learn more with man command: To know more about any command, use the man command. For instance, man ls will display the manual page for the ls command.

Conclusion

Whether it’s uncovering hidden files and folders, controlling file and directory permissions, or installing and using system monitoring tools, each new discovery adds another layer to your understanding of this powerful operating system.

Remember, hidden files and folders in Linux play a vital role in system and application configurations. While you can’t completely prevent their creation due to their importance, you can certainly control permissions and monitor their creation and changes.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.