Showing Hidden Files on OS X and Time Machine

Not Perl related, but I suspect some folks may appreciate this.

Today after a nasty mistake on the command line involving find and rm, I discovered that I deleted a number of files I didn't mean to delete, including some hidden files. Oops! I opened my Time Machine backup, only to discover that it doesn't show hidden files. However, it turns out that you can use that to show hidden files so long as your main system shows hidden files. I'm using OS X Mavericks, so I dropped the following bash script into my bin folder and named it togglehidden. Running this from the command line will toggle showing hidden files in the Finder on or off.

#!/bin/bash

is_shown=$(defaults read com.apple.finder AppleShowAllFiles)
if [ $is_shown != "TRUE" ]; then
    echo Showing hidden files
    defaults write com.apple.finder AppleShowAllFiles TRUE
else
    echo Hiding hidden files
    defaults write com.apple.finder AppleShowAllFiles FALSE
fi
killall Finder

Use at your own risk!

2 Comments

For me, anything involving find, xargs and rm gets an echo in front of the rm first!

I always have ShowAllFiles on, because I need to see and edit

.git .gitignore .htaccess .perlcriticrc .perltidyrc

and others. Also I want to see the crap which OSX, Windows and (most) Linux desktop environments (DE) leave in directories. It's a shame for Apple that you need a script for switching this mode. Nearly every other DE let you switch this in the menue 'View'.

BTW: Because of the courious treatment of filenames in OSX special care should be taken (keywords: Case Conservation, Escaping) .

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See http://www.allaroundtheworld.fr/ for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book! http://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840/