How to Show Hidden Files in Linux: 4 Best Ways

Written by

Reviewed by

Last updated: July 24, 2024

Expert verified

SVG Image

TL;DR

To show hidden files in Linux, you should know the following:

  1. List All Files, Including Hidden Ones: Use the command ls -a to list all files, including hidden ones, in the current directory.
  2. Display Only Hidden Files: Execute ls -d .?* in a specific directory to display only hidden files starting with a dot (.), excluding the current and parent directories.

Read the guide below to learn various methods to show hidden files in Linux, providing different ways to manage, access, and protect them.

Struggling to locate certain files on your Linux system because they seem to be missing? Hidden files play a crucial role in managing configuration settings and maintaining an uncluttered directory. This post will guide you through step-by-step methods to view, create, and manage hidden files, along with advanced tips and best practices. Whether you use the command line or a graphical interface, you’ll learn how to handle hidden files effectively. By the end, you’ll have the knowledge to organize your system better and avoid common pitfalls. Let’s dive into making your Linux experience smoother and more efficient.

What are Hidden Files in Linux?

Hidden files in Linux are regular files that start with a dot (.) in their name. For example:

  • .bashrc: A script file executed whenever a new terminal session is started in Bash.
  • .profile: A configuration file for the user environment.
  • .gitignore: Used by Git to determine which files and directories to ignore in a project.

These files do not appear when you list the contents of a directory using the ls command unless you add the -a (all) option. Hidden files are commonly used to store user preferences, system configurations, and application settings. By keeping these files hidden, the file system remains uncluttered, making it easier for users to navigate their directories.

Why Are Files Hidden in Linux?

Files are hidden in Linux for several important reasons:

  • Reduce Clutter: By hiding files, the directories appear cleaner and more organized. This helps users focus on the files they work with regularly without being distracted by system or configuration files.
  • Configuration Files: Many hidden files are essential for system and application configurations. Examples include:
    • .bashrc: Contains commands that run when a terminal session starts.
    • .profile: Sets environment variables and startup programs for the user.
    • .vimrc: Customizes the behavior of the Vim text editor.
  • Prevent Accidental Changes: Hidden files often contain critical settings that, if altered accidentally, could disrupt the functioning of applications or the system. Keeping these files out of sight minimizes the risk of unintended modifications.
  • Security: While not a primary security measure, hiding files can add a layer of obscurity, making it less likely for casual users to stumble upon sensitive configurations.

How to Show Hidden Files in Linux

To show hidden files in Linux, use the command ls -a in the terminal to list all files, including hidden ones. To display only hidden files, use ls -d .?*. For editing, open hidden files with text editors like nano or vim by specifying the file path. In graphical file managers like Nautilus or Dolphin, enable the option to show hidden files by pressing Ctrl+H. These methods help you easily access and manage hidden files using both command line and GUI environments.

For a better understanding of these methods, let’s explore all of them here:

1. List All Files Along the Hidden Ones

To list all files, including hidden files, in the current directory, use the ls command with the -a flag to display files with a dot (.) at the beginning of their names. Here’s the step-by-step guide to do this:

  1. Head to the command-line interface (CLI) via the Dash menu.
head to the command line interface cli via the dash menu
  1. Then, run the command below to list all files, including hidden files.
ls -a
  1. This command will display all files in the current directory, including those with a dot (.) at the beginning of their names, which denotes hidden files in Linux.
denotes hidden files in linux

2. Display Only the Hidden Files

This method displays only hidden files starting with a dot (.), excluding the parent directories by executing the ls command with the pattern ls -d .?* in a specific directory. It is helpful when you want to focus specifically on hidden files in a particular directory. Follow the steps below to use this method:

  1. Launch the Terminal window on your Linux machine using the Application menu.
launch the terminal window on your linux machine
  1. To display hidden files in a specific directory, use the cd command to navigate to that particular directory. For example, if you want to go to the Documents directory, you can run the following command:
cd Documents
  1. Then, execute the following command to display only hidden files in the current directory.
ls -d .?*
  1. This command will list files starting with a dot (.), excluding the parent directory (..).
will list files starting with a dot

3. Open Hidden Files with Text Editors

