RC Linux Tutorial

Revision as of 19:09, 13 August 2018 by Botto (talk | contribs) (Created page with "=RC Linux Tutorial= This tutorial has been put together by Research Computing to help familiarize new users with the Linux operating system. At the end of each chapter there...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

RC Linux Tutorial

This tutorial has been put together by Research Computing to help familiarize new users with the Linux operating system. At the end of each chapter there will be a short quiz. It is recommended that you take some time to do the quizzes to aid in remembering the main points of the chapter.

About this tutorial

What is Linux?

Linux is a Unix-like Operating System originally created by Linus Torvalds while he was a student at the University of Helsinki. His main goal was to create a Minix clone and make the operating system, with the entire source code, freely available.

Here is the original quote that Linus made in comp.os.minix about his new operating system.

   Do you pine for the nice days of Minix-1.1, when men were men and wrote their own device drivers? Are you without a nice project and just dying to cut your teeth on an OS you can try to modify for your needs? Are you finding it frustrating when everything works on Minix? No more all-nighters to get a nifty program working? Then this post might be just for you. 


   As I mentioned a month ago, I'm working on a free version of a Minix-look-alike for AT-386 computers. It has finally reached the stage where it's even usable (though may not be, depending on what you want), and I am willing to put out the sources for wider distribution. It is just version 0.02...but I've successfully run bash, gcc, gnu-make, gnu-sed, compress, etc. under it. 

Soon afterwards, Linus received lots email from people that where interested in his project. From there Linux continued to become what it is today, a full-scale multitasking, multiuser operating system.

Who uses Linux?

Linux users come in a variety of different people, although most of its users are fairly knowledgeable about computers and how they work.

   ``Linux is user-friendly. It just chooses its friends wisely. 

Many people are instantly turned off by the fact that Linux is a text-based operating system. It doesn't have all the graphical interfaces that one would expect to see on a MacIntosh® or Windows® operating system. Most of the home-users turn away from Linux when they hear about this. What they don't know is that many companies have put together distributions of Linux that have many graphical equivalents of the text-based utilities, making Linux a real option for the new user.

Linux has become popular for many different uses. Among these uses include web, ftp, dns, and other Internet related servers, software development, database uses, and is also popular with the scientific research community. The reliability of Linux makes it strong in most of these areas. Very few operating systems can stay running stable for months at a time without requiring a reboot of the machine. The free compilers for just about every programming language make Linux an excellent platform for software development, instead of having to pay thousands of dollars for site licenses, Linux users get everything for free. The speed of the operating system makes Linux a good choice for database and scientific related software. For instance, a reputable source claims that Maple® runs three times faster under Linux than it does in Windows®.

Multiple Method Disclaimer

This tutorial is designed to give you a basic idea of how to use Linux so you may program on the CIRCE/SC clusters at USF. It is not solely intended to make you a Linux expert, but should make you comfortable enough to use the system. Since this tutorial will be specific to the basic setup of a user account on the cluster, the examples and programs that are taught will not cover all alternative software. Please note that because we show you one way of doing something doesn't mean that it is the only way. This tutorial will use the bash shell for its examples, there are many other shells that you may choose from, such as: tcsh, korn shell, sh, csh. For the basic commands chapter, the commands will be the same on all Linux distributions. Please note that we will be using RedHat as the distribution for the cluster, there are very little differences between RedHat and other distributions. The main difference being the package system that they use, but you won't really need to use that on the cluster. If you have ever used a distribution other than RedHat you should be able to use our distribution just as easily as the other one.


Getting Started

Since most people have never even seen Linux, it might take a while to get used to. If you have used MS-DOS you should be able to recognize some similarities. Those who have experience using other types of UNIX's should adapt right away as Linux is almost the same in every way.

For those people who have only used windows be prepared to relearn most ways of doing things. You may not be used to using a command line, which is used for most of the basic programs such as listing the files in a directory, and moving and copying files. If you don't like the text based environment you will have to get used to it, although there are many graphical utilities that can do just about anything you want.

Logging In

Linux is a multi-user operating system. This means that many people can log into the system and use it simultaneously. Each user is given certain permissions on what files and programs they can or can't run, they may also have different shells, environment variables, etc.

When you connect to, or boot-up, your system you will be prompted to enter a user name and password:

RedHat Enterprise Linux 6.8
Kernel 2.6.32-696.18.7 on i686

host login: root 

Next you will be prompted for the password for that user:

password: 

After logging in you will be given a command prompt. This is where you will be entering commands to run programs.

   [root@host ~]# 

Users

In the above login example we logged into the system as the user root. The root user is the super-user of the system. Root generally is used to do administrative tasks on the system, install, uninstall, and configure programs for the users. The root user can modify any of the files on the system, which is why you should know what you are doing when using the root account. If you have your own computer with Linux installed on it, you will have access to the root account. The password should have been set during the installation of your distribution. The root account should rarely be used as it can cause serious damage to the system if you are not careful.

You may be asking then, "How do I add a standard user to work with?". This can be done by using the adduser program, while you are logged into the system as root. Simply type adduser into the command-line. He is an example, we will add the user bob to the system.

   [root@host /home]# adduser bob 

Depending on what distribution of Linux you are using the command passwd will be run for the user that you just added. The passwd program changes the password for a user account. If after running the adduser command, you aren't asked to change the password for the user you will want to type in the command 'passwd <user name>' to set the user's password. Otherwise the user can login to the machine with no password, and this is a BAD thing. By default, usually this command will add the user to the system's password file and the adduser command will create them a user home directory under /home/username. So if we look at /home there should now be a directory called bob. Log out as root by typing logout and then login as the user bob.

Setting up the Environment

Each user that is on the system has different settings for their account. These settings are typically what type of shell program they are given upon logging into the system to user-specific settings for globally install programs on the computer. Most of the time the settings are stored in files that begin with a '.' or they are set in the shell program as variables.

Variables

Lets take a second to look at how to use environment variables to specify paths, aliases, and other useful information that we might need.

Variables are used by the shell to temporarily hold information, this way the user can save time by not having to specify something every time a program needs to be found or what the command line should look like. To see a list of all the variables that are set type set in your command prompt, this should list all the variables and their values in the form of "variable=value". If you ever want to check the value of just one variable you can type echo $variablename, where $variablename is the name of variable with the $ in front of it. Typing echo $SHELL will output /bin/tcsh (or whatever your shell program is), the value for the variable SHELL.

We can create and modify variables to give us more flexibility when working with the shell. To create a usable variable we have to declare the name of the variable and then assign a value to it. I will be showing how to do this under the tcsh shell, other shells follow a similar way of declaring variables and usually you can find out how by typing man yourshell.

To change the value of a variable you would type the name of the varible and then assign it a value using the = sign. Here is an example where we tell the shell a path.

   [bob@host ~]$ export PATH="/bin:/usr/local/bin:/opt/gnome/bin
   [bob@host ~]$ echo $PATH
   /bin:/usr/local/bin:/opt/gnome/bin
   [bob@host ~]$ 

As you can see, we now have a variable called path that stores the directories where the shell should look to find files. This way instead of having to type /opt/gnome/bin/gcalc we can now just simply type gcalc from anywhere and the program will run, this saves us a lot of typing in the future if we are using a certain program frequently.

What if we already had a previous value for PATH and we would like to save that value and add our new directories along with it. We can just simply use the variable name with a $ in front of it to use the previous value. So if our path was originally '/usr/bin:/usr/sbin' it is now '/usr/bin:/usr/sbin:/bin:/usr/local/bin:/opt/gnome/bin'. The new line would be:

   export PATH="$PATH:/bin:/usr/local/bin:/opt/gnome/bin" 

There are other things that you can do with the command prompt, you can find more information by typing 'man bash'.

Configuration Files

Lets begin with an example on configuration files and what they are. These are the files in the user's home directory that begin with a '.'. Most of the time when the user logs into their account a file is read be the shell program to set up user settings such as paths, what the command prompt looks like, and other settings that change from user to user.

For an example we will take a look at the configuration file for the bash shell. This file is called .bashrc under the users home directory. If you are using another shell other than bash the file will be different but usually will follow the same naming scheme, i.e. tcsg uses .tcshrc as a configuration file. So, once inside your home directory use the command ls -al to display all the contents of the current directory.

   [bob@host ~]$ ls -al
   total 8
   drwxr-xr-x 2 bob other 512 Apr 22 16:03 .
   drwxr-xr-x 9 root root 512 Apr 22 15:54 ..
   -rw------- 1 bob other 397 Apr 22 16:09 .ssh
   -rw-r--r-- 1 bob other 20 Apr 22 16:09 .bashrc
   [bob@host ~]$

The .bashrc and .bash_profile files hold settings that should be applied whenever the shell is started. Typical settings in here at set commands for specifying paths and the prompt, and other programs that should be run at login. To see what is in this file you can type cat .bashrc and cat .bash_profile. Here is an example:

[bob@host ~]$ cat .bashrc

  1. .bashrc
  1. Source global definitions

if [ -f /etc/bashrc ]; then

     . /etc/bashrc

fi

  1. User specific aliases and functions

[bob@host ~]$ cat .bash_profile

  1. .bash_profile
  1. Get the aliases and functions

if [ -f ~/.bashrc ]; then

       . ~/.bashrc

fi

  1. User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH


As you can see mostly everything in the configuration file is from the previous section. With this configuration file it is possible to save those settings that we prefer and use them whenever we log into the user account. With out a .tcshrc file the shell uses the default settings. You can edit these files to your desired settings with any text editor. If you are new to Unix and have no clue about editing text try a program called pico, this is a fairly straight-forward editor; if have ever use the email program called pine you should be somewhat familiar to it. Editing text will be given in more detail in a future section.

Most configuration files will be commented, providing an explanation about how to use them.