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.

3
  • 3
    Make a shell script that combines the chmod and chown commands?
    – DerfK
    Dec 14, 2012 at 12:53
  • 1
    @DerfK Indeed. Or alias. Or a Bash function.
    – gertvdijk
    Dec 14, 2012 at 13:17
  • My thoughts are that the answer might be in some the usage of setfacl. Is it possible to update owner/group and default permissions with setfcacl?
    – Zoredache
    Dec 15, 2012 at 1:07

2 Answers 2

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .