- Hide files in Linux without using the dot
- 10 Answers 10
- An Easy Way to Hide Files and Directories in Linux
- How to Hide Files in Linux
- How to Hide Directories/Folders in Linux
- How to View Hidden Files and Directories in Linux
- How to Compress Files and Directories with Password in Linux
- How can I hide directories or files without changing their names?
- 6 Answers 6
Hide files in Linux without using the dot
I wish to hide files in Linux without using the dot, since it’s possible in Windows. Is there a way to do this?
10 Answers 10
Create a file .hidden in the directory with the names of the files to be hidden (one name each line).
Then add the following to your ~/.bashrc :
Now your ls command does not list these files.
I use this technique to hide my __pycache__ and __init__.py files.
EDIT: as per an other comment this also hides them in at least one (Nautilus), but probably several GUI file browsers as well.
it is interesting. Does it work also in the nautilus or other gui tools? Are you able to see the files with ls -al ?
code is missing a ‘ » at the end. (and in case you wonder where the upvotes are from: askubuntu.com/a/713591/15811 ) 😉
I got a syntax error syntax error near unexpected token `(‘ . Adding function to the beginning of the definition fixed this. But it looks like this definition doesn’t play nicely with aliases: I kept on getting either SIGINT s with ls —color=auto or an infinite string of ls —color=auto —color=auto —color=auto . depending on where in my .bashrc I included it. If someone has a solution let me know. Ubuntu includes several aliases by default.
The function keyword was introduced in ksh. The traditional Bourne shell (bash) only had the foo () syntax, and POSIX standardizes only the foo () syntax.
You cannot. There is a fundamental difference in the way the file systems handle hidden settings. In Windows, the file system stores several attributes for the file in metadata, including the attributes «hidden» and «system» (both of which are kinds of hidden files). In common *nix filesystems, no such attribute is stored. Instead, the information must be put somewhere else, such as in the file name. The convention is thus that files beginning with . (and depending on your system, maybe some others like _) will not be shown by most tools by default.
This is purely for convenience, a . beginning a file name means absolutely nothing but «the user probably doesn’t want to see this all the time.» To make sure that you know, running e.g. ls -a will show all files.
If you don’t want to have a file clutter up your listings in Linux, you should rename it to start with a dot (Bonus: this will work for OS X too, if we’re talking about a portable device). If you don’t want users to be able to find a file, you’re doing it wrong — that’s what permissions are for.
Unix permissions as they pertain to directories often confuse people, and maybe understanding it better will help you. The «read» and «execute» permissions ( r and x ) mean something different for directories than they do for files. For directories, the execute x permission determines whether or not you access the inodes in the directory. The read r permission dictates whether or not you can access the listing of the directory. Functionally, x allows the user to do things in a directory, while the r permission allows them to see what’s in it. These are different, and the difference can be confusing. Let’s look at an example:
jeanluc@login64: ~ $ mkdir example jeanluc@login64: ~ $ echo "you can read it" > example/file jeanluc@login64: ~ $ ls example/ file jeanluc@login64: ~ $ cat example/file you can read it jeanluc@login64: ~ $ chmod -x example/ jeanluc@login64: ~ $ ls example/ ls: cannot access example/file: Permission denied file jeanluc@login64: ~ $ cat example/file cat: example/file: Permission denied jeanluc@login64: ~ $ cd example/ -bash: cd: example/: Permission denied jeanluc@login64: ~ $ chmod +x example/ jeanluc@login64: ~ $ chmod -r example/ jeanluc@login64: ~ $ ls example/ ls: cannot open directory example/: Permission denied jeanluc@login64: ~ $ cat example/file you can read it jeanluc@login64: ~ $ cd example/ jeanluc@login64: ~/example $ ls ls: cannot open directory .: Permission denied jeanluc@login64: ~/example $ cd ..
So, notice that without execute I can still list the files (although ls shows an error because it cannot get the file properties), but I can’t change in to the directory or read the files in it. Without read I cannot list the files, but I can still change in to the directory and if I know the name of a file I can still access it.
Do note, though, that removing the read permission only gives you security by obscurity. If the user guesses the file name, they will be able to read its contents.
This may not have really been relevant to your question, I just wanted to make sure you understood directory permissions.
An Easy Way to Hide Files and Directories in Linux
Do you occasionally share your Linux desktop machine with family members, friends, or perhaps with colleagues at your workplace, then you have a reason to hide certain private files as well as folders or directories. The question is how can you hide files in linux?
In this tutorial, we will explain an easy and effective way to hide files and directories and view hidden files/directories in Linux from the terminal and GUI.
As we’ll see below, hiding files and directories in Linux is so simple.
How to Hide Files in Linux
To hide a file or directory from the terminal, simply append a dot . at the start of its name as follows using the mv command.
$ ls $ mv sync.ffs_db .sync.ffs_db $ ls
Using the GUI method, the same idea applies here, just rename the file by adding a . at the start of its name as shown below.
Once you have renamed it, the file will still be seen, move out of the directory and open it again, it will be hidden thereafter.
How to Hide Directories/Folders in Linux
To hide a directory or folder, you can use the same mv command and append the . at the start of the directory name (here directory name is my_imp_dir) as shown.
$ mv my_imp_dir .my_imp_dir $ ls -l
To unhide a directory, remove the . at the beginning of the directory name with the mv command as shown.
$ mv .my_imp_dir my_imp_dir $ ls -l
How to View Hidden Files and Directories in Linux
To view hidden files, run the ls command with the -a flag which enables viewing of all files in a directory or -al flag for a long listing of files.
From a GUI file manager, go to View and check the option Show Hidden Files to view hidden files or directories.
How to Compress Files and Directories with Password in Linux
In order to add a little security to your hidden files and directories, you can compress them with a password and then hide them from a GUI file manager as follows.
Select the file or directory and right-click on it, then choose Compress or Create Archive from the menu list, set the zip compression preferences, and click on “Other options” to get the password option as shown in the screenshot below.
Once you have set the password, click on Create.
From now on, each time anyone wants to open the file, they’ll be asked to provide the password created above.
You can also compress and password-protect files and directories using the zip command.
$ zip -re my_imp_files.zip files1.txt files2.txt files3.txt $ zip -re my_imp_dir.zip my_imp_dir
That’s it for now! In this tutorial, we described how to easily and effectively hide files and directories and view hidden files/directories in Linux from the terminal and GUI file manager. Make use of the feedback form below to share any thoughts with us.
How can I hide directories or files without changing their names?
The OCD in me wants directories I do not like the name of to be hidden since I do not interact with them directly. How can I hide directories without using the dot notation?
6 Answers 6
Assuming you only care about hiding the files from showing up in nautilus, there is a bug on the GNOME Bugzilla about this. However, currently, that bug has not been resolved.
There is another way to hide files from appearing in nautilus. If you create a file called .hidden inside of a directory, any filename listed in the file will not be displayed.
For example, below is a .hidden file that I created. This file will hide any files or folders named b or e located in the same directory as the .hidden file.
Below is a screenshot of the folder that contains the .hidden file. Note that you only see three files: a , c , and f . You do not see the .hidden file due to the ‘.’ at the beginning of its name.
The screenshot below is of the same folder as before. However, this time, I hit Ctrl + H to cause nautilus to display hidden files and folders. Notice how there are several additional files that show up. You now see several files that were previously hidden due to having names that began with a ‘.’. There are also now files called ‘b’ and ‘e’, which although not having names beginning with a ‘.’, were hidden due to being listed in the .hidden file.
Files mentioned in the .hidden file will only be hidden in nautilus. Tools like ls will still display them. The .hidden file is also not recursive. It only affects files in the same directory as the .hidden file is in.
Some people on the forum have gone ahead and created scripts for nautilus that make it easier to add files to the .hidden file. The first script includes a nice explanation about how to install and use the scripts, but the second script is a bit cleaner and shorter. Feel free to use either script to make your life a bit easier.