Linux tutorial, part 3 (ssh, cd, ls, cp, mv)

Logging in to a remote system

To login to that system I'll use a command named ssh, which stands for "secure shell". It's basically an encrypted login session to a remote system. To login to that remote system I'll type this command in my terminal window:

ssh al@foo.bar.com

(Of course everything after the ssh command there is made up. I don't have a login account on any systems named anything like that.)

Again my username on that remote system is "al", so I supplied it with the ssh command when I logged in. After a few moments the remote system prompts me for my password, which I type in. After entering the correct password the remote system logs me in. My command-line prompt on that system is very simple, and looks like this:

foo.bar.com:/home/al> _

I set up my prompt this way to remind me that I'm now working on that remote system, and not my local system.

Moving around a remote system

Typically I'm working on a web site, like devdaily.com, so the first thing I need to do is change to the correct directory, something like this:

cd /sites/www.devdaily.com/html

The Unix filesystem is a hierarchical system, just like Windows, and just like folders on Mac systems, so I just moved from one location in the filesystem to another with that command. On Unix systems there aren't things like drive letters (like "C:"), everything just comes off the top-level root directory ("/").

Now that I'm in this directory my prompt changes so it looks like this:

foo.bar.com:/sites/www.devdaily.com/html> _

That's cool, it always shows where I am.

Copying and moving files

Next, I want to move that file that I transferred to this system into this directory. If I wanted to copy the file to this directory I'd use the Unix cp command, like this:

cp /tmp/foo.html .

which means "copy the file named foo.html from the directory /tmp to the current directory". This leaves one copy in the /tmp directory, and makes a duplicate of that file in the current directory.

But, in my case I just want to move the file, so I use the mv command instead:

mv /tmp/foo.html .

Using either command, if I don't get any error messages you can assume that the command succeeded. This is the Unix way. If the file really didn't exist in the /tmp directory I would have seen an error message, like this:

mv: /tmp/foo.html: No such file or directory

However, if I don't trust the system I can always confirm that it's in the local directory by using the __ls__, or "list" command. I could type this to keep it short:

ls foo.html

or any number of different options to see a longer listing, with more detail.