May 12, 2024

Batch unlock files on macOS

Intro

Recently, I was trying to reinstall my Mac system.

Firstly, I made a copy of all my Mac files to my Synology device.

After reinstalling the macOS, I moved back all the files and saw this “lock” on every single file.

Screen Shot 2024-05-12 at 11.07.41 am

Screen Shot 2024-05-12 at 11.09.02 am

It is stupid and impossible to unlock all these files individually, let us try something quick.


Batch unlock files

Open Terminal, and go to the folder where you want to batch unlock your files.

For example

1
cd Documents

Then execute the below command

1
find . -exec chflags nouchg,noschg {} \;
  • find .: This command starts a search from the current directory (.) and includes all subdirectories.

  • -exec: This option of the find command allows you to execute a command on each found file or directory.

  • chflags nouchg,noschg {} \;: This is the command executed on each found item. It’s using the chflags command to change file flags. Specifically, it’s removing two flags: uchg (user immutable) and schg (system immutable) from each file ({} represents the current file being processed by find). The nouchg and noschg flags tell chflags to remove these specific flags.

Overall, this command recursively searches through the current directory and its subdirectories and removes the user and system immutable flags from all files. This can be useful if you need to modify files that are currently marked as immutable.

Screen Shot 2024-05-12 at 11.11.38 am

Done.

Screen Shot 2024-05-12 at 11.08.30 am



Reference

About this Post

This post is written by Andy, licensed under CC BY-NC 4.0.

#macOS