Show the Hidden File on Mac OS

Sometimes we might need to edit the hidden file on Mac such as the configuration file but we don't know the path of this file. Therefore, letting the computer shows the hidden file allows us to locate and edit this file more convenient. This post would introduce two ways to show the hidden file on Mac.

(1) Enter the command of show / hide hidden file

We can directly enter the following commands on terminal to show or hide all the hidden files.

1
2
3
4
# Show the hidden files
defaults write com.apple.finder AppleShowAllFiles -boolean true;killall Finder
# Hide the hidden files
defaults write com.apple.finder AppleShowAllFiles -boolean false;killall Finder

(2) Create the SH file that contains the two commands above, and use the file to show / hide the hidden files

The commands above is so long that it's hard to remember and type it correctly. Hence, we can store them in the SH file, and each time we run the SH file can also achieve the same effect.

1
2
3
4
5
6
7
8
9
10
11
# Create the SH files 
touch show_hidden_file.sh
touch hide_hidden_file.sh

# Write the show_hidden_files_command into show_hidden_file.sh
# Write the hide_hidden_files_command into hide_hidden_file.sh

# Show the hidden files
./show_hidden_file.sh
# Hide the hidden files
./hide_hidden_file.sh