Introduction

As in Windows, by default MacOS doesn’t show hidden files, but unlike Windows that has a straight forward ‘Hidden Items’ option in the File Explorer View ribbon menu, MacOS doesn’t make it easy to toggle hidden files view on and off.

To do so you need to run a Terminal command.

Terminal Commands

From Applications > Utilities folder launch Terminal 

To show hidden files, enter following which will show hidden files then restart Finder:

defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder

To hide hidden files, enter following to revert to hiding hidden files then restart Finder:

defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder

Create aliases for Terminal commands

If you don’t want to remember the above commands, you can easily create a Terminal alias

This is a direct lift from Ian Lunn’s blog. Ian explains the procedure and what commands are used to create a Terminal alias replacing the command lines above with easy to remember ‘showFiles‘, ‘hideFiles‘ commands:

  • From Applications > Utilities folder launch Terminal
  • In Terminal, enter sudo nano ~/.bash_profile and hit Return
  • Enter your Mac’s administration password if required, then hit Return
  • At the bottom of the open .bash_profile file, enter two new lines:
alias showFiles='defaults write com.apple.finder ~AppleShowAllFiles YES; killall Finder /System/Library/~CoreServices/Finder.app'
alias hideFiles='defaults write com.apple.finder ~AppleShowAllFiles NO; killall Finder /System/Library/~CoreServices/Finder.app'
  • Press Ctrl+O and hit Return to save the file
  • Press Ctrl+X to exit the file and return to the command line
  • In Terminal, enter source ~/.bash_profile hit Return – this will refresh your profile and make the aliases available

Now when you want to show hidden files, all you need to do is open Terminal and enter showFiles. Enter hideFiles to revert to default and hide them

Creating Finder context menu item

To expand on this, Bert van Langen’s blog explains how you can use Automator with the commands outlined above to create a new Finder context menu item allowing you to toggle hidden files on and off directly from Finder:

  • From Applications folder launch Automator
  • Select Service as template type and click the Choose

  • In actions list, click Run Shell Script and drag it to the workflow pane. (Filter actions list by selecting Utilities from Library, or use the search menu)
  • At the top of the workflow pane set Service receives selected to files or folders and set in to Finder
  • Enter following into the Run Shell Script (replacing anything already there)
#!/bin/bash
#
# Script to toggle hide/unhide hidden files in the Finder application.
#
# Author : Bert van Langen
# Created : 21 December 2014
#
STATUS='defaults read com.apple.finder AppleShowAllFiles'
if [ $STATUS == 1 ]
then
defaults write com.apple.finder AppleShowAllFiles -boolean false
else
defaults write com.apple.finder AppleShowAllFiles -boolean true
fi
killall Finder
  • From File menu, select Save and then give the service a name – the name you select will appear as the menu item – e.g. Toggle Hidden Files. (Will be saved to /Users/Yourlogon/Library/Services)
  • Quit Automator

When you bring up the right-click context menu in Finder you will now see the new item Toggle Hidden Files which will execute the script to show/hide hidden files and restart Finder.