SetFile -- set attributes of files and directories
There are a number of methods used to hide files in the Finder.app and from the end user in Mac OS X. I would only suggest using two: Unix style "preceding dot" naming system and setting the invisible attribute in the file's meta information.
The Unix method is very easy and survives cross-platform migration but isn?t nearly as neat or functional for the GUI as the meta attribute method. Plus I'm an Apple slut so I wanted to know how the meta solution worked.
Unix style
The Unix style of hiding files from general browsing is to begin the file or directory name with a period (E.g. .htaccess or .bash_profile). This will, by default, hide the file or directory from the Finder.app AND the ls list command (unless the -a flag is passed) on most if not all *nix systems.
This is useful for files and directories that are not normally accessed by either GUI uses in the Finder.app or from command-line uses. The .bash_profile file contains environmental setting for a System-user that does not need to be touched often but does need to be contained in the home directory for the user. These files can be viewed on the command-line as well as in the Find.app but the default setting need to be altered to allow this Viewing the files on the command-line is allowed by using the -a flag via the command-line:
$ ls
Desktop Library Pictures
Documents Movies Public
Downloads Music Sites
$ ls -a
. .dvdcss Documents Pictures
.. .python-eggs Downloads Public
.DS_Store .ssh Library Sites
.Trash .viminfo Movies
.bash_profile Desktop Music
Viewing 'dot' files in the Finder.app requires the preference file for the Finder.app to be altered and Finder.app to be relaunched. This can be accomplished by the following commands:
# SHOW 'dot' files in Finder.app
$ defaults write com.apple.Finder AppleShowAllFiles YES
$ killall Finder
# HIDE 'dot' files in Finder.app
$ defaults write com.apple.Finder AppleShowAllFiles NO
$ killall Finder
SetFile meta information
The more interesting and Mac-centric approach is to set the invisibility attribute for the meta of the file. This is how much of the BSD underbelly of Mac OS X is now hidden from the GUI users but without requiring a major rewrite and thereby causing incompatibility of the Unix arm of the system to other *nix systems and applications.
An example of some standard directories are /etc, /var, and /usr. These are directories found on every *nix system but hidden from the Finder.app because they would only cause confusion and most-likely, deletion by users not 'in the know'. The tool need for setting attributes of files and directories is part of Apple's Developer tools and located here: /Developer/Tools/SetFile.
Directories (folders) can be set as invisible by using the correct options for SetFile:
# Show '/private' in the Finder.app
$ sudo SetFile -a "v" /private
# Hide '/private' from the Finder.app
$ sudo SetFile -a "V" /private
SETFILE(1) BSD General Commands Manual SETFILE(1)
NAME
/usr/bin/SetFile -- set attributes of files and directories
SYNOPSIS
/usr/bin/SetFile [-P] [-a attributes] [-c creator] [-d date] [-m date]
[-t type] file ...
DESCRIPTION
/usr/bin/SetFile is a tool to set the file attributes on files in an HFS+
directory. It attempts to be similar to the setfile command in MPW. It
can apply rules to more than one file with the options applying to all
files listed.
Flags:
-P Acts on a symlink file instead on the file the symlink resolves to.
-a attributes Sets the file attributes bits where attributes is a string
of case sensitive letters. Each letter corresponds to a
file attribute: an uppercase letter indicates that the
attribute bit is set (1), a lowercase letter indicates
that it is not (0). Note: attributes not specified remain
unchanged.
A | a Alias file
B | b Has bundle
C | c Custom icon (allowed on folders)
D | d Located on the desktop (allowed on folders)
E | e Extension is hidden (allowed on folders)
I | i Inited - Finder is aware of this file and has
given it a location in a window. (allowed on
folders)
L | l Locked
M | m Shared (can run multiple times)
N | n File has no INIT resource
S | s System file (name locked)
T | t "Stationery Pad" file
V | v Invisible (allowed on folders)
Z | z Busy (allowed on folders)
-c creator Specifies the file's creator, where creator can be a
string of four MacRoman characters, an empty string ('')
designating a null creator, or a binary, decimal, octal,
or hexadecimal number in standard notation (e.g.
0x52486368).
-d date Sets the creation date, where date is a string of the
form: "mm/dd/[yy]yy [hh:mm:[:ss] [AM | PM]]" Notes:
Enclose the string in quotation marks if it contains spa-
ces. The date must be in the Unix epoch, that is, between
1/1/1970 and 1/18/2038. If the year is provided as a two-
digit year, it is assumed to be in the 21st century and
must be from 00 (2000) through 38 (2038).
-m date Sets the modification date where date is a string of the
form in -d above. (mm/dd/[yy]yy [hh:mm:[:ss] [AM | PM]])
-t type Sets the file type, where type can be a string of four
MacRoman characters, an empty string ('') designating a
null type, or a binary, decimal, octal, or hexadecimal
number in standard notation (e.g. 0x55455955).
RETURN VALUES
0 attributes set
1 syntax error
2 any other error
SEE ALSO
GetFileInfo(1)
EXAMPLES
This command line sets the modification date of "myFile":
SetFile -m "8/4/2001 16:13" myFile
Mac OS X January 4, 2009 Mac OS X
K
Command-Line