move all files except with extension [duplicate]
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-OrangeIn 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/shareI 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.
63 Answers
You can use the GLOBIGNORE variable of bash:
GLOBIGNORE=ComixCursors-0.8.2.tar.bz2Now 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 GLOBIGNOREOr
GLOBIGNORE= 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/ 2 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) ~/Xtest2All the content except test.tar.gz will be moved to Xtest2 folder.