Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BASH copy all files except one

People also ask

How do I select all files except one?

Click the first file or folder you want to select. Hold down the Shift key, select the last file or folder, and then let go of the Shift key. Hold down the Ctrl key and click any other file(s) or folder(s) you would like to add to those already selected.

How copy and exclude files in Linux?

Using cp In this case, we get a list of files & folders to be copied using ls command, and use grep command to exclude files & folders. We pass this list to cp command for copying. Here exclusion is done by grep command and not cp command.

How do I copy everything except one folder?

We can also use cp command to copy folders from one location to another excluding specific directories. Go your source directory i.e ostechnix in our case. The above command will copy all contents of the current folder ostechnix except the sub-directory dir2 and saves them to /home/sk/backup/ directory.


Should be as follows:

cp -r !(Default.png) /dest

If copying to a folder nested in the current folder (called example in the case below) you need to omit that directory also:

cp -r !(Default.png|example) /example

rsync has been my cp/scp replacement for a long time:

rsync -av from/ to/ --exclude=Default.png

-a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
-v, --verbose               increase verbosity

Simple, if src/ only contains files:

find src/ ! -name Default.png -exec cp -t dest/ {} +

If src/ has sub-directories, this omits them, but does copy files inside of them:

find src/ -type f ! -name Default.png -exec cp -t dest/ {} +

If src/ has sub-directories, this does not recurse into them:

find src/ -type f -maxdepth 1 ! -name Default.png -exec cp -t dest/ {} +

cp `ls | grep -v Default.png` destdir