Introduction to the LINUX operating system

Introduction to the LINUX operating system

1.1. What is LINUX?

  • An operating system based on the UNIX operating system, running on a PC
  • An operating system enables the different parts of the computer (central processor, memory, printer etc) to communicate with each other
  • Other operating systems: DOS, Windows 95, 98, 2000, XP (PC), MacOS (Apple Macintosh), UNIX (Solaris, SGI)
  • UNIX was invented in the 1960's, and was transformed into LINUX in the early 1990's by Linus Torval as part of his PhD research.
  • LINUX is free, extremely stable (difficult to crash!) and has a well-established security system for authenticating users and controlling access to files
  • Because of the above advantages, LINUX is increasingly being adopted by large firms and governments as a viable alternative to Microsoft
  • LINUX was originally entirely command line! (not windows-based), but many GUI's are now available for LINUX
  • LINUX commands are small  programmes that can be executed from a GUI's or from the command line
  • LINUX commands tend to have un-user-friendly names (e.g. grep, more, ls), but they are very powerful

1.2. Getting started with LINUX in our laboratories

  • The basic layout of the desktop is called the KDM environment; the alternative Gnome environment can be selected from the login box before logging in
  • The main KDM menu can be called up by selecting the "K" symbol at bottom left of your screen; launch applications as you would in MS Windows
  • Important applications can be found along the static menu at the bottom of the screen
  • Clicking on the icon depicting a shell launches a terminal window
  • In traditional UNIX, commands are executed from the command line, in a window called a terminal or a shell (hence the icon)
  • Each shell is a separate process (programme) running on the central processor of the computer
  • You are free to choose from a number of different types of shell: Bourne-shell (bsh), Korn-shell (ksh), c-shell (csh), tc-shell (tcsh), Bourne-again shell (bash)
  • We will use the tcsh, as it allows recall and editing of previous commands, which is very useful.

1.2.1. Logging in

  • Username: guest
  • The system will prompt you for a password: guest
  • LINUX has well-configured security system
  • Rules for selecting passwords: at least 6 letters or numbers, beginning with a letter
  • LINUX is case-sensitive
  • some obvious passwords will not be accepted by the system

1.2.2. Executing commands

