Hide Files and Directories in the Linux Terminal
Hiding files and directories in Linux is a way to make them invisible to regular users, ensuring that sensitive data or important configuration files remain secure. There are several methods to achieve this
Using Dot (.) Prefix
The easiest method is to use a dot (.) prefix. Files or directories starting with a dot are considered hidden. For example:
# To hide a directory mv test .test # To hide a file mv document.txt .document.txt
Hidden files can still be accessed using ls with the -a option.
Using Hidden Attribute
This method uses the hidden attribute, requiring root privileges. To set the hidden attribute for a file or directory:
# Set hidden attribute sudo chattr +h document.txt sudo chattr +h test # Unset hidden attribute sudo chattr -h document.txt sudo chattr -h test
Hidden files can be viewed using ls -a. This method offers more security as it requires root privileges.
This method involves setting permissions to “000” to make files or directories inaccessible to anyone, including the owner:
# Set permissions to "000" for a file sudo chmod 000 document.txt # Set permissions to "000" for a directory sudo chmod 000 test
Accessing files with these permissions requires sudo ls -a.