Unhide invisible files from the command line

By default, a number of system directories (such as ~/Library) are hidden in OS X (ie. they don't appear in Finder):

Library Folder

I know I can do this through the GUI but I would like to add a script to my dotfiles that does this automatically for certain system directories.

Is it possible to remove the hidden flag for a file/directory from the command line?


For files hidden by prepended .

To show:

defaults write com.apple.finder AppleShowAllFiles YES; killall Finder

To hide:

defaults write com.apple.finder AppleShowAllFiles NO; killall Finder

edit: as per RikerW's advice, to shorten these long strings into some shorter strings, add the following line to ~/.bash_profile from your favorite text editor:

alias showall='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder'
alias hideall='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder'

do note that you will have to do source ~/.bash_profile to update your shell with the new aliases.


For files hidden from the GUI:

To show:

sudo chflags nohidden /path/to/file

To hide:

sudo chflags hidden /path/to/file

Do bear in mind that this completely removes the hidden flag.