OS X

How To Hide Folders Using Terminal

Terminal Icon

Occasionally it may be desirable to hide a folder on your Mac’s filesystem, either to keep it away from prying eyes or simply because it’s better not to be able to view some folders that could easily be removed or deleted by accident.

Finder doesn’t have any built-in ways to hide a folder (i.e. with a simple keyboard shortcut or from the Get Info window), and so the recommended method is within Terminal using the chflags command. This tutorial describes how to hide any file or folder in seconds.



Hide a Folder

Follow these steps to hide any folder or file:

1. Open Terminal from the Applications -> Utilities folder or using Spotlight

2. At the Terminal command prompt, type this followed by Enter:

  • chflags hidden <filename or folder>

The folder specified and all it’s contents will disappear from view in Finder, but it’s important to note that the files are still there and have not been deleted. If the filename contains spaces, you may need to put quotes around it, for example:

  • chflags hidden "~/Documents/Hide This Folder"

Rather than type in the whole file path, it’s also possible to enter the chflags command and then drag the file or folder into the open Terminal window which completes the file path for you. This just speeds up the process of entering the file path manually.

Hide Folder
Use the chflags hidden command to hide a folder

It may be necessary to enter the chflags command as the super user if you’re not already logged in as root. To do this, use the sudo command (the “super user do command”) and enter the root password when prompted.

  • sudo chflags hidden <filename or folder>

The chflags command can be used to change many properties about files. For more complete details on chflags, just type in man chflags at the command prompt to display the manual pages.

Unhide a Folder

Once your folder has been hidden, you might be wondering how to view it again. The simplest way is to use the same terminal command with the nohidden flag as follows:

  • chflags nohidden <filename or folder>
Unhide Folder
Chflags with the nohidden option will unhide a folder

This makes the file reappear in Finder and resets its visibility back to normal.

Automator IconUsing Terminal With Automator

Every time you want to hide or unhide a folder, you could open Terminal and type in the chflags command. However, another perhaps more convenient method is to use Terminal to build an Automator workflow. This lets you create a small app that you can drag and drop files onto to hide, or even as a service to act on Finder items.

One approach to create an application is as follows:

1. Open up Automator and choose workflow to create a new workflow

New Automator Workflow
Open Automator and create a new workflow

2. In the Actions pane, search for the Get Specified Finder Items item and drag it to the main window

3. In the Actions pane, search for the Run Shell Script item and drag it to the main window

4. In the Run Shell Script item, change the Pass input menu to as arguments

5. In the Run Shell Script item, enter the following script commands:

for f in “[email protected]”; do
chflags hidden “[email protected]
done

Your workflow should look like this:

Edit Workflow
Your workflow contains the commands to hide any files passed to it

6. Save the workflow as an application and enter a suitable filename. Your new application will be saved with an Automator icon. You could also save it as a service which would be available in Finder’s Services menu item

Save Workflow As App
Save your workflow as an app

7. Now just drag and drop any files onto the Automator app icon to hide them. To unhide them, obviously you can’t drag and drop files already hidden from Finder so you’ll have to unhide them manually with the chflags nohidden command from Terminal instead

Application Icon
Your new app

How To Speed Up Your Mac Easily With CleanMyMac 3

There is no better tool for cleaning your hard drive from junk than CleanMyMac 3. While some speed issues on the Mac simply cannot be resolved but using an app, many that can are covered in this comprehensive cleaning utility.

But that's not all CleanMyMac 3 can be also clean up after uninstalling app and can remove temporary files, plugins, redundant files and offers better management of start up items and much more. It’s a utility that should have been built into macOS from the beginning.

Download CleanMyMac 3 for Free Now!

About the author

Roland Banks

I've been passionate about Apple ever since I bought my first iPod followed by a white polycarbonate MacBook in 2007. I currently own a MacBook Pro Retina, an iPad Mini Retina, and an iPhone 6.

Add Comment

Click here to post a comment

Leave a Reply

Related Posts