3.1. Basic Linux


Logging into Linux

To log into Linux, use one of the following methods.

  1. Go to Austin 208 and log into one of the machines. Your login ID and password are your pirate ID and password — the same ones you use for your email.

  2. Log in from your computer (over an internet connection). For that, you will need to get two pieces of software.

    1. You will need to use the student virtual private network (VPN). You can either set up a VPN connection immediately from there or download the software to your computer so that you do not need to use the web start for it.

      The VPN is needed because the university has disabled access to port 22 (used by NX and SSH) except from machines that are at ECU. (They have also disabled it for access from the PIRATES wireless network, but not from the BUCANEER network.) After you start the VPN, all packets that your computer tries to send to any machine in the ecu.edu domain will be sent instead to the VPN, which forwards them to the desired machine. It appears that the packets originated at the VPN, so they are allowed to get through.

    2. Get the NX client from NoMachine.

    To log in using NX version 3.x, do the following.

    1. Be sure that you have started the VPN.

    2. Start NX.

    3. Click on configure. Set the login id to your id, the operating system to Unix and the host to login.cs.ecu.edu. Set the window manager to either Gnome or KDE. If you do not know which to select, choose Gnome. After configuring, press the login button.

    4. Enter your password when asked. It will take a minute to set up the screen, which is managed by login.cs.ecu.edu. The things that you do there are done on that server.

    To log in using NX version 4.x, do the following.

    1. Be sure that you have started the VPN.

    2. Start NX.

    3. Press continue enough times to get to the login screen.

    4. Press the first button to the right of the lightning bolt (add a computer). Choose a name for this profile. (You will be able to start it up again using that name.) Enter

      1. Host: login.cs.ecu.edu
      2. Protocol: SSH
      3. Port: 22

    5. Click on Advanced. Select Use the NoMachine login. Click continue then connect.

    6. Enter your pirate id and password. Click OK.

    7. You will get a page showing active sessions on the server. Scroll down to the bottom of the screen and select New virtual desktop or custom session. Select either the Gnome or KDE desktop manager. I prefer KDE, but many people prefer Gnome.

    8. Press Continue. You should get a screen showing a sequence of a few small icons at the bottom and a button labeled OK. Select the second icon at the bottom of the page. Press OK enough times to get to the user screen. You are logged in.

  3. For a simpler but faster interface to the same server, use the SSH client. You can get a Windows version here. Run it to install the client. Run the client and select Quick connect. Enter your login id and the host (login.cs.ecu.edu).

    The interface that you get is text-only. Keystrokes done in the terminal window are sent to the server, but what you do with the mouse is not sent to the server at all.

    Press the yellow button with blue dots to open a file transfer window. You get a window that shows your computer on one side and the server on the other. You can drag files from one side to the other with the mouse to transfer them.

    If you want to edit files using this interface you will need to learn a text editor such as emacs that is suitable for a text-only interface.


Using the desktop

You can start a terminal in Gnome by right-clicking on the background and select open in terminal.

To start a terminal in KDE, click on the box at the lower left of the screen. Select system tools and select terminal. You will be offered a choice of terminals. I recommend the Gnome terminal.

There are several buttons and menus that you can explore. But everything that you need can be started from a terminal, and that is all that is described here.


Linux commands

Type a command into a terminal window after the prompt. Always end a command with the enter key.

gedit&

Run a text editor (gedit). The & symbol at the end of the command tells the terminal not to wait for gedit to finish. That way, you can keep using the terminal without closing gedit. The gedit text editor is simple and easy to use.

firefox&

Start the firefox browser.

cd dir

A directory is the same as a folder. It holds files and other directories. You always have a current working directory. Any files that you mention are assumed to be in the current working directory. The cd command sets the current working directory to a given directory.

pwd

Show the current working directory.

Paths

You refer to a file by saying how to find it, either starting in the current working directory or starting in the main directory of the computer (called the root directory). Use / to separate directories, or to separate a directory from a file name. Do not use \.
  1. A path that starts with / starts in the root directory. For example, /bin/ls is a file called ls in the directory called bin in the root directory. (It is the executable code for the ls command.)

  2. A path that does not start with / starts in the current working directory. For example, if your current working directory is your home directory, 3300/test/trial.cpp describes file test.cpp in directory test that is in directory 3300.

Your home directory is /home/INTRA/your id. But you can abbreviate that as ~. For example, ~/3300 is the directory or file called 3300 in your home directory.

Each directory has two special directories in it that are created automatically. File . (just a dot) refers to the directory itself. File .. refers to the directory that contains this directory. For example, if the current directory has a file called assn1.cpp, then you can write path ./assn1.cpp to say explicitly to look in the current directory. Command

  cd ..
sets the current working directory to its parent, the one that contains it. For example, if your current directory as ~/3300/assn1 and you do command cd .., then your current directory becomes ~/3300. Another cd .. makes the current directory be ~.

mkdir dir

Create directory dir. For example,
  mkdir 3300
creates a directory called 3300.

ls

List the names of the files and directories in the current directory. (The first letter of this command is a lower case ell.)

Use

  ls -l
to get a listing that shows details about the files and directories. Use
  ls -F
to get a listing that shows a / after the name of each directory.

Normally, the ls command does not show files whose names begin with a dot. To see all files, use

  ls -a
Add multiple options to get the effect of all of them.

cp old new

Make a copy of file old, and call the copy new. Both old and new are paths. For example,
  cp assn1a.cpp assn1b.cpp
creates a copy of assn1a.cpp and calls the copy assn1b.cpp.

If new is an existing directory, then cp creates a file in that directory with the same name as old.

Use cp -R ... to copy an entire directory. For example,

  cp -R 3300 3300.bak
creates a copy of directory 3300 and everything in it, and calls the copy 3300.bak.

mv old new

Move file or directory old to new. If new does not already exist, then this is just a renaming. For example, command
  mv assn1.cpp assn1a.cpp
renames assn1.cpp to assn1a.cpp.

If new is an existing directory then the mv command just moves old into directory new

rm path

Remove file path. If you want to remove a directory and everything in it, use
  rm -r dir
Be careful. The rm command does a permanent removal. You cannot get the file back.

rmdir dir

Remove directory dir, but only if it is empty. (A directory is defined to be empty if it only contains . and ...

man command

Read the manual entry for command. For example,
  man ls
shows the manual entry for ls in the terminal. It will show one page at a time. To go to the next page, press the space bar.

!!

Redo the previous command.

The PATH environment variable

You can set environment variables that control how Linux works for you. One environment variable tells Linux where to look for the executable files that perform commands. Its value is a string that is a sequence of directories separated by colons. For example, a setting of PATH =

  .:/bin:/usr/local/bin
says to look first in the current directory (.), then in /bin (where many commands are kept) and then in /usr/local/bin (where a few commands are put). In a command, you refer to path by $PATH. Command
  echo $PATH
shows you the current value of PATH. Command
  export PATH=.:/bin:/usr/local/bin
sets PATH to be .:/bin:/usr/local/bin. Typically, you put commands into a file such as ~/.bashrc (which is read each time the bash command processor starts).


Exercises

  1. Which pieces of software do you need to log into login.cs.ecu.edu from your computer? Answer

  2. How can you transfer files between your computer and login.cs.ecu.edu? Answer

  3. How to you enter commands? Answer

  4. How can you create a C++ file using Linux? Answer

  5. How do you create a directory called dir? Answer

  6. How can you set your current working directory to dir? Answer