With this method, you can open, view, and edit any hidden file in the specified directory using a text editor. It can be Vim, Nano, or even Gedit. This is often helpful when you have to configure preference settings. Here’s how this method works:

  1. In the Terminal window, use a text editor command like nano, vim, or gedit, followed by the file’s path, to open a hidden file.
text_editor file_path
  1. Replace text_editor with your preferred text editor and file_path with the path to the hidden file. Just like I did here:
nano ~/.myhiddenfile
  1. Once you execute the command, the specified hidden file will open in the text editor:
specified hidden file will open in the text editor
  1. Now, you can edit the file or leave it unchanged. Then, close it using the appropriate keys based on your text editor. In my case, I used Ctrl + O to save and Ctrl + X to close the Nano editor.
you can edit the file or leave it unchanged

4.  View Hidden Files Using Linux File Managers

This method enables the visibility of hidden files in Linux file managers like Nautilus or Dolphin. By accessing the file manager’s settings and enabling the option to show hidden files, you can easily navigate through directories and access hidden files in a graphical and user-friendly manner. Here’s how to do it:

  1. Open your preferred Linux file manager (e.g., Nautilus, Dolphin).
preferred linux file manager work with hidden files in linux
  1. Navigate to the toolbar at the top and click on the three horizontal lines. Then, tick the box of Show Hidden Files in the dropdown menu.
tick the box of show hidden files in the dropdown menu
  1. Once you click the hidden files option, you’ll see all the files in the current directory, including the hidden ones. Now, you can easily navigate through directories as you normally would to access hidden files.
once you click the hidden files option

How to Create Hidden Files in Linux

Creating hidden files in Linux is essential for managing configuration settings, storing sensitive data, and reducing clutter in your directories. Hidden files in Linux are simply files that start with a dot (.) in their name. This convention ensures these files are not displayed by default when listing directory contents.

1. Using the Command Line

  1. Launch the terminal application on your Linux system. 
  2. Use the cd command to change to the directory where you want to create the hidden file.
cd /path/to/your/directory
navigating to a directory
  1. Use the touch command to create a new file. Prefix the file name with a dot (.) to make it hidden.
touch .myhiddenfile
creating a hidden file
  1. List all files in the directory, including hidden ones, using the following command:
ls -a

You should see your newly created hidden file (.myhiddenfile) in the list.

listing availabe hidden files

2. Using a Graphical User Interface (GUI)

  1. Launch your preferred file manager (e.g., Nautilus, Dolphin, Thunar) from the applications menu. Browse to the directory where you want to create the hidden file.
browse to desired directory
  1. Right-click in the directory and select the option to create a new file/folder. This option might be labeled as New Document, Create New, or something similar.
selecting new folder option
  1. When prompted to name the new file, start the file name with a dot (.). For example, name it .myhiddenfile. Save or confirm the creation of the file.
creating a hidden folder through gui
  1. Ensure that the file manager is set to show hidden files. In Nautilus, you can press Ctrl+H to toggle hidden files visibility. Verify that your hidden file (.myhiddenfile) appears.
viewing hidden files or folder

5 Advanced Techniques To Know When Working with Hidden Files in Linux

Besides the basic operations, you can also rename, move, search, and delete hidden files in Linux. Moreover, you can hide and encrypt important hidden files using tools like GPG or VeraCrypt. Here’s the breakdown of each method:

1. Rename and Move Hidden Files

With the mv command, you can rename or move the hidden files in Linux. That is, you can use the syntax mv current_name new_name to modify the name of the file, or mv file_path destination_directory for relocating the hidden file in Linux. It helps in organizing and managing hidden files. Here’s the step-by-step guide to do it:

  1. First, run the ls -a command to view the hidden files in the directory:
run the ls a command to view the hidden files
  1. To rename a hidden file “.myhiddenfile”, use the mv command:
mv current_name new_name
  1. Replace current_name with the current name of the hidden file, new_name with the desired new name.
replace current name with the current name of the hidden file
  1. Now, run the ls -a command to view the renamed hidden files in the directory:
view the renamed hidden files in the directory
  1. To move a hidden file to a different directory, you can execute:
