How to Fix File Ownership and Permissions Safely Using Terminal on a Mac

Illustration for How to Fix File Ownership and Permissions Safely Using Terminal on a Mac

Quick Answer

To fix a file or folder you own, first inspect it with ls -leO@. Then use chown to change ownership and chmod to change permissions. Start with the smallest possible change, work on a specific path instead of an entire disk, and verify the result afterward.

Never run a recursive ownership or permission command on /, /System, /Library, or an entire startup disk unless you have a documented recovery plan. Incorrect changes can prevent apps from opening, expose private files, or make macOS unstable.

Understand ownership and permissions first

macOS uses ownership and permissions to control who can read, write, or run a file:

  • Owner: The user account associated with the file.
  • Group: A collection of users that may share access.
  • Permissions: Read (r), write (w), and execute (x) access for the owner, group, and everyone else.
  • Extended attributes and ACLs: Additional metadata and access rules that can affect behavior.

A permission problem often appears as an error such as “permission denied,” an inability to save a file, or a folder that another account cannot access. However, not every access problem is caused by Unix permissions. macOS privacy controls, file locks, read-only volumes, encryption, and app-specific restrictions can produce similar symptoms.

If you want to understand the output before changing anything, see how to check file and folder permissions in Terminal on a Mac.

Before changing anything

Back up important files

Changing metadata does not normally delete file contents, but a mistake involving rm, a wildcard, or the wrong path can. Make sure important files exist in a current backup before proceeding.

Identify the exact path

Do not type a path from memory if it contains spaces or unusual characters. In Terminal, type the command prefix and a space, then drag the file or folder from Finder into the Terminal window. macOS inserts the correctly escaped path.

For example, begin with:

ls -leO@

Then drag the item into Terminal and press Return. The resulting command will resemble:

ls -leO@ /Users/yourname/Documents/Example

The placeholder yourname is not a command to copy literally.

Be careful with sudo

sudo runs a command with administrator privileges. It may ask for your Mac login password. Terminal does not display characters while you type the password; this is normal.

Use sudo only when the item is not owned by your account and you have a specific reason to change it. Do not use it to bypass an error without understanding the path and the intended result.

Warning: The commands in this guide can change access to files. Avoid running them on system directories, application bundles, or an entire home folder unless you know exactly which files must change. If a command could affect unsaved work or an active app, close that app first.

Inspect ownership and permissions

Before making a change, record the current state. The following command displays standard permissions, owner, group, flags, ACL entries, and extended attributes for one item:

ls -leO@ "/path/to/item"

Replace /path/to/item with the actual file or folder path. Quotation marks protect spaces in the path.

For a folder, this command reports the folder itself, not every item inside it. To inspect the contents too, use:

ls -laeO@ "/path/to/folder"

Do not add -R casually. Recursive listings can be difficult to read in large folders and do not change anything, but they may expose a great deal of information.

A typical permission string begins with a character identifying the item type, followed by three groups of permissions. For example, drwxr-x--- describes a directory where the owner can read, write, and enter it; the group can read and enter it; and everyone else has no access. The exact output depends on the item and the account running the command.

Terminal showing the command ls -leO@
Run this command in Terminal for this step.
ls -leO@ "/path/to/item"

Fix ownership with chown

Use chown when the owner or group is incorrect. The safest form names the intended owner explicitly:

sudo chown "$USER" "/path/to/item"

This changes the item’s owner to the account currently running the shell. It does not change the permissions or contents.

To set both owner and group, use:

sudo chown "$USER":staff "/path/to/item"

The staff group is common for user-owned files on macOS, but do not assume it is correct for every location or account. Confirm the intended owner and group before using this form.

Afterward, verify the result:

ls -leO@ "/path/to/item"

Change ownership for a folder and its contents

Only use the recursive option when every item below the folder should have the same owner:

sudo chown -R "$USER" "/path/to/folder"

This changes ownership throughout the selected folder. It does not restore each file’s original ownership, and it can damage applications or special folders if used on the wrong path.

A safer approach is to copy the folder to a backup location first, or change ownership on one affected item at a time. If the recursive change was a mistake, there is no universal automatic undo command: you must restore the original owner and group from a backup or from notes made before the change.

Fix permissions with chmod

Use chmod when the owner is correct but the access bits are not.

Add owner write permission

If you can read a file but cannot save changes, add write permission for the owner only:

chmod u+w "/path/to/file"

Here, u means the owner and +w adds write access. This does not grant write access to other users.

To remove write access from everyone except the owner, use:

chmod go-w "/path/to/file"

This removes write permission from the group (g) and others (o) while leaving the owner’s write permission unchanged.

Set a precise permission mode

Numeric modes can be useful when you know the intended result. This command gives the owner read and write access, gives the group read access, and gives everyone else no access:

chmod 640 "/path/to/file"

For a private directory that the owner can fully use while others can list and enter, use:

chmod 750 "/path/to/folder"

A directory needs execute permission to be entered or traversed. That is why directory modes should not be chosen by treating them exactly like file modes.

Avoid chmod 777. It gives everyone read, write, and execute access and can expose or alter private data. It is not a general-purpose fix for permission errors.

Restore a change

If you added owner write access and want to remove that specific change, run:

chmod u-w "/path/to/file"

