Vous êtes sur la page 1sur 12

Linux Operating System

Linux is a free open-source operating system based on Unix. Linux was originally created by Linus Torvalds with the assistance of developers
from around the globe. Linux is free to download, edit and distribute. Linux is a very powerful operating system and it is gradually becoming
popular throughout the world.

Advantages of Linux
1. Low cost:
There is no need to spend time and huge amount money to obtain licenses since Linux and much of it’s software come with the GNU
General Public License. There is no need to worry about any software's that you use in Linux.

2. Stability:
Linux has high stability compared with other operating systems. There is no need to reboot the Linux system to maintain
performance levels. Rarely it freeze up or slow down. It has a continuous up-times of hundreds of days or more.

3. Performance:
Linux provides high performance on various networks. It has the ability to handle large numbers of users simultaneously.

4. Networking:
Linux provides a strong support for network functionality; client and server systems can be easily set up on any computer running
Linux. It can perform tasks like network backup more faster than other operating systems.

5. Flexibility:
Linux is very flexible. Linux can be used for high performance server applications, desktop applications, and embedded systems. You
can install only the needed components for a particular use. You can also restrict the use of specific computers.

6. Compatibility:
It runs all common Unix software packages and can process all common file formats.

7. Wider Choice:
There is a large number of Linux distributions which gives you a wider choice. Each organization develop and support different
distribution. You can pick the one you like best; the core function's are the same.

8. Fast and easy installation:


Linux distributions come with user-friendly installation.

9. Better use of hard disk:


Linux uses its resources well enough even when the hard disk is almost full.

10. Multitasking:
Linux is a multitasking operating system. It can handle many things at the same time.

11. Security:
Linux is one of the most secure operating systems. File ownership and permissions make linux more secure.

12. Open source:


Linux is an Open source operating systems. You can easily get the source code for linux and edit it to develop your personal
operating system.

Today, Linux is widely used for both basic home and office uses. It is the main operating system used for high performance business and in
web servers. Linux has made a high impact in this world.
Linux Vs Windows
Linux is an open-source Operating System. People can change codes and add programs to Linux OS which will help use your computer better.
Linux evolved as a reaction to the monopoly position of windows. you can't change any code for windows OS. You can't even see which
processes do what and build your onw extension. Linux wants the programmers to extend and redesign it's OS. Linux user's can edit its OS and
design new OS.

All flavors of Windows come from Microsoft. Linux come from different companies like LIndows , Lycoris, Red Hat, SuSe, Mandrake, Knopping,
Slackware.

Linux is customizable but Windows is not. For example,NASlite is a version of Linux that runs off a single floppy disk and converts an old
computer into a file server. This ultra small edition of Linux is capable of networking, file sharing and being a web server.

Linux is freely available for desktop or home use but Windows is expensive. For server use, Linux is cheap compared to Windows. Microsoft
allows a single copy of Windows to be used on one computer. You can run Linux on any number of computers.

Linux has hign security. You have to log on to Linux with a userid and password. You can login as root or as normal user. The root has full
previlage.

Linux has a reputation for fewer bugs than Windows.

Windows must boot from a primary partition. Linux can boot from either a primary partition or a logical partition inside an extended partition.
Windows must boot from the first hard disk. Linux can boot from any hard disk in the computer.

Windows uses a hidden file for its swap file. Typically this file resides in the same partition as the OS (advanced users can opt to put the file in
another partition). Linux uses a dedicated partition for its swap file.

Windows separates directories with a back slash while Linux uses a normal forward slash.

Windows file names are not case sensitive. Linux file names are. For example "abc" and "aBC" are different files in Linux, whereas in Windows it
would refer to the same file.

Windows and Linux have different concepts for their file hierarchy. Windows uses a volume-based file hierarchy while Linux uses a unified
scheme. Windows uses letters of the alphabet to represent different devices and different hard disk partitions. eg: c: , d: , e: etc.. while in linux "
/ " is the main directory.

Linux and windows support the concept of hidden files. In linux hidden files begin with " . ", eg: .filename

In Linux each user will have a home directory and all his files will be save under it while in windows the user saves his files anywhere in the
drive. This makes difficult to have backup for his contents. In Linux its easy to have backup's.

Linux File Permissions


Linux files have their own permissions set-up. There are mainly 3 types of access permission: -
1. Read
2. Write
3. Execute

Permission sets in linux for files and directories


