P
P
Playtoster2018-09-20 00:20:44
Command line
Playtoster, 2018-09-20 00:20:44

How to copy to the current folder part of another with exceptions?

How to copy files and folders from another directory, excluding a couple of unnecessary ones?
I know it's possible like this:

cp sourcefolder/* !(excludefolder | excludefile) destination/

But I need to copy to the current one from another:
cp sourcefolder/* !(sourcefolder/excludefolder | sourcefolder/excludefile) this-folder/

Or copy to the previous one, from which I moved to sourcefolder:
cp sourcefolder/* !(excludefolder | excludefile) previous-folder/

This is real?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2018-09-20
@Playtoster

use extglob (for bash)

$ mkdir -p d/folder
$ touch d/folder/excludefile{1..5}
$ ls d/folder/
excludefile1  excludefile2  excludefile3  excludefile4  excludefile5
$ shopt -s extglob
$ cp d/folder/excludefile!(1|2) .
$ ls
d  excludefile3  excludefile4  excludefile5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question