On Mac OS, proibably the most command I googled is to show/hide hidden files in Finder. I just could not understand why it cannot simply provide it in the menu of Finder.

Today, I’m going to build it by my own.

Normal Way

Here is the normal way to show hidden files:

  1. Open Terminal app.
  2. In Terminal, do the following command:
    defaults write com.apple.finder AppleShowAllFiles YES
    
  3. Relaunch the Finder app.

And here is how to hide hidden files:

  1. Open Terminal app.
  2. In Terminal, do the following command:
    defaults write com.apple.finder AppleShowAllFiles NO
    
  3. Relaunch the Finder app.

The problem of this “normal way” is the two commands are usaully hard to remember (at least for me :). So in the short way, we will use Terminal Aliases.

Use Terminal Alias

A Terminal Alias is a name or shortcut for one or multiple commands. So by using an easy-to-remember alias, we can simply use ONE command to do all 3 steps shown above.

And here is how.

  1. Open Terminal app.
  2. In Terminal, edit the file .bash_profile under you own home folder.
    vi ~/.bash_profile
    # or 
    nano ~/.bash_profile
    
  3. In the file, add the fllowing two 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'
    
  4. Save the file.

  5. Run the following command to refresh the profile and make the aliases available.

    source ~/.bash_profile
    
  6. Now, you can just use showFiles and hideFiles to show/hide hidden files.

Ok, done.

Peace!!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>