8

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?

1 Answers1

15

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.

  • 1
    Excellent, I was looking for the latter, but the first option is also good to know. Not sure if the sudo is strictly necessary though. – Markus Schanta Apr 09 '16 at 09:38
  • 1
    It depends, really. chflags works if you're the owner of the file, and if you're not, then sudo is necessary. – perhapsmaybeharry Apr 09 '16 at 09:43
  • Would have accepted anyway, just needed to wait for the 10 minute lag to pass. Don't have enough reputation to upvote yet. – Markus Schanta Apr 09 '16 at 10:12
  • 1
    Also note, adding a alias to .bash_profile is generally a good idea. I have showall and hideall set to hide/show dotfiles. –  Apr 09 '16 at 16:36
  • 2
    I ran into a case where chflags nohidden didn't work, but what did work was xattr -c /path/to/file. It was the Finder info extended attribute that was hiding the file. – JWWalker Oct 01 '18 at 15:01
  • @JWWalker Thank you! Your xattr -rc /path/to/folder/* (changing all hidden files & folders) is what ended up working for me on my MacBook Pro Mojave 10.14.2 chflags wasn't working. – JayRizzo Jan 06 '19 at 05:22