Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Hide Files and Directories in Linux: A Practical Guide

· 5 min read · Home Tech

In this article
  1. Why Hidden Files Exist
  2. How to Hide a File or Directory
  3. Viewing Hidden Files
  4. Common Misconceptions and Security
  5. How to Choose Between Hiding and Other Methods
  6. Common Problems and Troubleshooting
  7. Alternatives to Dot-Prefix Hiding
  8. Frequently Asked Questions

To hide a file or directory in Linux, rename it so its name begins with a dot (e.g., mv file.txt .file.txt). Hidden files are not shown by default in ls, file managers, or many command-line tools, but they are not encrypted or secure—anyone who knows the name can still access them.

Why Hidden Files Exist

The dot-prefix convention dates back to early Unix systems, where configuration files like .profile and .cshrc were placed in a user's home directory. To keep these files from cluttering directory listings, the ls command was designed to omit entries starting with a dot unless explicitly asked to show them. Over time, this became a de facto standard across Unix-like systems, including Linux and macOS. Today, most Linux applications store their per-user settings in hidden files or directories (such as .bashrc, .config, and .local) to keep home directories tidy.

How to Hide a File or Directory

The simplest method is to rename the item so its name begins with a dot. For example:

  • mv notes.txt .notes.txt hides a single file.
  • mv myfolder .myfolder hides a directory.
  • To hide multiple items at once, use a loop: for f in file1 file2; do mv "$f" ".$f"; done

If you want to hide a file without renaming it, you can use the chattr command to set the hidden attribute on ext4 filesystems: sudo chattr +h file.txt. This makes the file invisible to ls even with the -a flag, though it is not supported on all filesystems (e.g., it does not work on FAT or NTFS). The chattr method is more obscure and can cause confusion, so most users stick with the dot-prefix approach.

Viewing Hidden Files

To see hidden files in the terminal, use the -a (all) or -A (almost all, excluding . and ..) options with ls:

  • ls -a shows all files including hidden ones.
  • ls -A shows hidden files but omits the current and parent directory entries.
  • ls -la shows detailed information including hidden files.

In graphical file managers like GNOME Files (Nautilus), press Ctrl+H to toggle the display of hidden files. In KDE Dolphin, the same shortcut works. On the command line, you can also use find . -name ".*" to list hidden files in the current directory and its subdirectories.

Common Misconceptions and Security

A frequent misunderstanding is that hidden files are private or secure. In reality, the dot-prefix is only a visibility filter—it does not provide any protection. Anyone who knows the filename can access the file directly, and hidden files are often the first place an experienced user looks for configuration data. If you need to protect sensitive data, use proper file permissions (chmod), encryption (e.g., gpg or LUKS), or access control lists (setfacl). Hiding a file does not prevent it from being read, copied, or deleted by a user with appropriate permissions.

How to Choose Between Hiding and Other Methods

Deciding whether to hide a file depends on your goal:

  • Decluttering: If you want to keep configuration files out of your home directory listing, dot-prefixing is the standard and expected approach.
  • Security: If you need to protect sensitive information, hiding is insufficient. Use encryption or restrictive permissions instead.
  • System-level hiding: If you want to hide a file from all users on a shared system, consider using chattr or moving the file to a directory with restricted permissions.
  • Permanent vs. temporary: Renaming is easily reversible (mv .file.txt file.txt), while chattr requires sudo chattr -h to undo.

Common Problems and Troubleshooting

One common issue is that hidden files are not copied by default when using wildcard commands. For example, cp * /backup/ will not copy hidden files because the shell expands * to non-hidden names only. To include hidden files, use cp .* /backup/ or cp -a /source/. /backup/ (the trailing dot copies everything). Another issue arises when a file manager does not show hidden files after pressing Ctrl+H—this can happen if the file manager uses a different shortcut (e.g., some use Alt+.). Also, be aware that some programs (like tar) include hidden files when you specify a directory, but not when you use wildcards. If you accidentally hide a file and cannot find it, remember that ls -a will always reveal it.

Alternatives to Dot-Prefix Hiding

If you need to keep files out of sight but still want them easily accessible, consider these alternatives:

  • Move to a subdirectory: Put files in a directory like ~/private/ and simply avoid navigating to it.
  • Use a dedicated tool: Encrypted containers (e.g., veracrypt) or encrypted archives (gpg -c) provide real security.
  • Set permissions: Use chmod 700 on a directory to prevent other users from listing its contents.
  • Use a file manager's "hide" feature: Some file managers allow you to mark files as hidden without renaming, but this is often just a dot-prefix in disguise.

Frequently Asked Questions

How do I unhide a file in Linux?

To unhide a file, rename it to remove the leading dot: mv .file.txt file.txt. If you used chattr +h, run sudo chattr -h file.txt to clear the hidden attribute.

Does hiding a file save disk space or improve performance?

No. Hiding a file only changes its visibility in directory listings. The file occupies the same disk space and is read/written at the same speed as before.

Can I hide files on a USB drive or NTFS partition?

Yes, the dot-prefix method works on any filesystem because it is a naming convention, not a filesystem feature. The chattr method, however, only works on filesystems that support extended attributes, such as ext4, but not on FAT32 or NTFS.

Why do some hidden files have names like .bashrc but others like ..?

The . and .. entries are special directory entries that represent the current and parent directories, respectively. They are not actual files and are always present in every directory. The -A option in ls hides them because they are not useful in most listings.

Is there a way to hide files from ls -a?

Yes, using chattr +h on ext4 filesystems makes a file invisible even to ls -a. However, this is not a standard feature on all filesystems and can be confusing for other users who expect the dot-prefix behavior.