mv file_path destination_directory
  1. Replace the file_path with the path to the hidden file, and destination_directory with the path to the destination directory.
replace the file path with the path to the hidden file
  1. Now, use the cd command to navigate to the folder where you have moved the file.
use the cd command to navigate to the folder
  1. Then, run the ls -a command to view the moved file in the folder.
run the ls a command to view the moved file in the folder

2. Delete Hidden Files

This method involves using the rm command to delete a hidden file. By specifying the path to the hidden file, you can permanently remove it from the specified directory. However, you have to be carefil when using this method, as hidden files may contain important data or configuration settings.

  1. In the Linux command line, use cd to navigate to the directory.
use cd to navigate to the directory
  1. Then, run the ls -a command to view the hidden files in this folder.
run the ls a command to view the hidden files in this folder
  1. After that, use the rm command to delete a hidden file:
rm ~/.filename
  1. Run the ls -a command. However, you won’t see the deleted file in the specified directory as you have removed it using the rm command.
see the deleted file in the specified directory

However, you should be careful when deleting hidden files, as they may contain important data or configuration settings.

3. Manage Hidden Files in File Explorer

Once the hidden files in Linux are visible using the file manager’s settings, it let you directly manage hidden files within the file explorer interface. You can quickly right-click on any hidden file and access various options like renaming, moving, deleting, and more. This method provides a convenient and visual way to handle hidden files with familiar context menus.

  1. Once you enable the hidden file visibility from the File Manager’s settings, locate the desired hidden file in window explorer.
enable the hidden file visibility from the file manager
  1. Then, right-click on a hidden file to access various options such as renaming, moving, deleting, or more.
right click on a hidden file to access options
  1. In case you select to delete the file or move it to trash for any reason and later want that particular hidden file back, then you can easily get it restored via the Trash folder.
delete the file or move it to trash for any reason

4. Search for Hidden Files

You can use the find command with appropriate options to search for hidden files in Linux Terminal. This method makes it easier to locate specific hidden files based on criteria such as file type or name. Follow the steps below to use this method to search for hidden files on your Linux machine:

  1. To search for all hidden files in your home directory, run the following command in the Terminal window:
find ~ -type f -name ".*"
  1. This command will scan the specified directory (in this case, the home directory) and display a list of hidden files, including their paths, that match the given criteria.
display a list of hidden files that match the given criteria
  1. To help you understand the output of this command, here’s the breakdown:
    • find: The command used to search for files and directories.
    • ~: Represents the home directory.
    • -type f: Specifies that only regular files should be included in the search (excluding directories).
    • -name ".*": Sets the search pattern to match hidden files, as their names start with a dot (.) in Unix-like systems.

5. Encrypt and Secure Hidden Files

This method involves encrypting important hidden files in Linux using tools like GPG (GNU Privacy Guard) or VeraCrypt. Encryption adds an extra layer of security to protect sensitive information within hidden files. Here’s how you can easily encrypt your important hidden files in Linux:

  1. Update your package repository with the command below to ensure you have the latest package information before installing any software.
sudo apt update && sudo apt upgrade
  1. Type y and press Enter to continue with the update installation.
type y and press enter to continue with the updates
  1. Install and set up an encryption tool like GPG or VeraCrypt on your Linux machine. In my case, I executed the following command:
sudo apt install gnupg
  1. If this tool is already installed on your machine, it’ll display the following output:
set up an encryption tool like gpg
  1. Next, run the ls -a command to list all the files in the current directory, including the hidden ones. Then, identify the hidden files that you want to encrypt.
identify the hidden files that you want to encrypt
  1. Use the encryption tool’s commands to encrypt the hidden files. For example, with GPG, you can run the following command to encrypt a file:
gpg --encrypt filename
  1. Replace the filename with the actual name of the hidden file that you want to encrypt. Make sure that you’ve already generated the key using gpg --gen-key to make this method work.
actual name of the hidden file that you want to encrypt
  1. Follow the tool’s instructions to set a strong passphrase or password for accessing the encrypted hidden files.
password for accessing the encrypted hidden files
  1. When you are done, you’ll have the encrypted hidden file in that particular folder.
encrypted hidden file in that particular folder

