How do I hide a file or folder under Linux?

How to hide a file or folder under Linux

Under Linux, files and folders can be created in a variety of ways, notably with the touch and mkdir commands. Although we generally create visible items on the file system, how can we hide a file or folder under Linux? Find out in this article!

The manipulations are performed on a Debian machine, but this method can be applied to other Linux distributions, including Ubuntu, CentOS, Rocky Linux, Fedora, etc.

1. Creating a hidden file under Linux

To create a hidden file under Linux, this may come as a surprise, but all you have to do is prefix the file name with a dot.

The following command creates a non-hidden file

touch file.txt

While this command creates a hidden :

touch .fichier.txt

The difference is in the detail... And I must point out that the name of the element will be ".fichier.txt" and not "fichier.txt", because the dot is actually part of the file name. Perhaps some of you have already worked on Web servers where there are often hidden ".htaccess" files.

In the same style, a file that is not hidden can become so simply by renaming it :

mv file.txt .file.txt

For Linux GUI enthusiasts, if you want to hide a file in graphical mode, simply add a "." at the beginning of the name. The principle remains the same!

2. Creating a hidden folder under Linux

To make the file invisible on the disk, you need to add a dot to the beginning of the name, but what about folders? The answer is simple: by adding a "." as well, in exactly the same way!

As a result, this file will not be hidden:

mkdir folder

While this folder will be hidden :

mkdir .folder

Here again, you can rename a folder so that it becomes hidden (or vice versa):

mv folder .folder

3. List hidden items

Finally, we'll take a look at how to list hidden files and folders under Linux. The command for listing the contents of a directory is " ls" . Except that, by default, it doesn't list hidden items.... We can see this with our previously created hidden file:

Creating a hidden file under Linux

But also with the hidden folder :

Creating a hidden folder under Linux

How do you get ls to return the hidden elements? Is it possible? The answer is yes.

The "-a" option of the "ls" command should be used to display hidden items, whether files or folders. For better readability, you should also add the " -l "to get a list.

ls -a
ls -al

Here's the proof that it works:

Linux - List hidden files and folders

From now on, I know a few people who will have the reflex to use the "-a" option to make sure they don't miss anything when listing the contents of a directory!

4. Conclusion

Thanks to this article from the Computer Tutorials box, you will be able to hide a file or folder under Linuxbut also to list these same items from the command line. It's all part of the essential Linux basics!

Resources :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *