How to restore a hidden file in Time Machine?
To be able to view invisible files…
Late edit
Since Sierra (macOS 10.12) you can use shift ⇧ cmd ⌘ . to toggle visibility. You only need the old AppleShowAllFiles
trick if you want to make the change permanent.
Open Applescript Editor, in Applications > Utilities then copy/paste this to a new script...
Since El Capitan the trick of changing view no longer works, so it's back to quitting the Finder
For a method to make this into a Service with key command see
https://apple.stackexchange.com/a/258741/85275
set newHiddenVisiblesState to "YES"
try
set oldHiddenVisiblesState to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if oldHiddenVisiblesState is in {"1", "YES"} then
set newHiddenVisiblesState to "NO"
end if
end try
do shell script "defaults write com.apple.finder AppleShowAllFiles " & newHiddenVisiblesState
do shell script "killall Finder"
return input
Mavericks/Yosemite ought to work with this view refresh version, which was faster & smoother, but it just stopped working at El Capitan...
set newHiddenVisiblesState to "YES"
try
set oldHiddenVisiblesState to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if oldHiddenVisiblesState is in {"1", "YES"} then
set newHiddenVisiblesState to "NO"
end if
end try
do shell script "defaults write com.apple.finder AppleShowAllFiles " & newHiddenVisiblesState
tell application "Finder"
set theWindows to every Finder window
repeat with i from 1 to number of items in theWindows
set this_item to item i of theWindows
set theView to current view of this_item
if theView is list view then
set current view of this_item to icon view
else
set current view of this_item to list view
end if
set current view of this_item to theView
end repeat
end tell
Then Save as an application, which you can then just double-click to toggle showing/hiding invisible files.
You don't need to kill the Finder for this toggle, a refresh is sufficient - & may be faster.
Rest assured that Time Machine is backing up your dot-files! You just can't see them by default in Finder. In order to restore a hidden file like .zshrc
you first need to turn off file hiding in finder. You can do this by opening a Terminal window and entering:
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
Now enter Time Machine and navigate to where your hidden files resided. You should be able to restore them from there.
When you've restored all the files you want you can go back to having Finder hide them by entering:
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder
in a Terminal window.
The AppleShowAllFiles pref seems to be gone in High Sierra.
Fortunately, you can now (in Sierra and High Sierra) tell Finder to show you all your "hidden" (dot) files with:
shift ⇧ + cmd ⌘ + .
This works in Time Machine as well.
You can easily access to your hidden file by using the Terminal.
cd /Volumes/TIME_CAPSULE_DISK_NAME/Backups.backupdb/YOUR_BACKUP/Users/YOUR_NAME
ls -la