How to move and copy files using SSH Print

  • 0

Very often you will need to move one or more files/folders or copy them to a different location. You can definitely drag and drop your files/folders using the file manager feature in cPanel. However, the easiest way to do this is via SSH. It could take a bit to be familiar with different SSH commands, but once you get the hang of it, SSH makes everyones lives a lot easier.

The commands which you would need to use are mv (short from move) and cp (short from copy).

The mv command syntax:-

mv local.xml.sample local.xml

You can also use mv to move a whole directory and its contents:-

mv public_html/subfolder/* public_html/

This will move all files and folders from the location - public_html/subfolder/ to public_html

In some cases however, we will need to only update the files and move only files that were changed, which we can do by passing ‘-u’ as argument to the command:

mv -u test/* admin/test

The cp (copy) commands is similar to mv, but it copies the files/folders instead of moving it from one location to another.

cp local.xml.sample local.xml

The command will copy the local.xml.sample file to local.xml and will preserve the original file (the file will NOT be removed after it is copied).

cp also accepts various arguments:

cp -R admin/ admin_backup/

-R instructs cp to copy files recursively (for example, a whole directory). To overwrite already existing files you should use the -f argument:

cp -fR admin/ includes/admin/

The following commands in your console should show all available options and switches for both the commands. It pulls up the manual of the commands

man mv 
man cp

Was this answer helpful?

« Back