How to lock and unlock a folder/file in MacOS from terminal (so that general program can't modify it

  1. Launch Terminal. 
  2. sudo chflags uchg [file path]
  3. Press Enter.

    Unlock: chflags nouchg [file path]