How to Hide Files and Folders From Prying Eyes on Linux
Hide Existing Files and Folders Using the Terminal
To hide an existing file or folder using the Terminal, press Ctrl + Alt + T to open a Terminal window.
Use the cd command to go to the file or folder you want to hide. For example, we’re going to hide our FilesToHide folder in the Documents folder. So we use the following commands:
cd Documents/
cd FilesToHide/
You can also change to a folder by putting the full path in a single cd command:
cd ~/Documents/FilesToHide/
The “~” character is a shortcut for your Home folder. The above path expands to /home/lori/Documents/FilesToHide/.
Then, we use the ls command to list all the unhidden files and folders in the current folder. We’re going to hide the HideThisFile.txt file. To hide a file or folder, add a dot (.) at the beginning of the name.
To add a dot at the beginning of the HideThisFile.txt file name, we’re going to use the mv command to rename the file:
mv HideThisFile.txt .HideThisFile.txt
Now when you use ls to list the files in the current folder, you’ll see the file you renamed is now shown.
View Hidden Files and Folders Using the Terminal
So how do you view files and folders in the Terminal once they’re hidden? The -a switch on the ls command lists all items, including hidden files and folders.
Use the cd command to go to the folder containing hidden items. Then, type the following command:
ls -a
Hidden items with a dot (.) at the beginning of the name are listed.
Sometimes it’s easier to view the items in a folder in a list format, like the Details view in File Explorer in Windows. The following command lists all files, hidden and not hidden, in a detailed list format:
ls -al
Create a New Hidden File or Folder Using the Terminal
You can also create new files and folders as hidden items. Use the mkdir command to create a new folder. To make that folder hidden, add a dot (.) at the beginning of the name, just like you would when renaming an existing folder to hide it.
mkdir .FilesToHide
The touch command creates a new blank file in the current folder. For example, the following command creates a new text file called MyFile.txt.
touch MyFile.txt
To create a new hidden file, add a dot (.) at the beginning of the name in the touch command.
touch .HiddenFile.txt
View Hidden Files and Folders Using Nautilus
If you’re not comfortable using the Terminal to hide files and folders, you can use the file manager in your Linux system. Ubuntu is a commonly used version of Linux, so we’re going to show you how to view hidden items in Nautilus, Ubuntu’s file manager. File managers in other Linux systems may vary but likely operate similarly.
Go to Edit > Preferences.
Make sure the Views tab is active. Then, check the Show hidden and backup files box in the Default View section. Close the dialog box.
You’ll see all items in the file manager now, including hidden items with a dot (.) at the beginning of their name.
You can also press Ctrl + H to show and hide hidden files and folders.
Hide Files and Folders Using Nautilus
To create a new hidden folder in Nautilus, go to File > New Folder. If you’re creating a new hidden text file, go to File > New Document > Empty Document instead.
The name of the folder (or file) becomes editable and is selected. Type a dot (.) and then the name you want. Press Enter.
You can also easily rename a file or folder in Nautilus to hide the item. Right-click on the item and select Rename. The name of the item becomes editable and is selected. Add a dot (.) to the beginning of the name.