Often you may want to copy all files except a specific one in Bash.
You can use the following syntax to do so:
cp -R `ls -A | grep -v 'teams4.txt'` c:/users/bobbi/data2
This particular example copies all files from the current directory except the file named teams4.txt into a new directory named data2 with the path that we specified.
Here is what the various commands do:
- cp -R: Copy files recursively from all subfolders
- ls -A: List all files in current directory including ( -A ) hidden files
- grep -v: Select all filenames that do not match a specific pattern
The following example shows how to use this syntax in practice.
Example: How to Copy All Files Except One in Bash
Suppose that we would like to copy all of the files from our current directory except for a file named teams4.txt into a new directory.
We can use the ls -A command to first view all of the files in our current directory:

We can see that this directory contain the following files:
- teams1.txt
- teams2.txt
- teams3.txt
- teams4.txt
We can use the following syntax to copy all of these files except the teams4.txt file into a directory named data2:
cp -R `ls -A | grep -v 'teams4.txt'` c:/users/bobbi/data2
The following screenshot shows how to use this syntax in practice:

Notice that when we use the ls command to view the contents of the data2 directory we can see that each of the files from data1 except the file named teams4.txt have been copied.
Feel free to use similar syntax to copy all files except a specific one from your own directory.
Related Tutorials
The following tutorials explain how to perform other common tasks in Bash:
Bash: How to Copy a File to Multiple Directories
Bash: How to Copy and Rename a File
Bash: How to Copy All Files in Directory to Another Directory
