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

Is it possible that if I have this:


Can I delete folder2 but keep its content?

So the result would look like:

share|improve this question

I think that you don't need to actually delete something... just move it away.

mv  /folder1/folder2/*  /folder1/
rmdir /folder1/folder2/

First command moves the contents to parent directory and the second removed the directory if it's empty. This won't move hidden/dot files. If you want also to move hidden files you would need:

mv  /folder1/folder2/{*,.*}  /folder1/
rmdir /folder1/folder2/

or use dotglob option in bash. If you don't have dot files it would lead to no matches found: dir1/dir2/.* in bash and the command would fail. Also you can ignore the:

mv: cannot move ‘folder1/folder2/..’ to ‘folder1/..’: Device or resource busy

errors since bash passes . and .. to mv.

share|improve this answer
cd /folder1/folder2/
mv * ../
cd ../

Now check the contents of the folder:


Then use this command to delete the directory. It is completely safe since it will only delete empty directories:

rmdir folder2/
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.