Getting to Grips With SSH – Part 6

By Ollie Armstrong Friday, 3rd December 2010

SSH-guides

Welcome to the sixth part in the series. The series that is the easiest way to get started with SSH.

In the last part, we got to know a powerful terminal text editor, so you will probably have a few more files on your server that you want to move around. So in this part we will be going over the final few commands that can be used to manipulate files. This includes the likes of copying, moving and renaming. After you know these you should be the master of file navigation and manipulation. If you haven’t yet read the previous part, you can find that here: Getting to Grips with SSH Part 5.


Getting Started

You probably know by now that you need to connect to your vCluster, once again here is the link to the guide if you need a hand on doing so.

Copying Files – cp

You are very likely going to want to copy a file on your vCluster, if for backup or another use. Not too taxing on the brain to remember the command for copy.

cp original_file path_to_new_file

The one major point with this command, is in the path to the new file you have to actually type the file name. You’ll understand with an example.

cp index.html backup/index.html

This copies the file index.html to a folder called backup in the current directory. Here’s a screenshot to illustrate.

As you can see, there isn’t an index.html file in the backup folder, but there is in the current folder. I used cp to copy the index file in the current folder to the backup folder. Try it out yourself!

You can also change the name of the new file while copying, this is as simple as changing the path to the new file.

cp index.html backup/index_backup.html

That will do exactly the same as the previous example, but the new file will be called index_backup instead of index.

Moving Files – mv

Incredibly similar to the copy command. Same syntax after the command, just different command.

mv original_file path_to_new_file

The difference between copying and moving is that moving will move the original file and copy duplicates it. Was that obvious?

Renaming Files – mv

Hang on, we just went over moving files and the used the mv command, and now we rename files using the same command? Yep. Basically, there isn’t a command to rename a file, so instead we move the file to the same directory but with a different name. Remember how we just went over when copying files you can change the name of the copied file, we can do the same when moving and that achieves a renamed file.

I have a file that I accidentally called ‘styl.css’ instead of ‘style.css’, so we would use this command to rename it:

mv styl.css style.css

The mv command is moving the file to the same directory but changing the name in the process. So in essence its renaming it, yay!

To Summarise

When moving/copying/renaming files, they all follow the same syntax.

command original_file new_file

Where command is either:

  • mv
  • cp

They should be fairly obvious as to which is which. And to rename a file, we use mv but you move it to the same directory.

Hopefully this has been a pretty easy guide in comparison with the last one, but if you have any questions leave a comment and I will get back to you.


Posted in Guides, SSH | No Comments » twitter-follow facebook-follow rss-follow

Leave a Reply

Your email address will not be published. Required fields are marked *