Here is a nifty trick that will hide all specified files and directories without the need to rename them.
All you do is create a hidden file named .hidden (with the dot) in the directory containing the files you wish to hide. When the file manager refreshes, the listed files will no longer appear.
Let’s see the details…
In this example, we have a directory named fruity that contains two directories and two files.
We want to hide skippy’s_wonder and file_to_hide.txt, so we create a hidden file named .hidden in the same directory.
Open .hidden in a text editor, and add two lines: skippy’s_wonder and file_to_hide.txt. (Remember to include the filename extension.)
Save the changes and refresh the file manager. Presto! The directory skippy’s_wonder and file_to_hide.txt no longer appear, but the other files are visible.
To view the hidden files, simply switch the file manager’s view mode to show the hidden files.
You can also comment out a line (# at the beginning of a line) in .hidden to unhide a file or directory.
“I use ____________. Will this work for me?”
Maybe, maybe not. You will need to experiment for yourself. I have tested and confirmed that this trick works in Linux Mint 17.1 and Xubuntu 14.04, but this tends to be a file manager-specific feature, not a Linux distribution feature.
Nemo 2.4.5 and Nautilus 3.10.1 both support this .hidden file trick, but Dolphin and Thunar do not.
“What about the command line?”
The .hidden file will not hide files and directories from a command line listing, such as the output of ls.
Dot files will still be hidden unless you use the -a option with ls.
“Why would I want to use this?”
A file or directory is hidden by renaming it with a leading dot character. This is not always possible for preset directories that are forced onto you. For example, some programs, like VirtualBox, will create folders in the home directory that are rarely used by the user and only clutter the home.
In the case of VirtualBox, the directory VirtualBox VMs is created that contains virtual images. I would prefer to hide this directory from the normal view in order to reduce home clutter, but renaming it will require configuration changes in VirtualBox.
Sure, I could rename or move VirtualBox VMs and then open the VirtualBox configuration settings to manually adjust the new location, but it is easier and faster to use a .hidden file. This way, I can easily unhide the directory in the future and VirtualBox will never know the difference.
Of course, proper dot files should be used to hide files and directories whenever possible, but there are times when you do not have control over other people’s programs and the digital litter they spew. For those instances, we have .hidden!
This feature is what I would consider to be one Linux’s best-kept secrets. It seems trivial at first, but I have found it to be amazingly useful for situations where renaming a file or directory is not the most practical option.
Give it try!