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.
Best Answer
Inverse Globbing:
You want an inverse match of a glob, I would do it like the following:
You can do an inverse match with a newer bash if you enable extended globbing. For example, to match everything that doesn't have foo or bar in the name:
Or just everything that doesn't have foo:
Find:
You could also use find (this is the most robust option I think), and use ! to negate a match, and then run the command with
xargs -0
:Simple:
Just mv the folder somewhere else, do what you need to do, and put it back :-)