There is permission set for the Owner, Group and Others. When you type " ll " you will get 10 set of values for each files eg: -rw-rw-r-- 1 name
name 41333 Aug 18 22:57 jpg . The 1st bit denotes if its a directory or file. 2nd, 3rd and 4th bit is the owner's permission. 5th, 6th and 7th bit is
group's permission and 8th, 9th and 10th bit is for other's permission. According to the example owner and group has read/write permission
and other's have only read permission.
You can change the permission of a file. Try chmod 777 filename. This will give owner, group and other's full permission (read/write/execute)
over the file.

Permission Sets

 1 - Execute
 2 - Write
 3- Write and Execute
 4- Read
 5- Read and Execute
 6 - Read and Write
 7 - Read, Write and Execute

Try chmod 700 filename. This will give the owner of the file full permission. The Group and other's will have no permission to access the file.
Only the owner of the file can read, write or execute the file. If you want other and Group only to read the file you can give chmod 744
filename.

Linux Directory Structure

" / " is the root Directory in Linux. " /root " will be the home directory for the root user (administrator). root will have the full administrative
power over the system and other users. There are other directories like / home, /bin, /sbin, /lib etc. Each user will have there own home
directory

List of all the Directories in Linux


/                      ---------> Root or the main directory
|---root           ---------> Home directory for the root user
|---home         ---------> User's home directories
|    |----ftp      ---------> Users services are listed here
|    |----httpd
|    |----samba
|    |----user1
|    |----user2
|---bin            ---------> Commands needed during bootup and also needed by normal users
|---sbin          ---------> Like bin but commands are not intended for normal users. 
|---proc        ---------> This filesystem is not on a disk.  virtual directory. 
|    | 
|    |----n       ---------> A directory with info about process number n. 

|---usr          ---------> Contains all commands, libraries, man pages etc  for normal operation.
|    |
|    |----bin       --------->   Almost all user commands.
|    |----sbin     --------->   System admin commands not needed in the root filesystem.
|    |
|    |----include      ---------> Header files for the C programming language.
|    | 
|    |----lib             --------->   Unchanging data files for programs and subsystems
|    |----local          --------->   Locally installed software and other files.
|    |----man          -------->   Help pages
|    |----info            --------->    Info documents
|    |----doc            --------->  Documentation for various packages
|    |----tmp
|    |----X11R6      ---------> The X windows system files. 
|    |  
|    |----X386           --------->     Like X11R6 but for X11 release 5
|---boot         ---------> Files used by the bootstrap loader, LILO.  Kernel images stored.
|---lib           --------->    Shared libraries needed by the programs on the root filesystem
|    |----modules    --------->    Loadable kernel modules.
|
|---dev         --------->     Device files for devices such as disk drives, serial ports, etc.
|---etc        --------->  Configuration files specific to the machine.
|    |----skel     --------->    For home directory creation.
|    |----sysconfig    --------->   Files that configure the linux system for networking etc.
|---var     --------->  Contains files that change for mail, news, temp files, etc
|    |----file
|    |----lib        --------->  Files that change while the system is running normally
|    |----local      ---------> Variable data for programs installed in /usr/local.
|    |----lock      --------->  Lock files.  Used by a program.
|    |----log       --------->  Log files from programs such as login and syslog etc.
|    | 
|    |----run      ---------> Files that contain information about the system.
|    | 
|    |----spool   --------->   Directories for mail, printer spools, news and other spooled work.
|    |----tmp      --------->   Temporary files that are needed to exist for longer time.
|    |
|---mnt    --------->  Mount points for temporary mounts by the system administrator.
|---tmp    --------->  Temporary files.  Programs running after bootup should use /var/tmp.

Linux Basic Commands

Linux operating system has a beautiful graphical interface which most of us will be using. It will be good to learn the basic commands in Linux to
work interactively with the Linux operating system. Linux has a back end access know as shell. You can control and activate all the process in
Linux from the shell. So it is very important to learn few basic commands to work with Linux operating system.
 
 First we will learn how to login for shell access. There are 7 terminals for Linux. 6 terminals are non - GUI and 1 terminal for GUI access. You can
login to each terminal using Alt + Ctrl + F1 , F2, .. F7. Each terminals will request your username and password for login. If you want to use the
shell in the graphical interface (GUI), press Alt + F2 and type "konsole". As a user you will have permission to access only your /home/user
directory and other directories in it.
 
 *Note: user denotes the username.

Basic commands in Linux

Navigation Commands - [ pwd, cd ]

pwd
 This command is used to find the current location or current working directory.
 
 Eg:
 [user@ws26 ~]$ pwd
 /home/user
 
 cd
 This command id used to change the directory. You can move from one directory to another using this command. Few examples are given
