How To View Hidden Files In Linux : Showing Hidden Files With Ls Command

Linux hides certain files by default, but a single command makes them visible. If you are new to Linux or just need a refresher on how to view hidden files in linux, this guide covers everything from the terminal to graphical file managers. Hidden files are usually configuration files or system data that start with a dot (.), and knowing how to reveal them is essential for troubleshooting, customization, or system administration.

How To View Hidden Files In Linux

Hidden files in Linux are simply files whose names begin with a dot (.). The system hides them to keep your home directory clean and prevent accidental changes to important settings. You can view them using the ls command in the terminal or by enabling a setting in your file manager. Let’s break down both methods step by step.

Using The Terminal To Show Hidden Files

The terminal is the fastest way to see hidden files. Open a terminal window and navigate to the directory you want to explore. Then run the ls -a command. The -a flag stands for “all” and displays every file, including hidden ones.

For example:

cd ~
ls -a

You will see entries like .bashrc, .profile, and .config. These are all hidden files. If you want more details like file size and permissions, use ls -la. The -l flag gives a long listing format.

Common Flags For Listing Hidden Files

  • -a – Shows all files including hidden ones
  • -l – Long format with permissions, size, and date
  • -la – Combines both flags
  • -A – Shows almost all files, except . and ..

Using ls -A is handy if you want to skip the current and parent directory entries. It still reveals hidden files but keeps the output cleaner.

Viewing Hidden Files In Graphical File Managers

Most Linux desktop environments like GNOME, KDE, or XFCE have a built-in option to show hidden files. The shortcut is usually Ctrl + H. Pressing this toggle will instantly reveal or hide dot files in the current folder.

If you prefer using the menu, look for an option like “Show Hidden Files” under the View menu. In Nautilus (GNOME’s file manager), you can also click the hamburger menu and select “Show Hidden Files.”

File Manager Specific Steps

  • Nautilus (GNOME): Press Ctrl + H or go to View > Show Hidden Files
  • Dolphin (KDE): Press Ctrl + H or use View > Show Hidden Files
  • Thunar (XFCE): Press Ctrl + H or go to View > Show Hidden Files
  • Nemo (Cinnamon): Press Ctrl + H or use Edit > Preferences > Show Hidden Files

Remember that this setting is per folder in some file managers. You might need to enable it each time you open a new directory.

Using Find Command To Locate Hidden Files

The find command is powerful for searching hidden files across your system. For instance, to find all hidden files in your home directory, run:

find ~ -name ".*" -maxdepth 1

This command searches for files starting with a dot (.*) and limits the search to the current directory level. Remove -maxdepth 1 to search recursively through subdirectories. Be careful with recursive searches because they can return a lot of results.

Practical Examples With Find

  • Find all hidden files in the current directory: find . -name ".*"
  • Find hidden directories only: find . -type d -name ".*"
  • Find hidden files larger than 1MB: find . -name ".*" -size +1M

The find command is especially useful for system administrators who need to audit hidden configuration files.

Using Grep With Ls To Filter Hidden Files

If you want to see only hidden files without the non-hidden ones, combine ls with grep. For example:

ls -a | grep "^\."

The ^\. pattern matches lines that start with a dot. This filters the output to show only hidden files. You can also use ls -A | grep "^\." to exclude . and ...

Alternative With Tree Command

The tree command can display hidden files if you use the -a flag. Install it with sudo apt install tree on Debian/Ubuntu or sudo dnf install tree on Fedora. Then run:

tree -a ~

This shows a visual directory tree including hidden files. It’s great for understanding the structure of configuration directories like .config.

Understanding Hidden Files In Linux

Hidden files are not secret or encrypted; they are simply not shown by default. The dot prefix is a convention that started with Unix. Most configuration files for user applications live in hidden directories like .config, .local, or .cache. System-wide configuration files are often in /etc and are not hidden.

Some common hidden files include:

  • .bashrc – Shell configuration for Bash
  • .profile – Login shell settings
  • .gitconfig – Git configuration
  • .ssh – SSH keys and config
  • .vimrc – Vim editor settings

Editing these files can change how your system behaves. Always make a backup before modifying them.

How To Hide Files Yourself

To hide a file or folder, simply rename it with a dot at the beginning. Use the mv command:

mv myfile.txt .myfile.txt

This will hide the file from normal directory listings. To unhide it, rename it back without the dot. You can also create a hidden directory with mkdir .myfolder.

Using Chflags On Some Systems

On some Linux distributions with extended attributes, you can use chattr to add the hidden attribute. For example:

sudo chattr +h myfile.txt

This is less common and not supported by all file systems. The dot prefix method works everywhere.

Viewing Hidden Files In Different Directories

Hidden files exist in many locations. Your home directory contains user-specific configs. The root directory / has some hidden files too, like .bashrc for the root user. System directories like /etc rarely have hidden files because they are not meant to be hidden.

To view hidden files in a specific directory, navigate there first:

cd /var/log
ls -la

