We all have private content stored on our laptops or external drives. Would you like that content to fall into the wrong hands? I sure don’t want that to happen, so I hide and protect my private files and folders.
Hiding Files and Folders
There are two main methods of hiding files and folders in MacOS.
Method 1 – Prefixed with a dot
This is my preferred method of hiding files and folders. It’s very convenient and can be easily done in Finder by renaming the file or folder with the dote prefix.
As in all Unix/Linux systems, a file starting with a dot is generally hidden in desktop managers (thus, Finder) and “normal” folder listings done through a shell (ls
). Listing a folder’s contents with ls -a
however reveals those files.
For example, a normal listing:
charon:portal werner$ ls -l
total 56
-rw-r--r--@ 1 werner staff 920 Aug 17 12:58 Gemfile
… and with the “all” option:
charon:portal werner$ ls -la
total 96
drwxr-xr-x 25 werner staff 850 Sep 14 16:08 .
drwxr-xr-x@ 9 werner staff 306 Jun 15 14:57 ..
-rw-r--r--@ 1 werner staff 12292 Sep 20 15:46 .DS_Store
drwxr-xr-x 15 werner staff 510 Sep 28 22:24 .git
-rw-r--r-- 1 werner staff 51 Aug 17 13:38 .gitignore
-rw-r--r--@ 1 werner staff 920 Aug 17 12:58 Gemfile
The Finder in OS X can also show files and folders that were hidden by the dot prefix by entering:
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
This can be reversed by exchanging TRUE
to FALSE
, obviously.
Method 2 – Changing the “hidden” flag
You can change the “hidden” flag of a file or folder by using the following commands:
chflags hidden some-file
chflags nohidden some-file
Hiding a file with flags will, as above, obviously only hide it from Finder itself. You will still be able to see the file with ls
. If you want to see which are really hidden, you can check these flags with ls -lO
:
charon:~ werner$ ls -lO
total 0
drwxr-xr-x 11 werner staff - 374 May 13 16:43 Binaries
drwx------+ 8 werner staff - 272 Sep 30 09:48 Desktop
drwx------+ 10 werner staff - 340 Sep 25 21:38 Documents
drwx---r-x+ 11 werner staff - 374 Sep 30 15:46 Downloads
drwx------@ 18 werner staff - 612 Sep 30 14:02 Dropbox
drwx------+ 53 werner staff - 1802 Sep 29 20:04 Library
drwx------+ 6 werner staff - 204 Sep 25 21:38 Movies
drwx------+ 8 werner staff - 272 Sep 25 21:38 Music
drwx------@ 12 werner staff hidden 408 Sep 26 10:31 Pictures
drwxr-xr-x+ 6 werner staff - 204 Sep 25 21:38 Public
drwxr-xr-x@ 5 werner staff hidden 170 Sep 25 21:38 Sites
This will show “hidden” on all files hidden from Finder.
Of course, you can still open any of these files.
- Through the terminal, by typing
open some-file
- In Finder, going to Go » Go to Folder …, and entering the full path.
There is no “real” way to hide a file forever or even hide it from the shell. At least for a user without access to a shell, these would be invisible.
Encrypting Files and Folders
You can easily encrypt a file or folder on your Mac without any additional tools. The way to do this is using Disk Images.
An encrypted disk image works just like a regular disk image but requires a password to open and become available (“mount”). You can move files to or from an encrypted disk image as easily as you can from a non-encrypted disk image. Follow these steps to create an encrypted disk image:
- Open Disk Utility (found in
/Applications/Utilities/
). - Select File → New → Disk Image from Folder… or press ⌘ cmd+⇧ shift+N.
- Select the folder that contains your files and press Image.
- Choose the Image Format. If you won’t be making changes to this image choose read-only or compressed (smallest file size). If you will eventually add files to this image you can go with read/write (resulting image file will be much bigger). I usually go for compressed.
- Choose the level of encryption you require (I go with 128-bit).
- Choose a password to encrypt the image. Make sure to uncheck the Remember password in my Keychain box if you want to be prompted each time you attempt to mount the disk.
- Click OK. Disk Utility will create a sparse bundle to hold your files. Don’t forget to delete the original folder.
You can make an alias (or a symbolic link, symlink for short) to folders in the encrypted folder to hide much of the difference between a disk image and the actual encrypted folder if desired. Alternatively, you can mount this disk image in a custom folder (instead of /Volumes) for even smoother access.
A Note on Image Formats
Read-only disk images cannot be modified without invalidating the built-in checksum, therefore they are a good container for storing archived material. Whether to choose read-only versus read-only compressed comes down to time and space. If your destination is tight on space and you have a bit of extra time, you can compress the disk image. Compression rates vary on the content of your source, but you can typically expect to reduce the size of your disk image by about half when using compression.
Another way of saying it:
- Read/Write – Allows you to add and remove files from the image, which treats it as a standard external disk of a fixed size.
- Read-only – This is for creating a disk image from the contents of a folder or another disk, and packages them so they cannot be modified. This is useful for distributing files to groups of people.
- Compressed – This option compresses the image and data on it as much as possible. The image will grow as you add files to it, but at an unpredictable rate since compression efficiency will be different for different files you add.
Using Software to Hide and Encrypt Files and Folders
There are some apps that attempt to make the process of hiding files and folders simpler, however, I wouldn’t trust them. First of all, who’s to say whether they will be around in 10 or 20 years time when I might need to unhide a folder that was hidden using the proprietary techniques of this software package? Secondly, they are usually not as secure as using the tools that ship with the OS itself.
Leave a Reply