Monday, January 28, 2013

Hiding a file or directory under Linux


Hiding a file or directory under Linux
To hide a file or directory in Linux, just give it a name preceded by a full stop (.).


For example:
. bash_history
. bash_profile
. ssh 

 
Hide UNIX file structure
 
1. Open a terminal and execut "ls -1 / | sudo tee /.hidden"

2. Do "sudo chmod a+r .hidden"

3. If you want all standard files hidden, skip to 5. Otherwise. Open the file with "sudo gedit /.hidden".

4. Remove every directory you don't want to hide from the file. Here's how mine looks like, as an example:

bin
boot
opt
usr
etc
sys
tmp
srv
proc
root
sbin
lib
lost+found
mnt
initrd
dev
debootstrap
var
cdrom
initrd.img
initrd.img.old
vmlinuz
vmlinuz.old
home
media


5. Now, let's create some entries that are easier for new users: select "home" and create a link to link to it (for example, by dragging it and holding <ctrl>+<shift>. Your mouse cursor should show two linked circles when dragging while holding them, if they do you're creating a link). Rename that link to "User Data" or something similar. Do the same with media; rename it to "Drives" or "Media" or what you want. (If the files are already hidden. show them with <ctrl>-<h>.)

6. If you want to have a discoverable way to some or all of the now hidden files, create a folder called "System Data". Create links to all the other files and directories there.

7. You're done! :) Update an open Nautilus with <ctrl>-<r>, or restart it with "killall nautilus".

I attached a screenshot of how it looks like.

Now, some anticipated FAQs:

Q: Won't this royally screw my system?
A: I see no reson why it should. Everything is still in it's original place, only no longer visible by default. It definitely works fine here and on several other Ubuntu installations.

Q: Are there any negative side effects?
A: Not that I know of. From the command line, everything stays the same. If you encounter any problem, please tell me!

Q: I want to access one of the hidden folders. How do I do that?
A: View -> Show Hidden Files. Or press <ctrl>-h

Q: I don't like this! How can I undo it?
A: Simple, just remove the .hidden file. Delete the links you created in step 5 and 6 if you want, or leave them there. Just make sure you don't accidentally delete the original folders. :)

Q: Can I have all the files shown automatically if I have a sudo'd nautilus?
A: Certainly. Make sure that the .hidden file is owned by root (should be automatically), then, in the permissions tab, disallow read access for the owner.

Q: Can I do that .hidden stuff in other directories too?
A: Yes. It's a pretty cool feature.

Q: Are there any limitations to this?
A: Yes, the file selector (ie open dialog) will still show all the files. The .hidden file currently only applies to Nautilus.