Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

5 Answers 5

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
3  
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
1  
@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 at 11:40

mv (directory)/ ../

share|improve this answer
    
What are the parens supposed to represent here? This looks like it would the directory itself not the contents of the directory like the OP asked. –  Caleb Aug 24 '11 at 20:51

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
1  
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 at 11:04
    
your right and here is the answer for it... –  Ricardo Havoc Jun 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 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 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 at 11:19

Here's what worked:

   cp -a /old/dir/* /new/dir/
share|improve this answer
2  
However, this will leave those contents in the old/dir/ as well since this is a copy. –  Dan W Aug 24 '11 at 18:11
3  
This is a copy not a move, and doesn't actually answer your original question (which talked about moving data) –  EightBitTony Aug 24 '11 at 19:40

Your Answer

 
discard

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