This will show all files including hidden ones in /var/log. Hidden files in system logs are rare but can occur.

Using Wildcards With Hidden Files

Wildcards like * do not match hidden files by default. If you want to copy or move all files including hidden ones, you need to use a special pattern. For example, to copy everything from one directory to another:

cp -r source/. destination/

The . at the end of source/. tells the shell to include hidden files. Alternatively, use cp -r source/* source/.* destination/ but this can cause errors if there are no hidden files.

Bash Glob Options

You can enable the dotglob option in Bash to make wildcards match hidden files:

shopt -s dotglob
ls *

Now ls * will show hidden files too. To disable it, use shopt -u dotglob. This is useful for scripts that need to process all files.

Hidden Files In Different File Managers

Besides the common ones, some file managers have additional settings. For example, in GNOME’s Nautilus, you can set it to always show hidden files by default. Go to Edit > Preferences > View and check “Show Hidden Files.” This saves you from pressing Ctrl + H every time.

In KDE’s Dolphin, you can set this in Settings > Configure Dolphin > General > Show Hidden Files. For Thunar, it’s under Edit > Preferences > Behavior > Show Hidden Files.

Command Line File Managers

If you use terminal-based file managers like mc (Midnight Commander) or ranger, they also have options to show hidden files. In mc, press Ctrl + H to toggle hidden files. In ranger, press zh to toggle.

Security Implications Of Hidden Files

Hidden files are not secure. Anyone who knows how to view them can see their contents. Never store sensitive information in hidden files expecting them to be invisible. Use proper encryption or permissions instead.

Malware can also hide itself as a dot file. Always check hidden files if you suspect an infection. The ls -la command is your first line of defense.

Troubleshooting Common Issues

Sometimes the ls -a command does not show hidden files because the file system is mounted with the hidden option. This is rare but can happen with some external drives. Remount the drive without that option.

Another issue is that some file managers cache the view state. If you toggle hidden files and nothing changes, try refreshing the window with F5 or restarting the file manager.

Permissions Problems

If you cannot see hidden files in a directory you don’t own, you might lack read permissions. Use sudo ls -la /root to view hidden files in the root user’s home directory. Be cautious with sudo commands.

Automating Hidden File Visibility

You can create an alias in your .bashrc to always show hidden files. Add this line:

alias lh='ls -la'

Now typing lh will show all files including hidden ones. You can also create an alias for ls -a called la. This saves time if you frequently need to view hidden files.

Using Environment Variables

Some programs respect the LS_OPTIONS environment variable. Set it to --almost-all to make ls always show hidden files:

export LS_OPTIONS='--almost-all'

Add this to your .bashrc for a permanent effect.

Hidden Files In Scripts

When writing shell scripts, you might need to iterate over hidden files. Use a loop with the .* pattern:

for file in .*; do
  echo "$file"
done

This will include . and .., so you may want to filter them out. Use an if statement to skip them:

if [ "$file" != "." ] && [ "$file" != ".." ]; then
  echo "$file"
fi

Comparing Hidden Files Across Systems

If you work on multiple Linux machines, you might want to compare hidden files. Use diff to compare two .bashrc files:

diff ~/.bashrc ~/backup/.bashrc

This helps maintain consistent configurations. You can also use rsync to synchronize hidden directories like .ssh.

Hidden Files And Backups

When backing up your home directory, ensure you include hidden files. Many backup tools ignore them by default. Use rsync -a which preserves hidden files because it copies everything. The -a flag stands for archive and includes dot files.

For example:

rsync -a ~ /mnt/backup/

This will copy all files including hidden ones. Always test your backup to verify hidden files are included.

Frequently Asked Questions

How do I view hidden files in Linux using the terminal?

Use the ls -a command in the terminal. This shows all files including hidden ones. For more details, use ls -la.

What is the shortcut to show hidden files in Linux file manager?

Press Ctrl + H in most file managers like Nautilus, Dolphin, or Thunar. This toggles hidden file visibility.

Why are hidden files hidden in Linux?

They are hidden to reduce clutter and prevent accidental modification of configuration files. The dot prefix is a convention from Unix.

Can I make hidden files always visible in Linux?

Yes, you can set your file manager to always show hidden files in its preferences. In the terminal, you can create an alias like alias ls='ls -a'.

How do I hide a file in Linux?

Rename the file with a dot at the beginning using the mv command, like mv file.txt .file.txt.

Final Thoughts On Hidden Files

Knowing how to view hidden files in linux is a fundamental skill. Whether you use the terminal or a graphical interface, the process is simple once you understand the dot prefix. Hidden files are not dangerous, but they contain important settings that can affect your system. Always edit them with care and keep backups.

Practice using ls -a and Ctrl + H until it becomes second nature. Over time, you will find yourself relying on hidden files for customization and troubleshooting. They are a core part of the Linux experience.

Remember that hidden files are not a security feature. They are just a convenience to keep your directories tidy. For real security, use file permissions and encryption. Now you can confidently navigate any Linux system and reveal what lies beneath the surface.