This guide will show you Hide Files and Directories in the Linux Terminal Command Line. As a Linux user, you may want to hide your folders and directories for many reasons. This guide tries to show you how you can do this from the Linux terminal by using the Linux Commands. Also, you can use this instruction in any Linux distro such as Ubuntu 22.04, Debian 12, AlmaLinux, Rocky Linux, etc.
Why Should You Hide Folders in Linux?
You may have some information and documents that you want to keep private and you don’t like to display it to others. Also, you can prevent it from accidental deletion. This is a good reason to keep your sensitive files and directories hidden.
Simple Way To Hide Files and Directories in Linux Terminal Command Line
To complete this guide, you must have access to your server as a root or non-root user with sudo privileges. For this purpose, you can check the Linux server setup initial guides on the Orcacore website.
Now proceed to the following steps to start the hiding process in Linux.
Step 1 – Hiding Files in Linux Terminal
To hide your files, you can simply use the mv command and move your file into a file starting with a dot. As you may know, the files that contain a dot at the beginning of their name, are hidden files.
For example, we have a file named file1, and we want to make it hidden in our Linux distros.
Output anaconda-ks.cfg cs exec_recipe.log file1 recipe_-1.log
To do this, we run the command below:
mv file1 .file1
As you can see, we append the file a dot to make it hidden. When you run the ls command, you can’t see your file because it is a hidden file now.
Output anaconda-ks.cfg cs exec_recipe.log recipe_-1.log
Step 2 – Hiding Folders or Directories in Linux Terminal
At this point, to make your directory hidden, you can also use the mv command and append the dot to it.
As an example, we have a test directory as shown below:
Output total 0 drwxr-xr-x 2 root root 4096 Nov 4 04:09 test_dir
Then, to make it hidden, we should append a dot to the dir name:
mv test_dir .test_dir
Now when you check your directories with the ls command, you will not see it:
Output total 0
Step 3 – View Hidden Files and Directories in Linux Terminal
At this point, you can view or display your hidden files and directories from the terminal by using the following ls commands:
# ls -a Or # ls -la
With these ls commands, you can simply view your hidden files and directories.
Step 4 – Unhide Files and Directories in Linux Terminal
If you want to unhide your files and directories, you can simply use the mv command and append the hidden file to the normal file. For example:
# mv .file1 file1 # mv .test_dir test_dir
This will simply unhide your files and directories.
Note: To delete hidden files and directories, you can visit this guide on Delete Files and Directories in Linux Terminal.
Step 5 – Compress Files and Directories with Passwords in Linux command line
To make your hidden files and directories more secure, you can compress them with Zip and set a password for them. For example, to compress your files and set a password for them, you can use the following zip command:
zip -re files.zip file1
Output Enter password: Verify password: adding: file1 (stored 0%)
Then, you can make your zip file as a hidden file.
For the directories, you can do the same.
At this point, you have learned a simple way to hide your files and directories in the Linux terminal command line. Also, you have learned to unhide them and compress them with passwords for more security. Hope you enjoy it.
You may also like the following articles: