Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

marked as duplicate by derobert, Gilles, uther, 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

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
share|improve this answer
mv -f * a1

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

share|improve this answer
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

You can achieve this using following command

find . -maxdepth 1 | grep -v a1| xargs -i mv {} ./a1
share|improve this answer

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