Skip to content

Instantly share code, notes, and snippets.

@liamnewmarch
Last active November 8, 2021 16:26
Show Gist options
  • Save liamnewmarch/c60687072d7a40e7a7649117e393eb44 to your computer and use it in GitHub Desktop.
Save liamnewmarch/c60687072d7a40e7a7649117e393eb44 to your computer and use it in GitHub Desktop.
Show and hide files and folders in macOS Finder

Aliases

Copy the following lines into your terminal to register the hide and show aliases.

alias hide='xattr -w -x com.apple.FinderInfo "$(xattr -p -x com.apple.FinderInfo ~/Library)"'
alias show='xattr -d com.apple.FinderInfo 2> /dev/null'

Usage

Create a bin folder in your home directory and hide it from Finder.

mkdir ~/bin
hide ~/bin

Show the folder in Finder again.

show ~/bin

Explanation

Files in a macOS HFS+ filesystem can have extended attributes. These attributes are used for storing meta information about the file and can be read and written with the xattr command.

Every macOS user has a folder in their home directory called Library, this folder is hidden from Finder because it contains files which shouldn’t be modified by the user. We can use xattr to inspect the extended attributes of this folder:

$ xattr -l ~/Library
com.apple.FinderInfo:
00000000  00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00  |........@.......|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000020

The hide alias works by copying the com.apple.FinderInfo extended attribute from ~/Library to another file. The show alias works by deleting this extended attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment