Though there is no –exclude option available in cp command but you can still exclude certain file or directory from being copied.
Example:
Create some files and directories:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
## Create some files and directorie mkdir -p mydir/{source/subdir,target{1..2}} echo "hello" > mydir/source/file1 echo "hello" > mydir/source/subdir/file11 tree ## . ## └── mydir ## ├── source ## │ ├── file1 ## │ └── subdir ## │ └── file11 ## ├── target1 ## └── target2 |
Exclude specific directory in cp command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
## Exclude specific directory (mydir/source/subdir) ## cp -R sourceDir/!(DirToExclude) destinationDir/ cp -R mydir/source/!(subdir) mydir/target1/ tree ## . ## └── mydir ## ├── source ## │ ├── file1 ## │ └── subdir ## │ └── file11 ## ├── target1 ## │ └── file1 ## └── target2 |
Exclude specific file in cp command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
## Exclude specific file (mydir/source/file1) ## cp -R sourceDir/!(FileToExclude) destinationDir/ cp -R mydir/source/!(file1) mydir/target2/ tree ## . ## └── mydir ## ├── source ## │ ├── file1 ## │ └── subdir ## │ └── file11 ## ├── target1 ## │ └── file1 ## └── target2 ## └── subdir ## └── file11 |