Remember to keep your passphrase or password secure and confidential.

How to Hide Files and Directories in Linux

To hide files or directories in Linux, you can rename them by adding a dot (.) at the beginning of their names. Here’s how this method works:

  1. Locate the file or directory you want to hide.
locate the file or directory you want to hide
  1. Then, right-click on the file and click the Rename from the context menu.
click the rename from the context menu
  1. Adding a dot (.) at the beginning of the file name. Then, click the Rename button.
dot at the beginning of the file name
  1. Now, this file has become a hidden file as its name starts with a dot.
hidden file as its name starts with a dot

5 Best Practices When Working with Hidden Files in Linux

By following the best practices when working with hidden files in Linux, you can ensure the effective management, security, and usability of hidden files in your Linux system. Here are the five best practices to keep in mind when working with hidden files in Linux:

  • 💾 Regular Backups: Regularly back up hidden files and directories. This ensures their safety and recoverability. Use commands like rsync to back up hidden files while excluding other files from the backup.
  • 📝 Descriptive Names: Use descriptive names for hidden files and directories. This enhances organization and readability. For example, rename .folder2 to .webserver-config to make file management easier and more organized.
  • 📂 Consistent Organization: Maintain consistent file organization for hidden files and directories. Create dedicated hidden directories like .hidden-data and categorize files by purpose, such as configuration files or personal scripts.
  • ⚠️ Backup Before Modifying: Always create a backup copy before modifying hidden configuration files. Use the cp command to make a backup. This ensures you can restore the original if something goes wrong.
  • Understand Before Deleting: Avoid deleting hidden files without understanding their purpose. Hidden files often contain crucial settings. Research their purpose to avoid issues or malfunctions in your system or applications.

To Sum Up

In this article, I have walked you through the step-by-step methods to show hidden files in Linux using both the command line and graphical user interface. I have also explored how to create hidden files and hide files and directories efficiently. Additionally, I have also covered advanced techniques along with best practices for managing these files securely and effectively.

To further enhance your Linux skills, I recommend:

Frequently Asked Questions

How can I restore visibility to hidden files in Linux?

To restore visibility to hidden files in Linux, you can enable the option to show hidden files in your file manager’s settings or use the ls -a command in the command line interface. That is, in most graphical Linux file managers, there is usually a setting or option to display hidden files. Once enabled, hidden files will be visible alongside other files in the file manager. Similarly, when using the command line interface, the ls -a command lists all files, including hidden files, in the current directory.

Are hidden files and folders the same in Linux?

Yes, hidden files and folders are treated similarly in Linux. They are denoted by a dot (.) at the beginning of their names. In Linux, any file or directory whose name begins with a dot is considered hidden. This naming convention helps to differentiate hidden files and folders from regular ones and serves as a visual cue that they are not typically displayed by default in file managers.

Can hidden files impact system performance?

Hidden files themselves do not directly impact system performance. However, it’s worth noting that hidden files can contain large amounts of data or be associated with resource-intensive processes, just like regular files. If a hidden file consumes a significant amount of system resources or is involved in continuous read/write operations, it can indirectly affect system performance. It’s essential to monitor resource usage and identify any specific hidden files that may be causing performance issues.

Are hidden files recoverable if accidentally deleted?

Hidden files can be recovered if accidentally deleted, provided they have not been overwritten by new data. When a file is deleted in Linux, its entry in the file system’s directory is removed, but the actual data remains on the disk until it gets overwritten by new data. To recover accidentally deleted hidden files, you can use file recovery tools (TestDisk, PhotoRec, Scalpel, etc.) specifically designed for Linux systems. These tools scan the disk for recoverable data and can often restore deleted files, including hidden ones, as long as the data has not been overwritten.

How do I change permissions on hidden files?

To change permissions on hidden files in Linux, use the chmod command with permission codes or symbolic notation. For example, chmod 644 .hiddenfile sets read and write permissions for the owner and read-only permissions for others. Symbolically, chmod u+rw,go+r .hiddenfile achieves the same result.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Create Symbolic Links in Linux [5 Best Ways]

Next Post

How to Create a Text File in Linux Terminal [5 Best Ways]

Read next