OSETC TECH

How to Hide Files And Directories in Linux

This post will guide you how to hide a file or directory on your Linux File system. How do I hide files or directories using a command in Linux operating systems. How to show all hidden files under a given directory in Linux.


Hide Files or Directories


If you want to hide a give file, and you just need to rename this file to place a dot character (.) directly in front of the file name. For example, you have file named mytext.txt under /root directory, and you want to change it as hidden file, you can use “mv‘ command to change its filename as “.mytext.txt“. type:

$ sudo mv mytext.txt .mytext.txt

Outputs:

[root@localhost ~]# ls mytext.txt
mytext.txt
[root@localhost ~]# mv mytext.txt .mytext.txt
[root@localhost ~]# ls
anaconda-ks.cfg ansible ansible.bak myvideo.mov myvideo.mp4

From the above outputs, you can see that mytext.txt has been changed as a hidden file.

List All Hidden Files


If you want to list all hidden files under a given directory or current working directory, and you can pass the “-al” option to the ls command, type:

$ ls -la

outputs:

[root@localhost ~]# ls -al
total 14912
dr-xr-x---. 6 root root 4096 Sep 28 19:34 .
dr-xr-xr-x. 18 root root 4096 Sep 27 15:07 ..
-rw-------. 1 root root 1027 Sep 24 15:47 anaconda-ks.cfg
drwxr-xr-x. 3 root root 4096 Sep 26 14:00 .ansible
drwxr-xr-x. 14 root root 4096 Sep 26 14:58 ansible
drwxr-xr-x. 14 root root 4096 Sep 26 14:59 ansible.bak
-rw-------. 1 root root 2670 Sep 27 17:30 .bash_history
-rw-r--r--. 1 root root 18 Feb 3 2019 .bash_logout
-rw-r--r--. 1 root root 176 Feb 3 2019 .bash_profile
-rw-r--r--. 1 root root 176 Feb 3 2019 .bashrc
drwx------. 4 root root 4096 Sep 26 14:26 .cache
-rw-r--r--. 1 root root 100 Feb 3 2019 .cshrc
-rw-------. 1 root root 48 Sep 27 17:48 .lesshst
-rw-r--r--. 1 root root 0 Sep 28 19:33 .mytext.txt
-rw-r--r--. 1 root root 8514187 Aug 10 12:14 myvideo.mov
-rw-r--r--. 1 root root 6689021 Sep 27 18:15 myvideo.mp4
-rw-r--r--. 1 root root 129 Feb 3 2019 .tcshrc
-rw-r--r--. 1 root root 221 Sep 27 18:06 .wget-hsts
[root@localhost ~]#

From the above outputs, you can see that hidden file named “.mytext.txt” created in the above step.

Conclusion


You should know that how to hide files and folders using mv command from the command line on your CentOS or RHEL or Ubuntu Linux system.