USF Home
Administrators
Hardware Status





Search this site
 

Linux Tutorial: Chapter 2

2.0 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.

2.1.0 Logging into the machine

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 7.2
Kernel 2.4.18 on i386

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 ~]#

2.2.0 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.

2.3.0 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.

2.3.1 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 ~]$ set 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:
set path=($path /bin /usr/local/bin /opt/gnome/bin)
Another useful environment variable you can modify is the variable $prompt. This is variable that determines what your command prompt looks like. If you have ever used MS-DOS you may be familiar with this. You can change the prompt to display your username, host, current directory, and more. Lets show you how to format the prompt in the format of 'user@host current_directory'. Try typing into the command-line:
set $prompt="[${USER}@${HOST} %.] "
This should change the command prompt to the user@host format. Lets take a second to break the statement down.
${USER}
This simply takes whatever that value of the environment variable $USER is. If you type echo $USER it should return your current username.

${HOST}
This pretty much is the same as ${USER} except that it returns your host name.

%.
This prints the current directory that you are in.
There are other things that you can do with the command prompt, you can find more information by typing 'man tcsh'.

2.3.2 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 tcsh shell. This file is called .tcshrc under the users home directory. If you are using another shell other than tcsh the file will be different but usually will follow the same naming scheme, i.e. Bash uses .bashrc or .bash_profile 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 .tcshrc
[bob@host ~]$
The .tcshrc file holds 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 .tcshrc. Here is an example:
[bob@zedd ~] cat .tcshrc
#!/bin/tcsh
set path=(/usr/local/bin /usr/bin /opt/gnome/bin)
set prompt="[${USER}@${HOST} %.] "
alias ls 'ls -la'
[bob@zedd ~]
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.

Take Chapter Quiz


 



Copyright © 2008, Research Computing, USF, 4202 E. Fowler Avenue, Tampa, FL 33620