Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

$ 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
4  
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
add comment

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
add comment

Your Answer

 
discard

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.