First steps on the Linux Terminal

First of all, we need to SSH access into our server. When this happens we'll have something like this: The characters of a terminal are both from the terminal and typed by ourselves. The text preceding our commands (new-host-6:~ settern$ in the example), is referred to as shell prompt. It can be configured and vary broadly from a computer to another, but it usually gives us some hints (in the example “settern” is the username, new-host-6 is the name of the server, and ~ means the user is in his home directory).

When the terminal offers us a prompt, it's ready to receive commands.

Understanding how to access files is probably one of the most difficult task, when beginning… But it's also essential to work well with Linux, so let's review this.

In Linux and Mac OS X (and with minor variations, this applies to Windows too) we store data in files, and each file can be placed inside a directory (or Folder, as Windows calls them). Linux and UNIX have a “mother folder”, called root directory. For the terminal the root directory is simply a slash: /.

The picture below1) depicts a directory tree.

The picture shows only directories, but let's assume that each directory also contains files. A file name is not enough to locate a file in the file system: a file called “readme.txt” can be present in any directory.

We must use the full path to describe a file position and this can be:

  1. An absolute path
  2. A relative path

Absolute paths are easy: they always start from root, so the have to begin with /. For example: /users/staff/tutorial.txt is an absolute path for a file called “tutorial.txt” inside the directory “staff” that is a subdirectory of “users”, itself belonging to the root directory (/). Note that directory names are separated with a slash.

Relative paths, as the name implies, are relative to the position we are working from (or working directory). Suppose that we currently are in the “/users” directory. To refer to the “tutorial.txt” file we can still use the absolute path (/users/staff/tutorial.txt), but this can be tedious to type. To build relative paths we need two special directory names: . (dot) is the current directory (working directory), while .. (two dots) is the previous directory (the directory a level above ours). This means that ./staff/tutorial.txt is a relative path for tutorial.txt if we are in the /users directory.

Now suppose that we move to /users/admin. In this case the relative paths to the file would be ../staff/tutorial.txt, because we need to go a level above our current directory.

pwd: where are we?

When we log into a server, by default, we are positioned in our home directory. We can type the command pwd (print working directory), to know the absolute path of our current position:

pwd

After typing this command, we'll receive as output a line like: /home/ubuntu.

ls: list files

With the pwd command we can know where we are, while with the ls command we can list files:

ls

We'll receive as output a list of files/directories included in our current directory. ls is more complex than pwd, so we can alter the behaviour of the command adding options (parameters) to the command.

Try this:

ls -l

The -l paramter force ls to print a detailed list of the files, like:

drwxrwxr-x  2 ubuntu ubuntu 4096 Jan  9 20:29 bin
drwxr-xr-x  2 ubuntu ubuntu 4096 Jan  6 09:07 Desktop
lrwxrwxrwx  1 ubuntu ubuntu   22 Aug 15 19:49 galaxy-app -> /mnt/galaxy/galaxy-app
lrwxrwxrwx  1 ubuntu ubuntu   18 Aug 15 19:49 galaxy-indices -> /mnt/galaxyIndices
lrwxrwxrwx  1 ubuntu ubuntu   11 Aug 15 19:49 galaxy-tools -> /mnt/galaxy

mkdir: make directory

We can create a new directory with the mkdir command. Try this:

mkdir Example

The command will tell you nothing, if everything goes ok. So you can use ls to list the files and verify that the directory has been created indeed.

cd: change your working directory

What if we can move to another location? cd (change directory) followed by the absolute or relative path. Here some examples:

cd Example
cd ..
cd /usr/bin

Reference:

1)
taken from the “Further reading” website