below.
 
 Concider you have a directory structure /home/user/test/test1/ . test and test1 are directories in user home.
 
 Example 1:
 Consider you have a directory "test" in /home/user. Your current working directory is /home/user. You want to change your current working
directory from /home/user to /home/user/test, use the following command
 [user@ws26 ~]$ pwd
 /home/user
 [user@ws26 ~]$ cd test
 [user@ws26 ~]$ pwd
 /home/user/test
 
 Example 2:
 If you want to move back to /home/user, use the following command
 [user@ws26 ~]$ cd ..
 [user@ws26 ~]$ pwd
 /home/user
 
 Example 3:
 To get back to the home directory of the user
 [user@ws26 ~]$ cd ~
 [user@ws26 ~]$ pwd
 /home/user.

Listing contents in a directory - [ ls, ls -l, ll ]

ls
 This command is used to list all the files and directory in the current directory.
 
 Eg:
 [user@ws26 ~]$ ls
 1152696870.jpg book OperaDownloads snapshot52.png
 image300.jpg Desktop test spiderman2.jpg
 
 ls -l or ll
 This command is also used to list all the files and directories. Here you will get more details about the files and directories present in the
current directory. You will see the permission set, creation date, file / directory size etc.
 
 Eg:
 [user@ws26 ~]$ ls -l
 total 5
 -rw-rw-r-- 1 user user 33188 Dec 22 02:56 1152696870.jpg
 -rw-rw-r-- 1 user user 17647 Aug 19 2006 534458.gif
 -rw-rw-r-- 1 user user 26817 Aug 19 2006 534477.gif
 drwxrwxr-x 2 user user 4096 Jan 13 04:20 book
 drwx------ 3 user user 4096 Feb 4 02:34 Desktop

Reading files in Linux - [ cat, more, less ]


Cat
 This command is used to display the contents of a file. You can read the file contents using the cat command.
 
 Example:
 [user@ws26 ~]$ cat testfile
 this is a test file.. You can read me..
 
 
 Less and More
 Both the less and more commands serve similar function. They are used to display file one screen at a time. You can press spacebar to continue
reading the file. These commands are mainly used while reading large files.
 
 Example 1:
 [user@ws26 ~]$ less testfile
 this is a test file.. You can read me..
 
 Example 2:
 [user@ws26 ~]$ more testfile
 this is a test file.. You can read me..
Manipulating files - [ cp, mv, rm, mkdir ]
cp
 This command is used to copy files/directory.
 
 Example:
 [user@ws26 ~]$ cp file1 directory1
 This will copy the file1 into the directory1
 
 cp -R
 This command is used to copy directories recursively (copy all the files and folders inside the directory).
 
 Example:
 [user@ws26 ~]$ cp directory2 directory1
 This will copy the whole directory2 into directory1
 
 mv
 This command is used to move the file or directory.
 
 Example:
 [user@ws26 ~]$ mv directory2 directory1
 This will move the whole directory2 into directory1
 
 rm
 This command is used to remove or delete files and directories.
 
 Example:
 [user@ws26 ~]$ rm directory2
 This will delete the directory - directory2
 
 mkdir
 This command is used to create a new directory
 
 Example:
 [user@ws26 ~]$ mkdir directory3
 This will create a new directory - directory3.

create new file in Linux - vi editor


The Vi editor is mainly used to create new files in Linux.

Example:
vi testfile
The command will open a new window and you can insert text to it. To begin press "i". After adding your contect press ":wq" to save the file.

Linux Server Administration Commands

All commands in Linux are equally important to manage Linux system / server.
Here I have listed some important commands that are widely used in Linux system / server administration.

Checking running Process on the server. [ ps, pstree ]


ps
This command is used to check the process running on the server. " ps " command will list all the running process with there respective process
ID.
Example:
root@server [~]$ ps
PID TTY TIME CMD
22438 pts/3 00:00:00 su
22439 pts/3 00:00:00 bash
22517 pts/3 00:00:00 ps

Use the following option to get more process information from the " ps " commands,
root@server [~]$ ps -aux

Also you can grep any particular process on the server.


root@server [~]$ ps -aux | grep exim

pstree
This command is also used the check the process on the server. " pstree " command will list all the running process in the form of a tree
structure.

