6

This question already has an answer here:

I have the following:

~@matrix:~/btp200/assignments> ls -la
total 40
drwxr-xr-x 3 molszewski1 users 4096 Feb  6 13:20 .
drwxr-xr-x 6 molszewski1 users 4096 Feb  6 13:14 ..
-rw-r--r-- 1 molszewski1 users 5727 Feb  6 13:20 ISBN.cpp
-rw-r--r-- 1 molszewski1 users  361 Feb  6 13:18 ISBN.h
-rw-r--r-- 1 molszewski1 users 3753 Feb  6 13:17 ISBNPrefix.cpp
-rw-r--r-- 1 molszewski1 users  422 Feb  6 13:15 ISBNPrefix.h
drwxr-xr-x 2 molszewski1 users 4096 Feb  6 13:20 a1
-rw-r--r-- 1 molszewski1 users    0 Feb  6 13:15 a1.cpp
-rw-r--r-- 1 molszewski1 users 6271 Feb  6 13:18 prefixRanges.txt
~@matrix:~/btp200/assignments> mv * a1
mv: cannot move `a1' to a subdirectory of itself, `a1/a1'

How can I move everything into directory a1 excluding a1?

marked as duplicate by derobert, Gilles, George M, jasonwryan, Stéphane Chazelas Feb 6 '13 at 19:51

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.

  • Well, you already did move everything into a1 excluding a1 itself. For avoiding the error message, see the "may already have an answer here" link up top. – derobert Feb 6 '13 at 18:51
10

One way to include everything but one item is:

mv !(a1) a1

This is a feature you need to have enabled first with:

shopt -s extglob
  • 2
    How do i do this in a shell script? I keep getting syntax error near unexpected token `(' – rapidclock Oct 12 '17 at 18:34
3

You can achieve this using following command

find . -maxdepth 1 | grep -v a1| xargs -i mv {} ./a1
2
mv -f * a1

This will force the move to happen despite the argument. Then do an ls after and you will see it worked.

  • For me this works even without -f – frostschutz Feb 6 '13 at 18:38
  • Ah, you're right. I didn't even think to check that. – sparticvs Feb 6 '13 at 19:11

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