Show hidden files and folders within Mac terminal
Categories:
Reveal Hidden Files and Folders in macOS Terminal

Learn how to quickly show and hide hidden files and folders on your Mac using simple terminal commands, enhancing your file management capabilities.
macOS, like other Unix-based operating systems, uses a convention where files and folders starting with a dot (.
) are considered hidden. These files often contain configuration settings or system-level data that users typically don't need to interact with directly. While the Finder offers a keyboard shortcut to toggle their visibility, sometimes you need to manage these files directly from the terminal, especially when working with development environments, system administration, or troubleshooting.
Understanding Hidden Files in macOS
Hidden files and directories are crucial for the proper functioning of your operating system and many applications. Examples include .bash_profile
, .zshrc
, .git
, and .DS_Store
. These files are hidden by default to prevent accidental modification or deletion, which could lead to system instability or application errors. However, developers, system administrators, and advanced users often need to access and modify these files.
flowchart TD A[User Needs to Access Hidden Files] --> B{Why are they hidden?} B --> C[Prevent Accidental Modification] B --> D[Reduce Clutter in Finder] A --> E[How to Access?] E --> F[Finder Shortcut (GUI)] E --> G[Terminal Commands (CLI)] G --> H[Temporary Visibility] G --> I[Persistent Visibility]
Decision flow for accessing hidden files in macOS.
Showing Hidden Files Temporarily
The most common scenario is needing to view hidden files for a short period, perhaps to edit a configuration file or inspect a .git
repository. You can achieve this by modifying a system preference via the defaults
command in the terminal. This change takes effect immediately after restarting the Finder.
defaults write com.apple.finder AppleShowAllFiles -bool true
killall Finder
Command to show hidden files and restart Finder.
Let's break down what these commands do:
defaults write com.apple.finder AppleShowAllFiles -bool true
: This command writes a boolean value oftrue
to theAppleShowAllFiles
key within thecom.apple.finder
domain. This is the preference that controls the visibility of hidden files.killall Finder
: This command terminates all instances of the Finder application. When Finder relaunches automatically, it reads the updated preference and displays hidden files.
Command + Shift + .
(period) in Finder to toggle hidden files on and off. This is often quicker for temporary viewing without using the terminal.Hiding Files Again
Once you've finished your task, it's good practice to hide these files again to maintain a clean and uncluttered Finder view and prevent accidental changes. The process is identical to showing them, but you set the boolean value to false
.
defaults write com.apple.finder AppleShowAllFiles -bool false
killall Finder
Command to hide hidden files and restart Finder.
Listing Hidden Files in Terminal
While the above commands affect Finder's graphical display, you can always list hidden files directly within the terminal using the ls
command with specific options, regardless of your Finder settings. This is often the preferred method for terminal-centric workflows.
ls -a
ls -la
Commands to list all files (including hidden) and long format listing.
Here's what the options mean:
ls -a
: This option tellsls
to list all entries, including those that start with a dot (.
).ls -la
: This combines-a
(all entries) with-l
(long format), providing detailed information such as permissions, ownership, size, and modification date for all files, including hidden ones.
1. Open Terminal
Launch the Terminal application from your Applications/Utilities folder or by searching with Spotlight (Command + Space and type 'Terminal').
2. Show Hidden Files
To make hidden files visible in Finder, paste the following command and press Enter: defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder
3. Work with Files
Perform your necessary operations on the now visible hidden files and folders.
4. Hide Hidden Files (Optional)
Once done, to hide them again, paste this command and press Enter: defaults write com.apple.finder AppleShowAllFiles -bool false; killall Finder
5. List in Terminal
To simply list hidden files in the current directory within Terminal, use ls -a
or ls -la
.