Linux


This page is under development. For a printable version of my old linux notes click here .


There are operating systems which you love when you use them and there are operating systems which you may love ONLY when you do not use them ! Linux is an example of the first and Windows is of the second. In this short introduction to Linux, I plan to discuss things which are of practical or direct use. If you are interested in history, geography or philosophy of Linux google that.

In this tutorial I will discuss some common Linux commands which are in general used for the following tasks:

  1. To monitor various hardware resources like CPU, RAM, Hard disk etc.
  2. To manage files and directories i.e., create, delete, move etc.
  3. To manipulate ASCII data files using editors like vi, pico, xemacs and scripting languages like sed and awk.
  4. To run programs in c, fortran and some other languages.
  5. To access a remote computer.

In the end of the tutorial I will also include a test which has different levels of difficulties i.e., Level I and Level II.

Linux Commands

1. Linux shells

In general, on a Linux system tasks are accomplished by typing commands on a shell and the shell translates these commands into instructions which computers can understand. Typically there are more than one type of shells on a linux system. Some of the common shells are the bash, csh and tcsh. Apart from interpretation commands, shells have their own languages also (called shell scripts) which can be used to do various type of complex tasks related to system management etc. In order to see which shell you are using type

> echo $SHELL    

A shell remembers all the commands it interprets and allows short-cuts also. For example, if you type acro on a bash shell and press the TAB key then the shell automatically completes the command which starts from acro. If there is just one command which starts from acro otherwise it gives a list of all commands which start from acro. Note that you can also configure the look and feel of a shell according to your taste. If your default shell is bash and you want to use csh shell, use the following command

> csh

When you type a command, the shell looks for that command (executable) in some familiar places (directories) which are shown by

>   echo $PATH  

If the command is not found in any of these places than the error message is returned. If we want to add any other command (executable) in the list of the commands which a shell can interpret, you can add the path of that command in the existing path

 > PATH=$PATH:PATHOFCOMMAND  

where PATHOFCOMMAND is the path of that command.

Note that the binary executable for all the commands which are available for the user on a Linux system are kept mainly in the directory "/bin" which you can see using:

> ls /bin

For every command there is a man page and a help page available which you can see using:

> man command

and

> command --help

2. Login, password and IP address

In general, a username and password is given to every user on a Linux system. If the user knows the IP address also (which acts as an "identity") of the computer, the user can login into that computer remotely and can exchange files with the remote computer, if they are connected over the network. In order to remotely login a machine the following command is used:

>ssh -X username@hostname

where "hostname" can be the IP address or "name" of the remote computer.

In order to transfer files, the following command is used:

> scp filename username@hostname:dir

where "dir" (see the next section) is the directory in which the file will be transferred on the remote computer.

In order to copy a directory the following command is used:

> scp -r direname username@hostname:dir

scp command can be used to transfer files or directories from a remote computer to the local computer also using:

> scp username@hostname:filename .

Here dot (.) says that the remote file will be copied in the current directory. In order to check if the remote computer is up and is connected to the network, the following command is used:

> ping hostname

3. Monitoring processes and resources

At any point of time many processes are running on a Linux system simultaneously. Some of these processes are necessary for the system to work and others are optional. Some of the optional processes are generally started by users. Every process contributes some amount of CPU and RAM use which can be checked by using the following command:

> top

This command gives the information about the user who started the process (owner), the CPU and RAM use , the time for which the process is running etc. In place of top the following command also can be used:

> ps -ef

The second column of the output of the above command gives the PID (process ID) of the process which can be used to terminate the process using:

> kill -9 PID

If you wish to terminate every process running on the system use: > kill -9 1

In order to see the use of the hard disk (HDD) the following command is used:

> df -h

This gives the free space on various partition of a hard disk. In order to see the disk space taken by a file or directory in mega bytes (MB) the following command is used:

> du -m filename

The total use of the hard disk by a user is given by:

> du -ms 

In order to see which Linux the computer is running the following command is used:

> uname --a

The above also can be used to know the type of processor (32 bit/64 bit) and operating system being used.

Some of the important parameters of the Linux setting are shown by:

> env

4. Making your own command AKA alias

Any executable can be considered as a "command" if it is in in the "path". You can also make an executable a "command" my liking that in a file called ".bashrc" which stays in the home directory. If it does not exists, you can create that. Not only that you can make short form of many commands using ".bashrc". For example, I have an executable named "devnag" in the directory "/data/software/velthuis/bin/linux/i386" and I want to make it as a command then I can write in ".bashrc"

alias devnag='/home/jayanti/software/velthuis/bin/linux/i386/devnag'

5. Permissions

Every file and directory in a Linux system has three type of permissions, named read(r), write(w) and execute (x) associated with. The permissions can be changed by either by the "owner" of the file or directory or by the "root". You can see the permission and ownership of a file/directory using:

> ls -l filename

where "filename" is the name of the file or directory. For example if I run this command on one of my files named "linu.html"

> ls -l linux.html 

I get the following output

-rw-r--r-- 1 jayanti jayanti 8875 2010-07-02 11:42 linux.html

In the above line there are ten characters in the first column (underlined part) which represent read (r), write (w) and execute (x) (starting from the second character) permissions for the owner, users belonging to owner's group and rest of everybody. If the first character is "d" then the given entity is a directory. The third and fourth represent the name of the owner. The owner can give or take various permissions for all or groups. The read, write and execute permissions are represented in the following way:

Permission Symbol Numerical Value
Read r 1
Write w 2
Execute x 4

The command which is used for changing permission is chmod which is used in the following way

chmod  A B C filename  

where A,B and C are integers which are between 1 and 7 and represent the permissions for the owner, the group and everybody respectively. If you want to give only read permission use 1 and for all use 7. For example if you want to give all the permissions and read and execute permission to all others for a filename "myfile" then use the following:

chmod 755 myfile 

If you want to apply these permissions to all files inside a directory "mydir" then use:

chmod 755 -R mydir  

using various combinations you can give or take permissions to other.

Apart from using number one can use "+/-" and "r,w,x" for changing permissions. For example if you want to give read and execute permissions to everybody (a) for a file name "myfile" use the following:

chmod a+rx myfile 

in the above "+" means giving. Using "-" you can take away permissions also. For example if want to take away all the permissions for the file "myfile" from everybody excluding you, use the following:

chmod 700 myfile

You can change the ownership of a file (if you are the owner) named "myfile" use the following:

chown newowner.newowner myfile

where "newowner" is the login id of the new owner. If you you want to apply this for all the files inside a directory use "-R" option.

do not forget to check the new permissions using "ls -l" after every change otherwise you may be in serious trouble !

Valid HTML 4.01 Transitional

This document was last modified on 02/27/2017 10:11:03