Hide Files Using Mac Terminal

Hiding files on your Mac can be useful when you want to keep certain files or folders out of view without deleting them. Using the Mac Terminal, you can hide files or directories by changing their attributes, and you can also reveal hidden files when necessary.

In this guide, we’ll show you how to hide files and folders using simple Terminal commands on Mac.

Step 1: Open the Terminal

First, open the Terminal app on your Mac. You can use Spotlight search (Cmd + Space) and type “Terminal.”

Step 2: Hide a File or Folder Using the Terminal

To hide a file or folder, you can use the chflags command. This command allows you to change file attributes, including whether they are visible in Finder. The syntax for hiding a file or folder is:

chflags hidden /path/to/file_or_folder

For example, if you want to hide a folder called PrivateFolder located in your Documents folder, use the following command:

chflags hidden ~/Documents/PrivateFolder
Hide Files Using Mac Terminal

This command will hide the PrivateFolder from view in Finder. The folder still exists, but it won’t be visible unless you specifically unhide it or access it via Terminal.

Step 3: Show Hidden Files in Finder

If you want to see hidden files and folders in Finder, you can reveal them temporarily by using a keyboard shortcut. Open Finder and press Cmd + Shift + . (period). This will toggle hidden files on or off in the current Finder window.

To permanently show hidden files using Terminal, you can use the following command:

defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder

This will show all hidden files in Finder. To hide them again, run the same command, but change TRUE to FALSE:

defaults write com.apple.finder AppleShowAllFiles FALSE; killall Finder

Step 4: Unhide a File or Folder

If you want to unhide a file or folder that was previously hidden, you can use the chflags command with the nohidden option. For example, to unhide the PrivateFolder in your Documents folder, use this command:

chflags nohidden ~/Documents/PrivateFolder

This will make the PrivateFolder visible again in Finder.

Step 5: Access Hidden Files via Terminal

Even if a file or folder is hidden in Finder, you can still access it directly from the Terminal. You just need to know the path to the file or folder. For example, to open a hidden folder called PrivateFolder in your Documents folder, you can use the cd command:

cd ~/Documents/PrivateFolder

You can then interact with the files in the hidden folder just as you would with any other directory.