Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 directory that is unpacked, but is in a folder. How can I move the contents up one level? I am accessing CentOS via SSH.

share|improve this question

migrated from stackoverflow.com Aug 24 '11 at 18:17

This question came from our site for professional and enthusiast programmers.

With the folder called 'myfolder' and up one level in the file hierarchy (the point you want it to put) the command would be:

mv myfolder/* .

So for example if the data was in /home/myuser/myfolder then from /home/myuser/ run the command.

share|improve this answer
You may need to also match .* not just * if the archive contained dot-files. Also add ` && rmdir myfolder` to the end o that to remove the now extraneous folder. This is save because it will only run if the mv returns success AND because rmdir will not remove a non-empty directory. – Caleb Aug 24 '11 at 20:53
Good point on the .*. Removing the original folder is both trivial and not asked for so we'll let OP deal with that him/herself. – Rudu Aug 24 '11 at 20:57
@Caleb is it possible to write both * and .* in one line? just curiosity – Richard Nov 13 '12 at 20:40
@Richard Yes, it is. The arguments for mv will all be sources except the LAST argument which needs to be the target for moving (and in the case of multiple sources, needs to be a folder). – Caleb Nov 13 '12 at 20:50
tested, and it works. – Richard Nov 16 '12 at 14:39

just issue an mv command

mv (directory)/* .

if you want to delete the directory then add

rm -rf (directory)

Assumed that you are in a parent directory of (directory)

If you are inside the (directory) then

mv * ../
share|improve this answer
Additional safety tip: When deleting a directory you know should be empty, rmdir complains and exits if the directory isn't empty, while rm -r would instead just have deleted it and all its contents. (It's a poka-yoke.) – Anko Jun 14 '14 at 11:40
Great point! I can't think of a reason not to do it that way. – Mark Lalor Nov 21 '15 at 15:03

This is possible either by using rsync:

rsync -vuar --delete-after foo/ .

or cp and rm:

cp -vaR foo/. . && rm -r foo/

or as suggested here by using mv:

mv foo/* foo/.[^.]* . && rm -r foo/


(shopt -s dotglob; mv -- foo/* ..)

where foo/ is your folder to be moved one level up.

share|improve this answer

for those of you on a shared server you'd have to use something like this

To move the files

mv -v ~/public_html/public_html/* ~/public_html/

To copy the files

cp -a ~/public_html/public_html/* ~/public_html/

share|improve this answer
The question above asks about moving not copying contents. This would duplicate the files by leaving the originals in a subfolder. Also being a "shared" server or not really doesn't have anything to do with this. – Caleb Jun 14 '14 at 11:04
your right and here is the answer for it... – Ricardo Havoc Jun 14 '14 at 11:11
Re your edit: how is that any different that the already upvoted answer? And what does a "shared server" have to do with it? Please edit to explain these items if this is going to be a useful contribution that adds value to what is already here. – Caleb Jun 14 '14 at 11:16
I disagree about the shared server not having nothing to do with it. The way the "dir" is entered makes a world of a difference.. – Ricardo Havoc Jun 14 '14 at 11:17
dude why you so mad?... wow.. I was just sharing a little knowledge. We all understand differently and confront different technical problems differently... Have yourself a good day Caleb.. – Ricardo Havoc Jun 14 '14 at 11:19

Your Answer


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