3 ways to hide Files and Directories in Linux [How To]

One day a friend of mine, who was a recent convert to the Ubuntu world from Windows came to me, asking how he could make the Desktop icon in his home directory go away. There is no 'enable hidden file' check box in the properties, as one have in Windows and this simple issue was driving him mad. He couldn't simply delete it as it's an important folder for proper functioning of GNOME. However the solution was simple.

Method 1

Make a file named .hidden in the same directory where our to-be-hidden file/directory lies. In our case, we want to hide /home/friend/Desktop. So we make a file named .hidden (don't miss the dot in front of hidden) in /home/friend. Next we add the name of the file/directory to be hidden into the .hidden file, one name in each line. Since we wanted to hide only the Desktop directory, we add a single line: Desktop into it. This was the solution to my friends problem as he needed to hide a file without renaming it. However, if you have the freedom to rename the file, then below two methods will be easier than this one.

Method 2

Just rename the file/directory and prefix the name with a ' . ' (a dot). Files starting with a ' . ' are considered to be hidden files by linux.

Method 3

Rename the file/directory and add a ' ~ ' to the end. eg: if the file name was secretfile.mk the new name will be secretfile.mk~. Linux considers files ending in ~ as backup files and hence hides them.

Note: In some machines you need to refresh the GNOME file browser to see the effect.

Do not use above methods to protect confidential data, as the hidden files can be easily seen using View -> Show Hidden Files (Ctrl + H) in Nautilus and ls -a in a terminal.