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


Click here to return to the 're: this can be done form the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
re: this can be done form the Terminal
Authored by: Anonymous on Mar 28, '01 07:23:02PM

that's not actually the case with locked files.

if the file is locked, then when you try to rm, even as root, it prompts
"override <permissions> for <filename>?"
hitting y for yes returns
"rm: <filename>: Operation not permitted"
and the file stays there.



[ Reply to This | # ]
re: this can be done form the Terminal
Authored by: alanw on Apr 14, '01 01:11:16AM

It is true that even as root via the Terminal you cannot use the usual UNIX "rm" command to delete locked files. This is disturbing (especially unsettling to one who has done Mac troubleshooting for years and is well acquainted with Murphy's Law--if something can go wrong, it will). Suppose that by whatever cause, malicious or otherwise, you find your disks filled with hundreds or thousands of locked files. There should be some backdoor method (certainly, I agree, not one to be invoked casually) to unlock them in batch fashion (apart from rebooting into Mac OS 9.1; perhaps someday that won't be an option).
Well, after puzzling over this for some time, I finally discovered that backdoor method. You need to have the Developer Tools installed. Open a Terminal window and type (without the quotes)
"/Developer/Tools/SetFile a -l <names of files to unlock>" You can use wildcards. "/Developer/Tools/SetFile a -l *" for example will unlock all files in the current directory. If some are already unlocked, their lock attribute remains unchanged. Experienced UNIX hackers will no doubt be able to use shell scripts or more complicated command combinations to unlock in batch fashion any files anywhere.



[ Reply to This | # ]
re: this can be done form the Terminal
Authored by: alanw on Apr 14, '01 01:19:34AM

Correction: That should have been "/Developer/Tools/SetFile -a l <names of files>" and
"/Developer/Tools/SetFile -a l *"
I knew I shouldn't have stayed up this late. :-)



[ Reply to This | # ]
re: this can be done form the Terminal
Authored by: sauy7 on Oct 30, '04 06:39:48AM
Here's a simple bash script to run in a Terminal window

#! /bin/bash
#
# Simple file unlocking utility for Mac OS X
#
ARGS=1
E_BADARGS=65

function recursiveUnlock() {
    pushd $1
    for rdir in `ls -A`; do
        if [ -d "${rdir}" ]; then
            recurse ${rdir}
        else
            /Developer/Tools/SetFile -a l ${rdir}
        fi
    done
    popd
}

if [ $# -ne "$ARGS" ]
then
    echo "Usage: `basename $0` starting-directory"
    exit $E_BADARGS
fi

recursiveUnlock $1
Usage (code saved as an excutable file recursiveUnlock.sh):

$ ./recursiveUnlock.sh /path/to/top-level/dir
unlocks all files in dir, including those in dir's sub-directories

---
sauy7

[ Reply to This | # ]

re: this can be done form the Terminal
Authored by: gwik on Mar 01, '06 09:55:25AM
$ find *the_root_dir* -type d -exec /Developer/Tools/SetFile -a l {} \;

[ Reply to This | # ]