Move files from one directory into another without affecting the existing directory using mac terminal

June 18, 2009

As part of using mac terminal more and more in my own day to day work, I today needed to be able to move all the files and folder from a directory back one directory in the main http folder on my server.

I needed to move all of the files from a file that I unzipped straight to the server, which unfortunately also created another subfolder called PhpEx in my http directory.

So I want to copy of the files and folders from /sites/ back a directory to /sites/

This is how I did it:

mv /sites/* /sites/

Notice the * this denotes move everything within the folder but not the actual folder. This will also leave the existing folder untouched exactly where it already is.

If you wish you can then delete the PhpEx folder and all its files with one simple command.

rm -rf /sites/

Hope this helps

About me

Hello! I'm David Heward, how are you going? I'm a Senior Devops/Build Engineer, specialising in AWS & Cloud Automation. Based in London. Strong 10+ year background in Software development. Have a read of my blog. Have a look at some of my working projects. Contact me at @davehewy or on Linkedin.