chown_and_chmod_examples
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
chown_and_chmod_examples [2016/08/10 09:06] – walkeradmin | chown_and_chmod_examples [2023/03/09 22:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 50: | Line 50: | ||
* Now, as the existing owner was not ‘guest’. So, the command failed to change the owner of the file. | * Now, as the existing owner was not ‘guest’. So, the command failed to change the owner of the file. | ||
* Next we tried to change the owner if the existing owner is ‘root’ (which was true) and this time command was successful and the owner was changed to ‘himanshu’. | * Next we tried to change the owner if the existing owner is ‘root’ (which was true) and this time command was successful and the owner was changed to ‘himanshu’. | ||
+ | \\ | ||
+ | ==== Copy the owner/group settings from one file to another ==== | ||
+ | This is possible by using the ‘–reference’ flag. | ||
+ | | ||
+ | # ls -l file | ||
+ | -rwxr-xr-x 1 himanshu family 8968 2012-04-09 07:10 file | ||
+ | | ||
+ | # ls -l tmpfile | ||
+ | -rw-r--r-- 1 root friends 0 2012-05-22 20:03 tmpfile | ||
+ | | ||
+ | # chown --reference=file tmpfile | ||
+ | | ||
+ | # ls -l tmpfile | ||
+ | -rw-r--r-- 1 himanshu family 0 2012-05-22 20:03 tmpfile | ||
+ | \\ | ||
+ | In the above example, we first checked the owner/group of the reference-file ‘file’ and then checked the owner/group of the target-file ‘tmpfile’. Both were different. | ||
+ | \\ | ||
+ | \\ | ||
+ | ==== List all the changes made by the chown command ==== | ||
+ | Use the verbose option -v, which will display whether the ownership of the file was changed | ||
+ | or retained as shown below. | ||
+ | | ||
+ | # chown -v -R guest: | ||
+ | changed ownership of `linux/ | ||
+ | changed ownership of `linux/ | ||
+ | ownership of `linux/ | ||
+ | ownership of `linux/ | ||
+ | changed ownership of `linux/ | ||
+ | changed ownership of `linux/ | ||
+ | ownership of `linux/ | ||
+ | ownership of `linux' | ||
+ | \\ | ||
\\ | \\ | ||
chown_and_chmod_examples.1470816394.txt.gz · Last modified: 2023/03/09 22:35 (external edit)