Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I have 100 files in a single folder including a folder called "target." I want to migrate all the files in this folder into the folder target (except for the target folder itself).

Is there an efficient terminal command to do this?

share|improve this question
up vote 9 down vote accepted

If there are only the files (and the directory target) in your directory, simply use mv, rather than find:

mv * target

It will complain that 'target' can't be moved on itself, but the files will all be in target afterwards.

share|improve this answer
+1. However, I would use target/ to make sure that I didn't accidentally rename all files to 'target'. – zpletan Mar 29 '12 at 3:25
As long as you've got more than one file to move, that shouldn't be a problem. It doesn't hurt though. – James Henstridge Mar 29 '12 at 4:00
This does not handle hidden files. – Oli Mar 29 '12 at 12:13

This works as well:

find . -maxdepth 1 ! -name target ! -name . -exec mv "{}" target \;

One of the key advantages of find over relying on bash completion is you get the hidden files at the same time. mv * ... won't do that.

You could perhaps go with something like:

mv -t target * .[^.]*

Or as James points out you could trim down the find command to only look at files... And as LoremIpsum pointed out if there are billions of them, using xargs would be slightly more efficient:

find . -maxdepth 1 -type f -print0 | xargs -0 mv -t target
share|improve this answer
You could probably simplify this to find . -maxdepth 1 -type f -exec ... to select by type rather than excluding particular names. – James Henstridge Mar 29 '12 at 4:02
Maybe xargs could be used, too ? – LoremIpsum Mar 29 '12 at 8:14

Use this

$ mv target ..
$ mv * ../target
$ mv ../target .
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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