You are not logged in.

#1 2005-08-03 14:09:07

From: Norway
Registered: 2005-05-25
Posts: 59

Composite patterns in bash for copying

I've used several hours today to try to make a shell (bash) script in order to take backup of some (quite some) directories. The problem (challenge) is that i want to leave some files (the big result files) out.

My directory structure:

By switching on extglob in bash (shopt -s extglob) it is possible to use socalled composite patterns for wildcards (ref., and i thought this would help.

Problem 1: I try to type in the following command, standing above Dir/, cp -R Dir/*/!(bigfile) new_location. This does not reproduce the directory structure (which i need) and files from Dir2 overwrites files from Dir1.

Problem 2: Since i didn't know how to solve problem 1, i tried to make a small bash script so that i can be in Dir/ and just write 'mycopy 1' so that 'cp SubDir1/!(bigfile) new_location/SubDir1' is run. Now i get an error message which says that "(" is unexpected.

Now i'm 100% stuck and i really don't want to do it manually...


Board footer

Powered by FluxBB