Toolvito

Works on this device

Chown Command Generator

Enter the new owner, the new group and the files or folders. The tool writes the command with every path quoted for the shell and explains each part. It writes text only and runs nothing.

Your command

Owner, group and options

Leave empty to keep the owner as it is.

Leave empty to keep the group as it is.

Files and folders to change

One path in each row, typed exactly. Spaces and other special characters are quoted for you.

More options

A path. When this is filled in, leave the owner and group empty. This option is in GNU chown and chgrp (Linux), not in macOS or BSD.

Your values are worked out in this browser. They are not sent to a server.

Your command will show here

Enter an owner or a group and at least one path, or choose Try an example.

How to use this generator

  1. Choose chown to change the owner, the group, or both. Choose chgrp to change only the group.
  2. Enter the new owner and the new group. A name or a numeric ID can be used. Leave a box empty to keep that value as it is.
  3. Enter one path in each row. Type each path exactly, with its spaces. Do not add quotes; the tool adds them.
  4. Tick the options you need, such as -R to change everything inside a folder.
  5. Read the table What each part does and any caution. Then choose Copy command and paste it into your terminal.

The form of the command

The command has the form chown options owner:group path path. With only an owner it is chown owner path. With only a group this tool writes chown :group path, or you can use chgrp group path.

Options this tool can write
Option Meaning Where it works
-R Changes each listed folder and everything inside it. POSIX
-P With -R: never follows a symbolic link. POSIX
-H With -R: follows a symbolic link to a folder only when it is a listed path. POSIX
-L With -R: follows every symbolic link to a folder. POSIX
-h Changes a symbolic link itself, not the file it points to. POSIX
-v Prints a line for every file. GNU and BSD
--reference=file Copies the owner and group from another file. GNU (Linux) only
-- Ends the options. It is added when a name or a path starts with a hyphen. POSIX

How paths are quoted

  • A word made only of letters, digits and _ @ % + = : , . / - is written as it is.
  • Any other word is put inside single quotes. Inside single quotes the shell changes nothing: spaces, $, * and backslashes all stay as typed.
  • A single quote inside a word cannot be put inside single quotes. It is written by closing the quotes, adding the single quote inside double quotes, and opening the quotes again.
  • The table The words of the command as the shell reads them shows what a POSIX shell passes on. It must show your paths exactly as you typed them.
  • Because every path is quoted, * is not expanded to many files and ~ is not replaced by your home folder. The tool tells you when a path has such a character.

Worked example

Owner alice, group staff, and the two paths /srv/app and /srv/app/my notes.txt give the command chown alice:staff /srv/app '/srv/app/my notes.txt'. The second path has a space, so it is inside single quotes.

With the group staff, the paths /etc/ and -x it's, the option -R and sudo, the chgrp command is sudo chgrp -R -- staff /etc/ '-x it'"'"'s'. The tool adds a caution, because /etc is a system folder.

Limits you should know

  • The tool does not run the command and cannot see your computer. It does not know which users, groups or files exist, and it cannot tell you if you have the right to make the change.
  • A recursive change of a system folder such as /, /etc, /usr, /var or /home can stop a system from working and is hard to undo. The caution is a reminder, not security advice. The list of folders it checks is short and fixed.
  • The quoting is for POSIX shells such as sh, bash, zsh and dash. It is not for PowerShell, the Windows command prompt, fish or csh.
  • -v is not in POSIX, and --reference is only in GNU chown and chgrp. On macOS and BSD --reference does not work.
  • With -R and no link option, POSIX leaves it open if symbolic links are followed. The GNU and BSD versions do not follow them.
  • A path can have up to 4,096 characters, and there can be up to 50 paths. A path cannot contain a tab or a line break here.

Related tools