Example:
root@server [~]$ pstree
init─┬─agetty
├─antirelayd
├─bdflush
├─chkservd
├─4*[courierlogger───couriertcpd]
├─courierlogger───authdaemond───5*[authdaemond───authProg]
├─cpanellogd
├─cpdavd
├─cphulkd.pl
├─cpsrvd-ssl───cpsrvd-ssl
├─crond
├─entropychat
├─exim───exim─┬─3*[exim]
│ └─spamc
├─2*[exim]
├─exim───20*[exim]
├─eximstats
├─hpt_wt
├─httpd───56*[httpd]
├─interchange
├─keventd
├─7*[kjournald]
├─klogd
├─ksoftirqd_CPU0
├─ksoftirqd_CPU1
├─ksoftirqd_CPU2
├─ksoftirqd_CPU3
├─kswapd
├─kupdated
├─mailmanctl───8*[python2.4]
├─mdrecoveryd
├─6*[mingetty]
├─mysqld_safe───mysqld───mysqld───26*[mysqld]
├─named───named───6*[named]
├─portsentry
├─pure-authd
├─pure-ftpd
├─10*[python2.4]
├─scsi_eh_0
├─spamd───2*[spamd]
├─ssh
├─sshd─┬─sshd───sshd───bash───su───bash
│ └─sshd───sshd───bash───su───bash───pstree
├─syslogd
└─xinetd
Also try the following options for " pstree ".
root@server [~]$ pstree -p
init(1)─┬─agetty(7480)
├─antirelayd(8658)
├─bdflush(8)
├─chkservd(6224)
├─courierlogger(6833)───couriertcpd(6834)
├─courierlogger(6840)───couriertcpd(6841)
├─courierlogger(6846)───couriertcpd(6847)
├─courierlogger(6852)───couriertcpd(6853)
├─courierlogger(6858)───authdaemond(6859)─┬─authdaemond(6873)
│ ├─authdaemond(6874)───authProg(26164)
│ ├─authdaemond(6875)───authProg(17488)
│ ├─authdaemond(6876)───authProg(8194)
│ └─authdaemond(6877)───authProg(29956)

Load on a server [ top, w , uptime ]

top

This command is used to find the load on the server. " top " command can also be used to find the process and users that causes load on the
server. It gives information about the total process, sleeping process, the zombie process etc.

Example:

root@server [~]$ top -cd3

11:32:03 up 15 days, 23:57, 2 users, load average: 4.95, 5.13, 5.94

220 processes: 219 sleeping, 1 running, 0 zombie, 0 stopped

CPU states: cpu user nice system irq softirq iowait idle

total 1.5% 1.6% 2.4% 0.0% 0.0% 0.0% 94.3%

cpu00 3.4% 2.8% 2.8% 0.0% 0.0% 0.0% 90.9%

cpu01 0.3% 3.1% 0.0% 0.0% 0.0% 0.0% 96.5%

cpu02 2.5% 0.3% 6.5% 0.0% 0.0% 0.0% 90.6%

cpu03 0.0% 0.3% 0.3% 0.0% 0.0% 0.0% 99.3%

Mem: 3104932k av, 2909432k used, 195500k free, 0k shrd, 284548k buff

1201588k active, 1558304k inactive

Swap: 3004112k av, 499936k used, 2504176k free 1015264k cached

PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND

3754 root 16 0 1252 1252 896 R 1.4 0.0 0:01 2 top -cd3

3620 nobody 9 0 61460 45M 28768 S 0.6 1.4 2:23 0 /usr/local/apache/bin/httpd -DSSL
3604 mailnull 9 0 4204 4116 2816 S 0.2 0.1 0:00 0 /usr/sbin/exim -bd -q60m

29956 root 9 0 4684 3384 2640 S 0.1 0.1 0:31 0 /etc/authlib/authProg

1 root 8 0 468 440 416 S 0.0 0.0 0:34 2 init [3]

From the above example you can see the load average, total processes, sleeping processes and the CPU usage. You can find the load average
( here the load average is " 4.95 " ), the memory usage, stats, swap and the list of process and its users.

This command is also find the load and users on the server. " w " command will provide a brief description about the load, time, number of
users and the uptime of the server.

Example:

root@server [~]$ w

11:39:18 up 16 days, 4 min, 2 users, load average: 5.33, 5.37, 5.74

USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

user1 pts/0 user - ip1 8:26am 3:13m 0.09s 0.00s sshd: user1 [priv]

user2 pts/3 user - ip2 11:09am 0.00s 0.13s 0.02s sshd: user2 [priv]

uptime

This command gives the basic information about the uptime and load of the server.

Example:

root@server [~]$ uptime

11:42:52 up 16 days, 8 min, 2 users, load average: 4.91, 5.35, 5.67

