Книга: Fedora™ Unleashed, 2008 edition

Changing File Access Permissions with chmod

Changing File Access Permissions with chmod

What you learned about chmod earlier 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 you can capture the output and use it for other purposes. For example:

[paul@caitlin tmp]$ chmod -c 600 *
mode of `1.txt' changed to 0600 (rw-------)
mode of `2.txt' changed to 0600 (rw-------)
mode of `3.txt' changed to 0600 (rw-------)
[paul@caitlin tmp]$ chmod -c 600 *
[paul@caitlin 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 enables 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 changes the permissions of that directory and 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 owners.

Оглавление книги


Генерация: 1.462. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз