Super User is a question and answer site for computer enthusiasts and power users. 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 a folderA that contains folderB that contains a lot of files. I would like to get rid of folderB, but not its contents. I want those contents to be inside of folderA. How can I accomplish this on the commandline?

share|improve this question
$ cd /path/to/folderA
$ mv folderB/* .
$ rmdir folderB
share|improve this answer
1  
mv folderB/* . ? what is the dot? – NewLinuxUser Jun 11 '10 at 16:44
5  
Watch out for dot files (files whose name begins with .) as this will not include those. Do mv folderB/.* . to move them as well. @NewLinuxUser, the dot in your question is an alias for the working directory (in this case, folderA). – Brian Jun 11 '10 at 17:36
    
This fails if folderB/folderB exists, so beware of using it in scripts. – filipos Feb 19 at 15:21
    
This also fails if folderB contains an insane amount of files. You will see bash: /bin/mv: Argument list too long because of the use of *. If that's the case use mv in combination with find as stated by @amphetamachine, or with a for loop – Javier de la Rosa Apr 5 at 15:10

Quick answer:

cd /path/to/folderA
find folderB -maxdepth 1 -mindepth 1 -exec mv {} . \;
rmdir folderB

Code-hardy answer:

cd /path/to/folderA
folderB_temp="$(mktemp -d -t folderB.XXXXXX)"
mv folderB "$folderB_temp"
find "$folderB_temp/folderB" -maxdepth 1 -mindepth 1 -exec mv {} . \;
rmdir --parents --ignore-fail-on-non-empty "$folderB_temp/folderB"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .