Changing File Access Permissions with chmod

What you learned about chmod in Chapter 5 can be greatly extended through one simple parameter: -c. This instructs chmod to print a list of all the changes it made as part of its operation, which means we can capture the output and use it for other purposes. For example:

[[email protected] tmp]$ chmod -c 600 * [[email protected] tmp]$

There the chmod command is issued with -c, and you can see it has output the result of the operation: Three files were changed to rw-------(read and write by user only). However, when the command is issued again, no output is returned. This is because -c prints only the changes that it made. Files that already match the permissions you are setting are left unchanged and therefore are not printed.

There are two other parameters of interest: --reference and -r. The first allows you to specify a file to use as a template for permissions rather than specifying permissions yourself. For example, if you want all files in the current directory to have the same permissions as the file

/home/paul/myfile.txt, you would use this:

chmod —reference /home/paul/myfile.txt *

You can use -R to enable recursive operation, which means you can use it to chmod a directory and it will change the permissions of that directory as well as all files and subdirectories under that directory. You could use chmod -r 600 /home to change every file and directory under /home to become read/write to their owner.

Was this article helpful?

0 0

Post a comment