1

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.

Donato
  • 583

3 Answers3

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=
heemayl
  • 91,753
  • @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/
A.B.
  • 90,397
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.

JoKeR
  • 6,972
  • 9
  • 43
  • 65