Show and Hide Hidden Files in Terminal

Published on Feb 7, 2015

One useful part of owning a Mac is the ability to quickly show and hide hidden files so that you can make quick adjustments. For my own workflow that meant starting a Google search for "Show Hidden Files on Mac" all the time when I needed to see and edit a hidden file, then open a terminal window and paste the command that they provided on the page in order to complete that particular workflow. Not the best and quickest solution I know. So at one point I figured that I would set up an alias for both showing and hiding files quickly using terminal with commands that I could remember easily.

Setting up a Terminal Alias to Show/Hide Hidden Files

A Terminal alias is a shortcut in that allows a user to run one or many commands easily. There are permanent or temporary types of alias and for this case we are going to setup a permanent alias.

  1. Open Terminal, which is found in Finder > Applications > Utilities

  2. In your Terminal, paste this: sudo nano ~/.bash_profile

  3. Enter your user password, if it requests one in the terminal, then hit enter.

  4. At the end of the .bash_profile, paste the following two commands:

    • alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder'

    • alias hideFiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder'

  5. Press ctrl + O and hit return to save the changes.

  6. Press ctrl + X to exit the file and return to the command line.

You can either refresh your Terminal window to accept the new changes you made or you can close and open another Terminal window. To refresh your Terminal window paste this: source ~/.bash_profile and hit return.

You should now be able to show and hide hidden files with the alias you inserted above: showFiles and hideFiles. This will allow you to easily show hidden files to make an edit to a file or to hide them to clean up the directory listings so you don't have to see everything all the time.

Justin Hough author picture
Justin Hough

Chief Development Officer at Hounder. He is a Christian, husband, father, writer, developer, designer, and a digital carpenter crafting amazing web experience. Also, created the Centurion Framework many moons ago.