5 Ways to Read and Edit Hidden Files or Dotfiles on Your Mac

As developers, we often need to create, read, and edit dotfiles. Any file or folder whose name starts with a period (dot) is automatically hidden from the Finder, and when listing a folder’s contents with ls in the Terminal.

macOS also hides certain directories, like ~/Library and ~/Trash. This makes sense since you don’t typically want to look at those hidden files and directories all the time.

There are times, though, when you need quick access to a hidden file. Below are five ways to interact with hidden files on macOS:

Finder Keyboard Shortcut

You can toggle hidden files on and off by holding down the three keys shift-command-period at the same time in any Finder window. This setting will apply across all your Finder windows. Once you can see the hidden files, then double-click to open them.

For an even faster way to view a hidden file, install the QLStephen Quick Look plugin. This assumes you already have Homebrew installed.

brew cask install qlstephen
xattr -d -r com.apple.quarantine ~/Library/QuickLook
killall Finder

Open a new Finder window, press shift-command-period to show hidden files if they’re not already there, and now you should be able to read a hidden file by selecting it and pressing the space bar.

Reading from Terminal

To view hidden files in a particular directory, add the -a flag to ls:

ls -a

To list files one per line, add the -l flag:

ls -la

To read a particular file, use cat or less:

cat ~/.zshrc

cat will print out the entire contents of the file, whereas less will show one page at a time. Press the space bar to view more pages, and q to quit.

For a more pleasant reading experience, with formatting and syntax highlighting, try bat:

brew install bat
bat ~/.zshrc

Editing in Terminal

To edit directly in the Terminal, macOS comes out of the box with nano, pico, vi, vim, and others :

vi ~/.zshrc

To exit vi or vim, type :q. To exit nano and pico, type shift-control-x.

If you want to quickly add a single line to an existing file, you can use the echo command and the >> operator:

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

The echo command takes everything between the single quotes and adds it (>>) to a file called .zshrc in your user’s home folder (~/).

Opening in a text editor from the Terminal

To open a file in TextEdit, use the open command:

open ~/.zshrc

To open in a different text editor, specify the app with the -a flag:

open ~/.zshrc -a "Sublime Text"

To speed up opening files from the Terminal in your preferred text editor, add an alias to your shell file. If you’re using zsh, you would put it in ~/.zshrc. If you’re using bash, put it in ~/.bash_profile. If you’re not sure, read my guide to find out which shell you’re using.

For fish (my preferred shell currently), put it in ~/.fish_aliases, then add source ~/.fish_aliases to your ~/.config/fish/config.fish.

alias s='open -a "Sublime Text"'

After you restart your Terminal, you can now open files in Sublime Text with s ~/.zshrc, or the entire current directory with s .

From within an app

Open a file with the File->Open menu item, then when you see the macOS window to pick a file, press shift-command-period to toggle hidden files on and off.

There you have it. If you enjoyed this post and learned something new, please share it. Let me know on Twitter if you use other ways to interact with hidden files that I should mention.