How do you exclude a folder when performing file operations i.e. cp etc.
I would currently use the wild card * to apply file operation to all, but I need to exclude one single folder.
The command I'm actually wanting to use is chown
to change the owner of all the files in a directory but I need to exclude one sub directory.
Method 1- using rsync command One of the useful option is --exclude. Using exclude option, we can exclude certain files/directories from copying.
In order to change the user and the group owning the directories and files, you have to execute “chown” with the “-R” option and specify the user and the group separated by colons. For example, let's say that you want to change the user owning the files to “user” and the group owning the files to “root”.
find dir_to_start -name dir_to_exclude -prune -o -print0 | xargs -0 chown owner
find dir_to_start -not -name "file_to_exclude" -print0 | xargs -0 chown owner
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With