Working with hidden files on the Mac
Files are hidden to protect them from accidental editing and deletions. For the most part of your computing experience you won’t need to bother with them, but there can be situations when you have to — this guide is for those situations.
There are 2 ways to work with hidden files on the Mac. The first is to set the “AppleShowAllFiles” to “TRUE” then view them in Finder. The second is to use Shell–Bourne Again Shell or bash as it is known among UNIX users–and use command line utilities to display and manipulate files. Both methods require the use the Terminal.app and some typing of commands.
Launch the Terminal.app right now, it’s inside the Applications/Utilities folder. Alternatively, you can use Spotlight, simply CMD + press space bar, then type Terminal.
How to work with hidden files
Open the Terminal.app — just press the command key (the clover) together with the space bar, then type Terminal
$ cd ~
$ open .
The first command ( cd ~ ) takes you to your home directory, the tilde is a shortcut to /Users/yourHomeDir. The second, launches Finder to open in current directory (your home directory). Take notice of the files you see, just regular files right? You can’t see the .profile , .DS_Store and .Trash.
Try the next exercise to make the hidden files visible in Finder
$ cd ~
$ defaults write com.apple.Finder AppleShowAllFiles TRUE
$ killall Finder
$ open .
The “defaults” command accesses the User defaults of OSX from the shell. It can read, write and delete OSX user settings. This example accesses the Finder settings (stored in com.apple.Finder), searches for the key “AppleShowAllFiles” and set it’s value to “TRUE” you can also put “YES” if you like, that will work too. The next command “killall Finder” is another command line utility that is equivalent to “Force Quit” if you were using GUI. The “open .” command launches the Finder application then shows the contents of the current folder.
To hide files in Finder, follow the same procedure but change the value of AppleShowAllFiles.
$ cd ~
$ defaults write com.apple.Finder AppleShowAllFiles FALSE
$ killall Finder
$ open .
Using the shell
The other way of working with hidden files is to use the shell to manage all files. The following example commands will create a hidden file, and launch them straight from the command line.
$ cd ~
$ touch .myhiddenfile.txt
$ open .
$ ls
$ ls -a
$ open .myhiddenfile.txt
The only command necessary to create files is the “touch” command — you can learn more about the touch command by typing “info touch” from the command line.
ls (the UNIX list command) will list all the files and folders in the current directory, but it will not list the hidden files — “ls -a” will show you all the files including the hidden ones. The “open .myhiddenfile.txt” line will launch TextEdit and open .myhiddenfile.txt
Leave a comment