0

Is it possible to change owner/group of a file AND permissions with 1 command?
I tried:
chmod user1:groupOfUser1=770 file.txt
but it does not work.

Jim
  • 335
  • 2
  • 4
  • 8
  • 3
    Make a shell script that combines the `chmod` and `chown` commands? – DerfK Dec 14 '12 at 12:53
  • 1
    @DerfK Indeed. Or alias. Or a Bash function. – gertvdijk Dec 14 '12 at 13:17
  • My thoughts are that the answer might be in some the usage of [setfacl](http://linux.die.net/man/1/setfacl). Is it possible to update owner/group and default permissions with setfcacl? – Zoredache Dec 15 '12 at 01:07

2 Answers2

4

Create a script

Similar to this you can modify as per your need

cat chmodown
#!/bin/bash

chmod $2 $1 $5
chown $3:$4 $1 $5

$1 is file name $2 is permission $3 user name $4 Group name $5 (-R) for recursive.

You can then place the same script to "/usr/bin/" too.

chmodown install.log 777 test root
ls -al install.log
-rwxrwxrwx 1 test root 18262 Jul 27 01:52 install.log
Pratap
  • 695
  • 6
  • 22
3

I don't think that's really possible.

I expect that what you are looking for is to input file name just once. You can do something like this

# for a in file.txt; do chown user1:groupOfUser1 $a; chmod 770 $a; done

Over here you need to input the file name just once :)

At the same time, you can use shell script like this:

#!/bin/bash
chown $1:$2 $4
chmod $3 $4

Make this executable and put it in your PATH variable and use it something like this.

# ./x.sh user group permission file_name

Napster_X
  • 3,373
  • 18
  • 20