1

This question already has an answer here:

I have moved a tar.bz2 from my Downloads to /usr/src, which is where I like to put all things that I install on my system. Now I extracted the file and I want to move its contents to /usr/share/icons. But I do not want to move the tar.bz2 itself:

# ls -l | grep Comix
-rw-rw-r--  1 guarddog guarddog   2190951 May 26 11:03 ComixCursors-0.8.2.tar.bz2
drwxr-xr-x  3 root     root          4096 Oct 23  2013 ComixCursors-Black
drwxr-xr-x  3 root     root          4096 Oct 23  2013 ComixCursors-Blue
drwxr-xr-x  3 root     root          4096 Oct 23  2013 ComixCursors-Green
drwxr-xr-x  3 root     root          4096 Oct 23  2013 ComixCursors-Orange

In the output command I want to move everything besides the tar.bz2, within the terminal.

I tried the following but unfortunately it moves the tar.bz2 as well:

 mv Comix*[!tar.bz] /usr/local/share

I expected the negation operator to exclude the file ending wit tar.bz. The solution below is what I was looking for, didn't want to use find with complicated flags.

marked as duplicate by muru, Eric Carvalho, karel, Volker Siegel, RPiAwesomeness May 27 '15 at 14:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

You can use the GLOBIGNORE variable of bash:

GLOBIGNORE=ComixCursors-0.8.2.tar.bz2

Now run:

mv ComixCursors* /usr/share/icons/

Also note that when you are done with the operation it is good to unset the variable to avoid unwanted scenarios:

unset GLOBIGNORE

Or

GLOBIGNORE=
  • @Arronical yes..it would be sensible if you are done with it..No, it does not automatically unset itself.. – heemayl May 26 '15 at 15:42
1

Use the good old find:

find /usr/src -maxdepth 1 -type f -name "Comix*[^\.tar\.bz2]" -print0 | xargs -I{} -0 mv {} /usr/share/icons/
  • @Arronical Then write your answer :) – A.B. May 26 '15 at 15:44
  • @Arronical ComixCursors-Blue2 doesn't match. – A.B. May 26 '15 at 17:01
0

There's also a simple command to use, for example in your Home Dir. we have a folder "Xtest" which contains test.tar.gz and test.txt, test2.txt etc. and an empty folder "Xtest2" where we want to move all files except .tar.gz then:

cd ~/Xtest
mv !(test.tar.gz) ~/Xtest2

All the content except test.tar.gz will be moved to Xtest2 folder.

Not the answer you're looking for? Browse other questions tagged or ask your own question.