Simple command to show or hide hidden files on Mac OS X

If you have ever come across a need to have Mac OS X show the files starting with a dot (.) in your GUI, you may have found the command to do it, only to forget it later. Instead of remembering the command, why not just create a logical shortcut that does the job for you?

In my case, I have created two new commands on my system:

show-hidden
hide-hidden

 

Here’s how to set this up:

Add the following three lines to your ~/.profile file (you can use vim or nano):

# Hide or Show hidden files in the OS X file system
alias show-hidden='defaults write com.apple.finder AppleShowAllFiles YES && killall Finder'
alias hide-hidden='defaults write com.apple.finder AppleShowAllFiles NO && killall Finder'

If you do not know the command to edit your ~/.profile file, here’s what you can use (I’m giving the nano example since most find nano easier to use than vim):

nano -w ~/.profile

When you are done, save the file and quit the editor with the following keystrokes (control + o, enter, and control +x):

[ ctrl + o ], [ enter ], [ crtl + x ]

Source your ~/.profile file:

source ~/.profile

Test it out:

  • Open your finder window and navigate to your home directory. You should see no hidden files unless you have previously executed the commands to make them show.
  • Run the following commands in any order you wish, any time you want and they will control wether hidden files show up or not (if you watch your Finder window while you run them, you will see the changes made in real time):
    • show-hidden
    • hide-hidden