How to move or copy files with SSH

Rudtek Knows Ssh

When developing a theme in WordPress, it’s often easier to move files or directories on the webserver than downloading and re-uploading all the files together.  You may need to move one or more files/folders or copy them to a different location. You can do so using an SSH connection.

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

The SSH MV command

The mv command syntax looks like this:

mv original_file new_name

By executing the above command you will move (rename) the file original_file to new_name.

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

mv www/* ./

This will move all files (and folders) from the www/ directory to the current working directory.

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

mv –u themes/* themes/backup

This is great if you’re moving files from your dev to a live server, but what if you want to back up your whole site before you start working on it?  (as in creating a WordPress directory backup.)  See what’s next!

The SSH CP command

The copy (cp) command works the same way as mv, but instead of moving the files/folders it copies them. For example:

cp original_file new_file

The command will copy the original_file file to new_file and will preserve the original one (the file will NOT be removed after it is copied).

cp also accepts various arguments:

cp –R www/ www_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 –Rf themes/customtheme themes/backup/customtheme/