My directory (in Linux) looks like com/com/{various,files} where com and com are folders of the same name and the second com holds the various files. I want the first com removed, but the second and files in the second kept.

  • 2
    mv com COM; mv COM/com com; rmdir COM Sep 2 '14 at 2:51

Rename the outer directory out of the way, move the inner one to the name you want, and then delete the (now empty) outer directory:

$ mv com to-delete
$ mv to-delete/com com
$ rmdir to-delete

You could also mv com/com/* com and remove the inner directory, if you don't have too many files and none of them are dotfiles, but the above is more general and more efficient.


The only way to accomplish this is to move the "various files" up a level and then remove the second "com" directory.


$ mv com/com/(various files) com/.
$ rmdir com/com

So here you have this all in one:-

mv com/com/ SOME-TEMPORARY-NAME ; rm -rf com ; mv SOME-TEMPORARY-NAME com

The ; simply lets you run all the commands in one go.

And then I have used rm -rf so that even if you have any other files inside com/ all will be removed without user-interaction.

  • You've been around long enough that you should know: one or two line answers are not considered terribly helpful. Consider expanding your post with some explanation or documentation (or perhaps reasoning for the -rf there).
    – HalosGhost
    Sep 2 '14 at 3:51
  • @HalosGhost Sorry, short question, short answer ;) . I have updated the answer now.
    – beginer
    Sep 2 '14 at 4:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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