From the above example you can find the load and the number of days server running with out failure etc..

Killing process on a server [ kill, pkill, killall -9 ]

kill

This command is used to kill a running process on the server. You need to process id to execute the kill command. Consider you run " pstree -p "
which will list all the process with its respective process id. To kill a particular process use the command " kill <process-id> ".

Example:

root@server [~]$ kill 27209

or

root@server [~]$ kill -9 27209

The above command will kill the process id 27209.


pkill

This command will kill the child processes of a particular process. Consider you want kill httpd on the server.

Example:

root@server [~]$ pkill httpd

or

root@server [~]$ pkill -9 httpd

or

root@server [~]$ pkill -HUP httpd

The above command will only kill all the child process of " httpd ". Using this command the parent process will be running and all the child
process will be killed.

killall

This command is used to kill all the processes ( parent process and child process ).

Example:

root@server [~]$ killall -9 httpd

Checking the number of connection's to the server [ netstat, mysqladmin processlist ]


netstat

This command is used to find the number of connections to the server. " netstat " command will list all the connections using httpd, exim, ftp
etc. You can grep the needed port and find the number of connections to a particular port. You can find the Local Address, Foreign Address,
State, port etc of all the connections.

Example:

root@server [~]$ netstat -plan

or

root@server [~]$ netstat -plan | grep ":80"

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15496/httpd

tcp 0 0 65.254.34.21:80 165.21.14.92:42469 SYN_RECV -

tcp 0 0 65.254.34.21:80 71.7.8.253:3922 SYN_RECV -

tcp 0 0 65.254.34.21:80 165.21.154.10:28343 SYN_RECV -

tcp 0 0 65.254.34.21:80 85.100.25.208:2157 TIME_WAIT -

mysqladmin processlist
This command is used to find the connections to the mysql database. It gives information about Id, User, Host, db, Command, Time, State and
Info of a mysql request to the server.

Example:

root@server [~]$ mysqladmin processlist

+--------+-----------------+-----------+-----------------------------+---------+-------+-------+

| Id | User | Host | db | Command | Time | State | Info |

+--------+-----------------+-----------+-----------------------------+---------+-------+-------+

| 186678 | mfjengin_shops | localhost | mfjengin_rapid | Sleep | 28337 | | |

| 188706 | mfjengin_shops | localhost | mfjengin_rapid | Sleep | 27051 | | |

| 195090 | kronosho_usifu | localhost | kroho_sifu | Sleep | 23069 | | |

| 201227 | mfjengin_shops | localhost | mfjengin_rapid | Sleep | 19655 | |

Blocking IP [ apf, csf ]

APF and CSF are firewall software’s.

You can use these commands to block a particular IP from connecting to the server. This command is mainly used when you find too many
connections from a particular IP. Normally too many connection might be a attack to the server. So it is important to block such IP before it
interrupts the balance of the server.

Check which firewall is installed on your server and use it accordingly.

Example:

root@server [~]$ apf -d <IP>

or

root@server [~]$ csf -d <IP>

Checking the port if open or not [ telnet, nmap ]


telnet

TELNET (TELecommunication NETwork) is a network protocol used on the Internet. TELNET is a client-server protocol, based on a reliable
connection-oriented transport. This command will help us to find if a particular port on the server is open or not.

Example:

root@server [~]$ telnet google.com 80

Trying 64.233.187.99...

Connected to google.com (64.233.187.99)


From the above example you could find that port 80 is open on google server. If we receive a " connection refused " signal, that mean's the
particular port is not open on the server.

nmap

This command nmap is a Network exploration tool and a security scanner.

Installing software’s [ yum ]


yum

This command is used to install software’s to the server without any dependences.

Example:

yum install <software>

If you find any software’s missing on the server, you can directly install it using this yum command. It will install the particular software on the
server without dependencies.

What are Semaphores?


Semaphores are IPC mechanism which allow different processes to synchronize their access to certain resources.

The simplest kind of semaphores is called a binary semaphore and they have two states ( locked or unlocked ).
These act like traffic lights, which allows certain processes to exclusively access certain resources.

When a process wants exclusive access to a resource, example: shared memory, they attempt to lock the semaphore associated with that
resource. If the semaphore they are attempting to lock is already locked, the caller is suspended, otherwise they are granted to lock.

When the process completes the task, it unlock the resource and any processes that have attempted to lock that semaphore in the meantime
are woken up again to attempt the lock again. This way only one process can have access to the resource at once.

In addition, semaphores can also be used as a signaling mechanism.

Vous aimerez peut-être aussi