32

I accidentally deleted my ~/.zshrc file and I'd like to get it back from a Time Machine backup. When I enter Time Machine I can see my home directory, but all the dot-files in the directory are hidden in the Finder window displayed by Time Machine.

How can I restore a hidden file like ~/.zshrc using Time Machine?

4 Answers 4

24

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.

5
  • 1
    The window redraw has the same effect as a Finder restart FWIW. I wouldn't say it's faster, but having the ability to detect and toggle state is nice.
    – Ian C.
    Commented Dec 20, 2014 at 21:50
  • I used to find the Finder sometimes took a few seconds to come back up [though I used to have HD not SSD, so that might be the difference]
    – Tetsujin
    Commented Dec 21, 2014 at 8:04
  • This did not work for me. Ian C.'s suggestion below however, did work. Commented Jun 13, 2017 at 11:05
  • 1
    @DarrellGolliher - this worked at the time, it doesn't since El Capitan. Here's the other version - apple.stackexchange.com/a/258741/85275 & how to set it to a key command too.
    – Tetsujin
    Commented Jun 13, 2017 at 17:25
  • thank you so much... this works in big sur (the cmd-shift-period solution). was just able to restore a much needed old chrome bookmarks backup from the hidden Library folder. Commented Jan 19, 2021 at 4:08
31

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.

27

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.

3
  • 5
    This works in MacOS Catalina as of 2020.
    – Rob
    Commented Jan 22, 2020 at 15:39
  • And, also as of 2020, this works on macOS Big Sur 11.0 Beta (20A5384c) — and very likely will work on the final version as well! Commented Oct 9, 2020 at 17:16
  • AppleShowAllFiles doesn’t have to be present. This default writes works on every version of macOS (even up to Monterey) but it is not needed anymore with the key combination.
    – lbutlr
    Commented Jun 5, 2022 at 16:19
10

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
3
  • 4
    It is a sad fact that this seems to be by far the simplest way. Thank you for this brief moment of sanity Commented Mar 27, 2016 at 14:36
  • Unfortunately this doesn't work for me: cd /Volumes/TIME_CAPSULE_DISK_NAME/Backups.backupdb/ ls -lra . ERROR: ls: .: Operation not permitted Any idea?
    – Matthias M
    Commented Oct 30, 2020 at 14:06
  • I don't see anything that looks like a TIME_CAPSULE_DISK_NAME in my /Volumes directory. Can you give an example of what such name would look like? Ditto for YOUR_BACKUP and YOUR_NAME. Thanks. Commented Aug 20, 2022 at 23:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .