# Lock & Unlock Files with the Terminal



## phule (Jan 2, 2011)

Is it possible to lock and unlock files with the terminal and if so, how?


----------



## artov (Jan 3, 2011)

For some reason, OS X has a concept of "locked file". You can lock a file (or directory) by selecting its info screen (CMD-I or File->Info) and then clicking Locked button. Locked file is hard to remove (either rm or move to trash).

To lock or unlock a file in terminal, use *chflags* command. To lock, use



> $ chflags uchg filename



and to unlock, use



> $ chflags nouchg filename


----------



## phule (Jan 3, 2011)

artov said:


> For some reason, OS X has a concept of "locked file". You can lock a file (or directory) by selecting its info screen (CMD-I or File->Info) and then clicking Locked button. Locked file is hard to remove (either rm or move to trash).
> 
> To lock or unlock a file in terminal, use *chflags* command. To lock, use
> 
> ...



THANKS a lot!!!


----------

