5 Ways to Read and Edit Hidden Files on Your Mac

As developers, we often need to create, read, and edit dotfiles. Any file whose name starts with a period is automatically hidden from the Finder, and when listing files 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.

1. 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.

2. 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

3. 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.

4. 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. 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 .

5. 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.