Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Unlock locked files from the terminal UNIX
In response to a newsgroup request for a way to unlock files from the command line I wrote this script. Note that it uses developer tools SetFile and GetFileInfo (so you'll need the Dev Tools installed for this to work).

Read the rest of the article for the cut-and-paste script and instructions.

Start a terminal and type these three commands (the stuff after the ">"):

prompt > cd
prompt > mkdir bin
prompt > cat > bin/unlock

Once you've done that, copy and paste the following:


use strict;
my $ask = ($ARGV[0] == "-i");
shift if $ask;
$| = 1;

foreach my $file (@ARGV) {
my $locked = `/Developer/Tools/GetFileInfo -al $file`;
chomp $locked;
next unless $locked;

print "Unlock '$file' ? " if $ask;
if (!$ask or (<STDIN> =~ /^y/i)) {
print STDERR "Unlocking $filen";
print STDERR `/Developer/Tools/SetFile -a l $file`;

##### hit control D here after pasting #####

Now type:

prompt > chmod +x unlock
prompt > rehash

Now you're ready to use it. Call it either with:

unlock filename
unlock filename1 filename2
unlock *


unlock -i *

The "-i" file makes the script interactive, it prompts you to confirm you want to unlock the file.
  • Currently 1.50 / 5
  You rated: 3 / 5 (4 votes cast)

Unlock locked files from the terminal | 3 comments | Create New Account
Click here to return to the 'Unlock locked files from the terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Unlocking Files and Divnull Software)
Authored by: hschickel on Sep 10, '01 06:58:12AM

Divnull Software ( has come up w/ a much faster utility to do this. Its called Dropunlock and can be downloaded w/ its sister utility, Dropnuke, and the source code at the above URL.

The gist of the source is as follows:

for file; do
location=$(dirname "$file")
cd "${location}"
chflags -R nouchg "${file}"

*Dropnuke adds the following code before done: rm -Rf "${file}"


[ Reply to This | # ]
Unlocking Files and Divnull Software)
Authored by: iMike on Sep 21, '01 06:28:53AM
You can also try the following:

chflags -R nouchg dir_to_unlock

Add wildcards for more fun. Checkout the chflags man page for more info.
This tip brought to you by someone smarter than myself on some list of smart people. 8^)


[ Reply to This | # ]
Unlock locked files from the terminal
Authored by: vanetten on Dec 16, '02 09:47:26PM

chflags will let you lock and unlock files.

chflags uchg ~/Desktop/test.txt

this would lock a file

chflags nouchg ~/Desktop/test.txt

this would unlock the file

[ Reply to This | # ]