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 β€œ$@”; do
chflags hidden β€œ$@”
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

Before you go

After spending over 20 years working with Macs, both old and new, theres a tool I think would be useful to every Mac owner who is experiencing performance issues.

CleanMyMac is highest rated all-round cleaning app for the Mac, it can quickly diagnose and solve a whole plethora of common (but sometimes tedious to fix) issues at the click of a button. It also just happens to resolve many of the issues covered in the speed up section of this site, so Download CleanMyMac to get your Mac back up to speed today.

mac-pc

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.