How to hide files and directories in Linux

.

ADVERTISEMENTS



What is the difference between a hidden file and an ordinary file in Linux?

I am a new Linux user. How do I hide files and directories in Linux operating systems using the command line interface?Introduction – In Linux and Unix-like systems, if a file or directory (folder) name starts with a period (), then the file becomes hidden by default. To see all hidden files in Linux run ls -al command . This page shows how to hide files in Linux using various methods.

The main difference between a hidden file and an ordinary file is that the file name of a hidden file starts with a period or dot ( . ). Often known as dot files in Linux. The dot file is not a security feature. It is for your convenience and to reduce clutter in your home directory.

You can pass the -a options to the ls command to see hidden file:

ls -a

ls -al

ls -al | more

ls -al | grep 'bash'



How do I hide files and directories in Linux?

To hide a file or directory in Linux, rename it with a period ( . ) at the start of its name using the mv command. Say, you need to hide a file named foo.txt, run:

mv foo.txt .foo.txt

Verify by running the ls command:

ls

ls -al

$ echo "Isolation doesn't bother me at all. It gives me a sense of security."> foo.txt

$ ls

$ mv foo.txt .foo.txt

$ ls

$ ls -al



Look ma files are hidden in GUI file managers too

Open folder or directories in your GUI file manager. Press CTRL+H to see or hide hidden files along with regular files.



How do I hide folders/directories in Linux?

Use the mv command by adding a . at the beginning of the directory name:

mv -v my-folder .my-folder

mv -v dir1 .dir1

mv -v dir2 .newdir2

How do I unhide a file or folder in Linux?

To unhide a file called .foo.txt, rename it to foo.txt i.e. remove a dot/period . at the beginning of its name:

ls -la

mv -v .foo.txt foo.txt

mv -v .dir1 dir1

mv -v .newdir2 dir2

ls -l

How to hide and password protect my files

To encrypt a single file, use the gpg command as follows:

gpg -c foo.txt

Now hide it:

mv -v foo.txt.gpg .foo.txt.gpg

Delete the original file in Linux using the rm command:

rm foo.txt

ls -la



gpg --output foo.txt --decrypt .foo.txt.gpg

rm .foo.txt.gpg

How to compress and protect a folder in Linux using a password

To decrypt file use the gpg command again as follow:For more information see my post “ Linux Encrypt And Decrypt Files With A Password “.

Use the tar command to compress the whole folder named dir1 in the current working directory:

tar -cz dir1 | openssl enc -aes-256-cbc -e > dir1.tar.gz.enc

Hide it:

mv -v dir1.tar.gz.enc .dir1.tar.gz.enc

Delete the original directory in Linux using the rm command:

rm -rf dir1

To decrypt, run:

openssl enc -aes-256-cbc -d -in dir1.tar.gz.enc | tar xz



Related – How do I Compress a Whole Linux or UNIX Directory?

Conclusion

This page demonstrated various ways to hide and use a password to protect files in Linux.

Category List of Unix and Linux commands File Management cat Network Utilities dig • host • ip • nmap Package Manager apk • apt Processes Management bg • chroot • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time Searching grep • whereis • which User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w