47

I want to set the group permissions for all files and subdirectories within a certain parent directory to whatever the user permission setting for that specific file or directory is.

For example, everything under /path/to/parentdir

# Permissions before
# Path                      Permissions
/path/to/parentdir/file1    755
/path/to/parentdir/file2    644
/path/to/parentdir/file3    600

# Permissions after
/path/to/parentdir/file1    775
/path/to/parentdir/file2    664
/path/to/parentdir/file3    660

I'm hoping there's a simple way to do this in hopefully one command. I can think of ways using a script with a bunch of commands, but it feels like there should be a pretty direct way of doing it.

Thanks in advance!

Stéphane Gimenez
  • 28,527
  • 3
  • 76
  • 87
Matthew
  • 1,041
  • 2
  • 11
  • 16

1 Answers1

77

This is what you want:

chmod -R g=u directory
Stéphane Gimenez
  • 28,527
  • 3
  • 76
  • 87