Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cp all things that DO NOT begins with abc?

Tags:

bash

Please don't give me a solution that leverages other commands like grep or ls or sed.

I want to know whether cp with a regular expression can do this.

like image 249
cloudyFan Avatar asked Dec 10 '25 21:12

cloudyFan


2 Answers

cp(1) itself has no "regular expression" support; the functionality you're depending on is probably Pathname Expansion (globbing) in Bash. Check the bash(1) manpage to find extglob syntax like this:

shopt -s extglob
cp !(abc*) destination/
cp -t elsewhere [^a]* a[^b]* ab[^c]*

Note that this:

  • doesn't involve regular expressions at all
  • involves shell globbing instead, but
  • is performed by bash not cp, and
  • is a hand-inversion of abc*
like image 32
JB. Avatar answered Dec 13 '25 15:12

JB.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!