I copied a lot of read-only files from a Windows system to my Mac. When viewing the Info for each file using "Get Info", I can see they are Locked. I'm writing a bash script to copy over some files and I'm getting an error that says "Operation not permitted" So, first I need to unlock the files. Since I'll be pulling files from the Windows system often, I want my script to unlock these files.

What is the terminal command to unlock "Locked" files on OSX?

link|improve this question

53% accept rate
feedback

2 Answers

up vote 11 down vote accepted

To unlock files you can use:

chflags -R nouchg /PATH/TO/DIRECTORY/WITH/LOCKED/FILES/
link|improve this answer
1  
Looks like I found the solution just as you were responding. I also learned that the -R is for recursive. So, to unlock all files in the current directory use<br/> chflags nochg *<br/> and to change just one file<br/> chflags nouchg onefile.txt See: mehtanirav.com/2009/04/16/recursively-unlock-files-on-mac-os-x – Michael Prescott Sep 14 '09 at 2:37
@Michael: Trying to use <br/> for a line break? – Hello71 Aug 15 '10 at 23:47
feedback

Along with the chflags solution, you can also use SetFile like so:

/Developer/Tools/SetFile -a L file.ext

Where:

  • the -a switch signifies an attribute change
  • L specifies the lock attribute
link|improve this answer
I also stumbled on this in my searches, but the dependency on Developer tools made me select Chealion's technique. I know nothing about chflags and assume it is universally available on os x systems. – Michael Prescott Sep 14 '09 at 2:39
Yeah once I opened this link there were already 2 other answers posted regarding the chflags solution, so I posted the alternate. – John T Sep 14 '09 at 2:46
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.