For changing file permission, I know I could use chmod. For changing group-owner, I could use chgrp. However, if I want to change both permission and owner at the same time, any command I could use on Linux?

For example, there is a file with this permission and owner:

-rw-r--r--+  1 raymondtau  staff    0 May  8 16:38 WantToChangeThisFile

And now I want to change it to:

---x-w--wx+  1 raymondtau  admin    0 May  8 16:38 WantToChangeThisFile

I know I could use this command: chmod 123 WantToChangeThisFile && chgrp admin WantToChangeThisFile, but want to know if there is any neat way to do that.

7 Answers 7


If what you also want is to copy the file somewhere (like its final destination), you might want to have a look at the install command:

install -m 0777 -o root $sourcefile $destinationfile

  • 1
    I wonder if "install" supports a way to operate on an already existing file, without moving anything Jan 27, 2023 at 7:33

There is concept known as "UNIX-way". Each tool should perform one simple function. If one need a more complex function, he can combine smaller tools.

The opposite is the monolitic design when all functionality is aggregated within one huge tool.

If you want to do something complex - just write a script, invoking simple tools.

  • Here is a script I wrote that combines these tools into one shell function, ch.
    – ki9
    Oct 9, 2017 at 19:59
  • 2
    there's no way it's an answer, what he asked could be achieve with several tools already existent such as rsync and though linux tend to prefers one tool/one function it does mean tools doing multiple stuff aren't existing
    – Kiwy
    Jan 17, 2018 at 13:07
  • @Kiwy Some linux tools do not conform unix-way principles and combine different functions of different nature. Like systemd for example.
    – Kondybas
    Jan 17, 2018 at 13:21
  • 1
    @Kondybas "tend to" is the important part of the sentence. exception to the rule does exist. Still your answer to me is a really bad one.
    – Kiwy
    Jan 17, 2018 at 13:35

Using the right tool for the job in *nix is important, but indeed repeating the same path in each chained command looks silly. Instead, you should really use Bash variables, and in smaller scripts, especially make use of $_.

Your command would become:

chmod 123 WantToChangeThisFile && chgrp admin $_

ALT + . does the similar thing of pulling the last used argument in your current shell.


You could achieve suche a goal with long rsync command

rsync --chown=root:root --chmod=F755 filename filename
  • i do not get it Jan 17, 2018 at 9:07
  • This is unsafe: it will affect all matching files in the specified directory and subdirectories, not just the one file it's pointed to.
    – telcoM
    Jan 17, 2018 at 11:49

Rsync is useful in this case:

From the Fine Manual (TM)

--chown=USER:GROUP simple username/groupname mapping

--chmod=CHMOD affect file and/or directory permissions

So, for example, you want to chmod /mnt/lala/lala4000/ "ugo=rX" and chown "foo.bar"

rsync --chmod=ugo=rX --chown=foo:bar -rvtpolgh /mnt/lala/lala4000/ /mnt/lala/lala4000/

This would recursively chown and chmod the dir.


You can do chown username:groupname file ... to change both simultaneously. It's changing two fields in the same (inode) structure so combining it saves two system calls (one for reading the current values and one for setting the modified vaules).

  • chown only changes the owners. How does this change the permissions at the same time as OP requested? Note OP's example includes a chmod as well.
    – jscott
    May 8, 2015 at 12:40
  • Ah, I thougth he wanted to change 3 things, as he wrote For changing group-owner I thought he meant group and owner.
    – wurtel
    May 8, 2015 at 12:42

# Setting the Variables for execution
CURRENTTIME=$(date +"%Y%m%d%s%H%M%S")

# Checking the number of Parameters passed
if [ "$#" -ne 1 ]; then
    echo "Master file name is mandatory parameter" > ${LOGFILE}
    exit 1

# Loading the Master file into an Array 
echo "Loading the Master file ${MASTERFILE} into an array" >> ${LOGFILE}
while read line
#echo $line  
INDEX=$(expr $INDEX + 1) 
done < ${MASTERFILE}

echo "Number of parameters in an master array ${MASTERARRAY[@]}" >> ${LOGFILE}

# Changing the permission of the file 
echo "Changing the permission of the file in master file ${MASTERFILE}" >> ${LOGFILE} 
for index in "${MASTERARRAY[@]}"
    if [ -f "$index" ] 
       echo "$index file exist"
       echo  "$index file exist" >> ${LOGFILE}
       chmod 755 "$index" 
       chown workstation "$index"
       chgrp workstation "$index" 
      echo "$index file does not extst"
      echo "$index file does not exist" >> ${LOGFILE}  
  • 2
    you could at least provide an explanation of how it works and how it's suppose to be use (parameters how much what they are...)
    – Kiwy
    Jan 17, 2018 at 13:04
  • 2
    Please do not just paste some code as an answer. Jan 20, 2018 at 22:03
  • Commenting is not likely to be productive; this is the only thing this user ever posted, and they haven’t even logged in since then. Jan 23, 2018 at 17:36

You must log in to answer this question.

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