Each UNIX command is actually a separate process (many of them are just C programmes) that is launched by the shell process when you hit Return. Traditional LINUX commands run entirely within the window in which they were launched, taking their parameters from the command line and sending their output back to the shell window (e.g. ls). But increasingly programmes are being written to run in separate windows (Graphical User Interfaces, or GUI's), with parameters selected using a mouse. Well-known examples are Netscape and Word.

1.2.3. To change your password

%passwd

You will be prompted to enter your old password, then the new password and then the new password again for validation.

1.2.4. Find out which directory you're in

%pwd (print working directory)

/home/david

This is my home directory. I am the only user (apart from the superuser, also called root) who should be able to create files in or below this directory. By default anyone should be able to read any of them, although this can be easily changed by the owner.

1.2.5. List files in current directory

%ls (list)

%ls -l (long listing, including time of last modification)

%ls -t (list in order of last modification)

%ls -lt (last two together)

1.2.6. Create a new directory in the current directory

%mkdir newdirectory (make directory with the name "newdirectory")

  • N.B! LINUX does not like spaces within filenames
  • A better option when using LINUX is to use an underscore; e.g. new_directory
  • If you must use spaces in a name, indicate the space by preceding it by a backslash; e.g.
    % mkdir new\ directory

1.2.7. Change into new directory

%cd newdirectory (change directory to newdirectory)

%pwd will now show that /home/guest/newdirectory is the current directory. Any files you create now will be created within this directory

1.2.8. Short-cut to return to home directory

%cd

1.2.9. The directory tree

The LINUX file-system is arranged like the roots of a tree, beginning with a single root and branching into more and more sub-branches. The topmost directory is called the "root" and is represented by /. The following command places you in the root directory:

%cd /

1.2.10. Example

Below the root are important subdirectories:

  • /bin contains the binaries (executables) making up the LINUX operating system
  • /etc and /var contain miscellaneous system-related stuff
  • /home contains the home directories of all users
  • /usr contains user-specific files:
    • /usr/local contains locally-installed software (i.e. not part of the general distribution);
    • /usr/data is where our large data-sets are stored. The Carnegie network is set up so that these directories are accessible from any of the machines (i.e. you don't have to work at the same machine in order to get access to files saved previously.)

1.2.11. Exercise

List (ls -l) some of the top-level directories to see what they contain.

Use more to look at the contents of /etc/passwd and /etc/group.

1.3. Creating and manipulating files

Most LINUX-related files are written in plain text (typewriter characters only, also called ASCII), unlike graphics files which contain binary numbers or MS Word files which contain other codes and metacharacters in addition to ASCII. There are many text editors available; the one we will be using is called nedit. To launch it, type:

% nedit

Open a new file and enter the text "This is my first file" and save it to your home directory under the name "first_file.txt".

1.3.1. Move a file to another directory

The following command moves the file first_file.txt from my home directory to the directory newdirectory:

%mv /home/david/first_file.txt /home/david/newdirectory/first_file.txt.

1.3.2. Exercise

Move your own copy of first_file.txt to your own newdirectory directory. Check that the file has been moved using %ls -l in the relevant directories.

/home/pugh/first_file.txt is known as the path of the file first_file. Where the context makes the path clear, it may be omitted, as follows:

%mv first_file.txt newdirectory

1.3.3. Warning

If the directory exists called newdirectory, then first_file.txt will be moved into it. If not, LINUX will simply change the name of first_file.txt to newdirectory. A safer practice would be to include the slash after the directory name:

%mv first_file.txt newdirectory/

which will cause LINUX to complain if there is not already a directory of that name.

To move a file and change the name at the same time, include the new name in the target path:

%mv /home/pugh/first_file.txt /home/pugh/new_filename.txt

1.3.4. Copying a file

To copy a file to another directory (without deleting the original):

%cp filename target_directory

To change the name of the copy, include the new name in the target path, as before.

1.3.5. Listing the contents of files

The command %more filename lists the contents of the file filename one page at a time. Spacebar moves on to the next page while b moves back one page. Return moves down one line at a time.

1.3.6. Exercise

Try moving the file first_file.txt to one of your fellow students' home directories. Try listing the files in their directory and reading the contents of files using more. What do you conclude?

1.4. Piping commands

A useful feature of LINUX is that commands are easily linked together, so that the output from one serves as the input to another. This is achieved using the | command, which is known as a "pipe". For example,

%ls -l /bin | more

causes the listing of the files in /bin to be listed page by page, rather than flashing across the screen.

1.5. Permissions

List the contents of your home directory using ls -l. On the extreme left of the listing you will see a column of characters ending in rwxrwxrwx. The first triple indicate that the owner of the file has read (r), write (w) and execute (x) permission on the file. The owner of the file is the name appearing in column 3 of the listing. The second three permissions relate to any user in the group whose name appears in column 4, called the group owner of the file. The third triple relate to all users. Dashes ('-') indicate that the the corresponding permission is not available to that user.

1.5.1. Example

The permissions for first_file.txt should allow the owner (you) to read, write or execute the file, members of the group users to read and execute but not write (alter), and the same for all users.

1.5.2. chmod

To change the permissions allowed to each category of user, use the command chmod. Only the owner of a file (and the superuser) may change its permissions.

1.5.3. Exercise

To remove read permission to first_file.txt for members of the group all:

% chmod a-r first_file.txt

To add write permission for members of the owner group of first_file.txt (in this case users):

% chmod g+w first_file.txt

To set the permissions for members of the owner group to --x:

% chmod g=x first_file.txt

1.5.4. What is execute permission?

If a file is an executable, it cannot be invoked by a user unless that user has execute permission on the file. If the 'file' is actually a directory, then removing execute permission for a user means that the user cannot make that directory their current directory.

1.5.5. chown

It is also possible (but only for the owner and the superuser) to change the user categories applying to a file, using the command chown. For example:

% chown jason.nmr first_file.txt

will make jason the new owner of the file first_file.txt, and at the same time change the group owner to nmr (see the list of all defined groups in /etc/groups). Unfortunately once you have given away ownership of your files, the only way to get it back is to ask the user to whom you gave them, or else the superuser.