Shell Script to find locked files & copy to another directory

Hi all,

I’m trying to write a shell script that will look in the directory of an SD card for all files that are locked.

Then duplicate those files to a folder on the Mac.

The script fails as I can’t find the correct syntax to use for the IF file is locked part.

Can any kind soul help me out?

Many thanks

#!/usr/bin/env zsh -f
#set -x

targetDir="~/Dropbox/Backups/Mobius\ Locked/"

cd $sourceDir

for file in *; do
  if [[ "$file" == -flags uchg ]]; then
    mv "$file" "$targetDir"

Found a solution:

cd /Volumes/MOBIUS/DCIM 
find ./ -flags uchg -exec mv -f {} ~/Dropbox/Backups/Mobius\ Locked \;

chflags -R nouchg /Volumes/MOBIUS/DCIM
chflags -R nouchg ~/Dropbox/Backups/Mobius\ Locked

The shell will also now unlock the files on the external volume, as well as the copied files