Change a file or folder's flags.
chflags [-R [-H | -L | -P]] flags file ...
Examples
➜ Downloads $ cp download.dat no_delete
cp: no_delete: Operation not permitted
➜ Downloads $ cp ls -lOe no_delete(Capital O, not number 0)
-rw-r--r-- 1 operator1 staff uchg 0 5 26 19:44 no_delete
➜ Downloads $
➜ Downloads $ chflags nouchg no_delete
➜ Downloads $ cp download.dat no_delete
➜ Downloads $
Examples
Lock the folder "finance" against changes:
$ chflags uchg finance
Unlock the folder named "finance" and allow changes to all the contents:
$ chflags -R nouchg finance
Make the folder ~/Library visible (this was the default setting prior to OS X Lion )
$ chflags nohidden ~/Library
(An alternative method is to use the 'Go' drop down menu in Finder and hold down the option key.)
Hide the folder ~/Library from finder:
$ chflags hidden ~/Library
Make the file MyLogs.txt append-only:
$ chflags uappnd MyLogs.txt
Unlock your Documents directory and everything in it:
$ chflags -R nouchg ~/Documents
Keywords and keyword aliases - Owner or Super-user only:
opaque set the opaque flag
nodump set the nodump flag
uappnd, uappend set the user append-only flag
uchg, uchange, uimmutable set the user immutable flag
uunlnk, uunlink set the user undeletable flag
Keywords and keyword aliases - Super-user only:
arch, archived set the archived flag
sappnd, sappend set the system append-only flag
schg, schange, simmutable set the system immutable flag
sunlnk, sunlink set the system undeletable flagThe immutable flag makes the file/folder Locked/Protected and is equivalent to locking the file in Finder's Show Info box.
Putting the letters no before an option causes the flag to be turned off.
For example:
uchg Means the file cannot be changed
nouchg Means the file can be changed (immutable bit cleared)
hidden Will set the hidden flag
nohidden Will remove the hidden flag