The cp
command does not have an excludes option. One way to copy files ignores some files or directories is to create a tarball. The tar
command has an exclude option. The exclude patterns can be mentioned in a separate file and passed in to the tar command.
BO
├── .git
├── .gitignore
├── books.html
├── book.js
├── build.sh
├── buildExcludes
├── main.js
├── manifest.json
├── bin
│ └── BO
│ ├── books.html
│ ├── books.js
│ ├── main.js
│ ├── manifest.json
│ └── res
│ └── icons
│ ├── bo-128.png
│ ├── bo-16.png
│ ├── bo-256.png
│ ├── bo-32.png
│ ├── bo-48.png
│ ├── bo-512.png
│ └── bo-64.png
└── res
└── icons
├── bo-128.png
├── bo-16.png
├── bo-256.png
├── bo-32.png
├── bo-48.png
├── bo-512.png
├── bo-64.png
└── bo.fla
In the above directory structure, I want to copy certain file to bin/BO
but ignore others like .git
, fla
files in the res/icons
directory, the build scripts etc. For that first create an file say buildExcludes
with the exclude pattern.
Content of the exclude file is given below.
.git
.gitignore
bin
res/icons/*.fla
build.sh
buildExcludes
Create the tar
, deflate to the destination directory and delete the tar
once done.
tar -cvf bo.tar * -X buildExcludes # create tar
tar -xvf bo.tar -C bin/BO/ # deflate to destination directory
rm -f bo.tar # cleanup