Sometime we need to copy entire directory with the except of a few files or a specific directory. This could easily be accomplished with a regular expression as follows:
Note: $ is the command prompt, not the code you type.
$ mkdir test
$ cd test
$ touch a.txt
$ touch b.txt
$ mkdir mod
$ cd mod
$ touch c.txt
$ touch d.txt
$ mkdir ../views
$ cd ../views
$ touch e.txt
$ touch f.txt
$ mkdir ../../test2
$ cd ..
Following is the directory structure created by this code:
$ ls -R
$ .:
a.txt b.txt mod views
./mod:
c.txt d.txt touch
./views:
e.txt f.txt touch
Now we copy all files except for the mod directory:
$ cp -a [^mod]* ../test2
This is what it looks like after copying. All files are copied with the exception of the mod directory and its contents.
$ ls -R ../test2
../test2:
a.txt b.txt views
../test2/views:
e.txt f.txt touch