If you used a numeric mode, the safe reversal is the original mode—not a generic command. Check a backup or the notes you made before changing it. If the original mode is unknown, inspect similar files in the same location and avoid guessing on important data.

Terminal showing the command ls -leO@ /Users/yourname/Documents/Example
Run this command in Terminal for this step.
chmod u+w "/path/to/file"
ls -leO@ "/path/to/file"

Apply changes to a folder carefully

Folders and their contents often need different permissions. A directory must be executable to be opened, while a regular file usually does not need execute permission.

For a folder that you own, add owner access without changing group or other permissions:

chmod u+rwx "/path/to/folder"

For every item inside a folder, recursive chmod applies the same operation to files and directories:

chmod -R u+rwX "/path/to/folder"

The uppercase X adds execute permission only to directories and to files that already have execute permission. This is safer than chmod -R 755, which can make ordinary documents executable and may alter access more broadly than intended.

Even so, recursive changes are powerful. Use a narrow folder path, close apps using the files, and verify the result afterward:

find "/path/to/folder" -maxdepth 2 -print

This lists the selected folder and items up to two levels deep without changing anything. If the path is not exactly what you intended, stop before running a modifying command.

A cautious repair workflow

Use this sequence for a specific file or folder:

  1. Close the affected app. This prevents unsaved changes from being overwritten or the app from holding the file open.
  2. Back up the item. Preserve the data before changing metadata.
  3. Inspect the item.

bash
ls -leO@ "/path/to/item"

  1. Decide whether the problem is ownership or permissions. If the owner is wrong, use chown. If the owner is correct but access bits are wrong, use chmod.
  2. Make one small change. For example:

bash
chmod u+rw "/path/to/file"

  1. Verify immediately.

bash
ls -leO@ "/path/to/item"

  1. Test the original task. Try saving, opening, or moving the item again.
  2. Undo the change if it did not help. Use the recorded original owner, group, and permission mode rather than applying a broad reset.

Terminal showing the command ls -leO@ "/path/to/item"
Run this command in Terminal for this step.
ls -leO@ "/path/to/item"
sudo chown "$USER" "/path/to/item"
chmod u+rw "/path/to/item"
ls -leO@ "/path/to/item"

The example shows a workflow, not a command sequence to run blindly. Run chown only if inspection confirms that ownership should change, and run chmod only if the intended permissions are clear.

Troubleshooting

“Operation not permitted” appears

An administrator password does not override every macOS protection. The file may be protected by privacy controls, a read-only volume, a file flag, an ACL, or another system restriction.

First inspect flags, ACLs, and extended attributes:

ls -leO@ "/path/to/item"

If the item is in a protected location, move or copy your own files to a user-owned folder instead of modifying system content. Do not remove flags or ACL entries unless you understand why they exist and have a recovery plan.

The command says “No such file or directory”

The path is wrong, the item was moved, or shell characters were interpreted unexpectedly. Drag the item from Finder into Terminal to insert its path, then inspect it again:

ls -leO@ 

Do not add a guessed path after the command. Drag the correct item into the window and press Return.

Changing permissions did not fix the problem

Check whether the volume is read-only, the file is locked, or an app is using a different location. Also check the parent folders: you need permission to traverse every directory leading to the item.

If the file is in a cloud-synced or external location, synchronization software, volume format, or another Mac account may control access. Avoid applying broad permissions until you identify the actual source of the error.

A recursive command changed too much

Stop using the affected folder and restore from a backup if files no longer behave correctly. If you recorded the original ownership and modes, restore those values selectively. Do not attempt a blanket reset on the home folder or startup volume; different files legitimately require different permissions.

A file opens but cannot be saved

Inspect both the file and its parent directory. A writable file inside a non-writable directory may still fail to save, especially when an app saves by creating a temporary file and replacing the original.

Use:

ls -leO@ "/path/to/file" "/path/to/parent-folder"

Then make the smallest required change to the affected item or directory.

Frequently Asked Questions

Should I use sudo chmod 777 to fix a Mac permission error?

No. It grants read, write, and execute access to everyone and can expose private data or allow unwanted changes. Identify the correct owner and the minimum required permission instead.

What is the difference between chown and chmod?

chown changes ownership or group membership. chmod changes read, write, and execute permissions. They solve different problems and should not be substituted for one another.

Can I repair permissions on the entire Mac with Terminal?

You should not apply general recursive chown or chmod commands to the startup disk or system directories. macOS uses many different ownership and permission requirements. Repair the specific user-owned item involved, or use an appropriate backup and system-recovery procedure.

Does changing permissions delete files?

chown and chmod change metadata, not file contents. However, a wrong path, wildcard, recursive option, or unrelated command can cause data loss. Verify every path before pressing Return.

How can I undo a permission change?

Use the original owner, group, and mode recorded before the change. For example, if you only ran chmod u+w, the specific reversal is:

chmod u-w "/path/to/file"

For more complex or recursive changes, restore from a backup or use documented original values.

Final Thoughts

Safe permission repair is a matter of inspection, precision, and verification. Check the exact path, change only the owner or permission that is wrong, avoid broad recursive commands, and keep a backup before modifying important data. If the problem persists after a targeted repair, investigate macOS privacy controls, volume status, file flags, and the application involved rather than granting wider access.