Friday, December 2, 2022
  • Index
  •  » Automator
  •  » Shell Script to find locked files & copy to another directory

#1 2022-10-31 04:16:38 am

Osmosis
Member
Registered: 2006-12-29
Posts: 41

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

Applescript:

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

sourceDir="/Volumes/MOBIUS/DCIM/"
targetDir="~/Dropbox/Backups/Mobius\ Locked/"

cd $sourceDir

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


Filed under: shell, Automator, flags

Offline

 

#2 2022-10-31 05:03:20 am

Osmosis
Member
Registered: 2006-12-29
Posts: 41

Re: Shell Script to find locked files & copy to another directory

Found a solution:

Applescript:



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

Offline

 
  • Index
  •  » Automator
  •  » Shell Script to find locked files & copy to another directory

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)