Showing and deleting hidden files (dotfiles) on macOS
If files whose names begin with a dot (.) don't appear in the Trash, macOS is treating them as hidden files. You can list them in Terminal or turn on hidden files in Finder to see them in the Trash.
Method 1: Toggle hidden files with a keyboard shortcut
Open Finder. On the desktop or inside a folder, press:
Shift + Command + .(句点)
This toggles all files and folders whose names begin with a dot (.), including hidden files in the Trash.
Method 2: View and delete files in Terminal (recommended)
-
Open Terminal under Applications > Utilities.
-
Enter this command to list all files in the Trash, including hidden ones:
ls -a ~/.Trash/
- To delete a particular hidden file, such as
.myHiddenFile.txt, enter:
rm ~/.Trash/.myHiddenFile.txt
Remember to include the leading
..
- If the file is in a subfolder, such as
~/.Trash/.config/myHiddenFile.txt, enter:
rm ~/.Trash/.config/myHiddenFile.txt
Warning:
rmpermanently deletes files without sending them to the Trash. Use it with care.
Method 3: Restore a file to its original location in Finder
If you just want to recover a file:
- Press
Shift + Command + .to show hidden files. - Find the file.
- Right-click it and choose “Put Back.”
The file will return to its original location.
Tips
- Many system and configuration files, including
.DS_Store,.bash_profile, and.zshrc, begin with a dot and are hidden by default. - When emptying the Trash, hold down
Optionas you click Empty to delete the files permanently and skip the confirmation dialog.