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'Create a bin folder in your home directory and hide it from Finder.
mkdir ~/bin
hide ~/binShow the folder in Finder again.
show ~/binFiles 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 |................|
00000020The 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.