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?

0

1 Answer 1

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.

6
  • 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. Commented Apr 9, 2016 at 9:38
  • 1
    It depends, really. chflags works if you're the owner of the file, and if you're not, then sudo is necessary. Commented Apr 9, 2016 at 9:43
  • Would have accepted anyway, just needed to wait for the 10 minute lag to pass. Don't have enough reputation to upvote yet. Commented Apr 9, 2016 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.
    – user173518
    Commented Apr 9, 2016 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
    Commented Oct 1, 2018 at 15:01

You must log in to answer this question.

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