3

lib1.a
lib2.a
lib1.so
lib2.so
libgcc1.so
libgcc2.so
libgcc3.so
lib3.so

How can I copy all *.so files excluding libgcc*.so i.e. copy the following files:

lib1.so
lib2.so
lib3.so

?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Andrei Sedoi
  • 1,534
  • 1
  • 15
  • 28
  • Copy to temp folder, delete the ones you don't need, copy the rest to the final destination? – millimoose Feb 11 '13 at 22:30
  • Also: http://stackoverflow.com/questions/216995/how-can-i-use-inverse-or-negative-wildcards-when-pattern-matching-in-a-unix-linu might have some pointers. – millimoose Feb 11 '13 at 22:31
  • How strict is the requirement to not copy `libgcc`? Could you copy everything and then delete just those? Either way, you probably want to start with `find` or `ls | grep`, both piped to `xargs cp`. To exclude things, use `grep -v`. – ssube Feb 11 '13 at 22:31

2 Answers2

7

In bash, you can use extended globbing:

shopt -s extglob
cp !(libgcc*).so destination/
choroba
  • 231,213
  • 25
  • 204
  • 289
3

Try using find:

find path/to/src-dir -name '*.so' ! -name 'libgcc*.so' \
    -exec cp '{}' /path/to/dst-dir \;
helmbert
  • 35,797
  • 13
  • 82
  • 95