Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exclude a folder when performing file operations i.e. cp, mv, rm and chown etc. in Linux

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.

like image 641
Camsoft Avatar asked Jan 14 '10 15:01

Camsoft


People also ask

How do I copy all directories except one in Linux?

Method 1- using rsync command One of the useful option is --exclude. Using exclude option, we can exclude certain files/directories from copying.

How do I change the Chown of all files in a directory?

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”.


1 Answers

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
like image 167
Dennis Williamson Avatar answered Sep 17 '22 14:09

Dennis Williamson