Bash script to change file ownership




















List the target file names after the new user to change the ownership for multiple files. Use single spaces between the file names. In the following example, root will be the new owner of files sample2 and sample3. With chown, you can change a group for a file or directory without changing the owning user. The result is the same as using the chgrp command.

To assign a new owner of a file and change its group at the same time, run the chown command in this format:. Therefore, to set linuxuser as the new owner and group2 as the new group of the file sample2 :. Rather than changing the ownership to a specific user, you can use the owner and a group of a reference file. Add the --reference option to the chown command to copy the settings from one file to another:.

Remember to type in the names of the files correctly to avoid the error message:. The chown command --from option lets you verify the current owner and group and then apply changes. The example below shows we first verified the ownership and the group of the file sample3 :. The option --from can be used to validate only the current user of a file. Similar to the previous section, you can validate only the group of a file using the option --from.

The chown command allows changing the ownership of all files and subdirectories within a specified directory. Add the -R option to the command to do so:. In the following example, we will recursively change the owner and the group for all files and directories in Dir1. To change the owner of a symbolic link, use the -h option.

Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Learn more. Script to change ownership of files Ask Question. Asked 7 years, 10 months ago. Active 3 years ago. Viewed 7k times. Improve this question. Rui F Ribeiro Is this all the files in a particular directory? Add a comment. Active Oldest Votes. Improve this answer. Changing owner of a file in Unix Changing file ownership means only updating the association between a Unix user and a file, and nothing else. Get in touch! Recent Articles 14 Oct Recent Tweets Tweets by Gleb Reys.



0コメント

  • 1000 / 1000