Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
68 views

Linux Overview: Huy Nguyen

This document provides an overview of the Linux operating system. It describes Linux's kernel and shell interface, its multi-user and multi-process capabilities, and how everything in Linux is treated as a file. It also outlines Linux's directory structure and important directories like /bin, /home, and /etc. The document concludes by explaining basic Linux commands, relative and absolute paths, redirection, permissions, and process management.

Uploaded by

Ba VuVan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Linux Overview: Huy Nguyen

This document provides an overview of the Linux operating system. It describes Linux's kernel and shell interface, its multi-user and multi-process capabilities, and how everything in Linux is treated as a file. It also outlines Linux's directory structure and important directories like /bin, /home, and /etc. The document concludes by explaining basic Linux commands, relative and absolute paths, redirection, permissions, and process management.

Uploaded by

Ba VuVan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

LINUX OVERVIEW

Huy Nguyen

1 http://www.tel4vn.com/
Outline
l  Overview of Unix System
l  Basic Commands
l  Relative & Absolute Path
l  Redirect, Append and Pipe
l  Permission
l  Process Management
l  Install Software
l  Text Editor
l  Foreground and Background Jobs
l  Remote log in and File transfer
l  Some tips
2 http://www.tel4vn.com/
Overview of Unix System
Kernel & Shell
l  Unix/Linux is operating system

(OS).
User
l  Unix system is described as kernel

& shell. input

l  Kernel is a main program of Unix Shell


system. it controls hard wares,
CPU, memory, hard disk, network Kernel
card etc.

l  Shell is an interface between user


and kernel. Shell interprets your
input as commands and pass them
to kernel.
3 http://www.tel4vn.com/
Unix Overview (cont.)
Multi-user & Multi-process
—  Many people can use one machine at the same time.

File & Process


—  Data, directory, process, hard disk etc (almost everything) are

expressed as a file.
—  Process is an running program identified by a unique id (PID).

4 http://www.tel4vn.com/
Unix Overview (cont.)

Directory Structure

l  Files are put in a directory.


l  All directories are in a hierarchical structure (tree structure).
l  User can put and remove any directories on the tree.
l  Top directory is “/”, which is called slash or root.
l  Users have the own directory. (home directory)

5 http://www.tel4vn.com/
Unix Overview (cont.)

—  Directory Structure

6 http://www.tel4vn.com/
Unix Overview (cont.)
Important Directories

l  /bin This contains files that are essential for correct operation
of the system. These are available for use by all users.
l  /home This is where user home directories are stored.
l  /var This directory is used to store files which change
frequently, and must be available to be written to.
l  /etc Various system configuration files are stored here.

7 http://www.tel4vn.com/
Unix Overview (cont.)

Important Directories

l  /dev This contains various devices as files, e.g. hard disk, CD-
ROM drive, etc.
l  /sbin Binaries which are only expected to be used by the super
user.
l  /tmp Temporary files.

8 http://www.tel4vn.com/
Unix Overview (cont.)
Normal user and Super user
l  In Unix system, there is one special user for administrator, which

can do anything.
l  This special user is called root or superuser.

Case Sensitivity
l  Unix is case-sensitive.

l  MYFILE.doc, Myfile.doc, mYfiLe.Doc are different.

Online Manual
l  Unix has well-written online manuals.

9 http://www.tel4vn.com/
Basic Commands
—  How to run commands
l  => Application => Accessories => Terminal
l  When you log on Unix machine, you will see,

[someone]$
l  One command consists of three parts, i.e. command name,

options, arguments.
Example:
[someone~]$ command-name optionA optionB argument1
argument2

10 http://www.tel4vn.com/
Basic Commands
How to run commands

l  Between command name, options and arguments, space is


necessary.
l  Opitions always start with “-”

l  Example:

cd ..
ls –l .bashrc
mv fileA fileB

11 http://www.tel4vn.com/
Basic Commands
Commands
l  ls show files in current position
l  cd change directory
l  cp copy file or directory
l  mv move file or directory
l  rm remove file or directory
l  pwd show current position
l  mkdir create directory
l  touch create new blank file
l  rmdir remove directory
l  less, more, cat display file contents
l  man display online manual
l  vi open and edit file
12 http://www.tel4vn.com/
Basic Commands
l  su switch user
l  passwd change password
l  useradd create new user account
l  userdel delete user account
l  mount mount file system
l  umount unmount file system
l  df show disk space usage
l  shutdown reboot or turn off machine

13 http://www.tel4vn.com/
Basic Commands
1. Type following command
in your directory.
—  ls 3. In your home directory,
—  ls –a ls .bash_profile
—  ls –la cp .bash_profile sample.txt
—  ls -Fa less/more/cat sample.txt
2. Make a directory (note: to quit less, press “q”)
—  mkdir linux rm sample.txt
—  pwd
—  cd linux
—  pwd
4. Check disk space usage
—  cd df
—  pwd df -h
—  rmdir linux
14 http://www.tel4vn.com/
Relative & Absolute Path

l  Path means a position in the directory tree.


l  To express a path, you can use relative path or absolute
path.
l  In relative path expression, the path is not defined uniquely,
depends on your current path.
l  In absolute path expression, the path is defined uniquely,
does not depend on your current path.

15 http://www.tel4vn.com/
Relative Path
l  Relative to your current location
. : your current location
.. : one directory above your current location
pwd: gives you your current location

l  Example
ls ./linux : lists the content of the dir linux
ls ../../ : lists everything that is two dir higher

16 http://www.tel4vn.com/
Relative & Absolute Path
l  Relative Path •  Ablsoute Path
pwd cd
cd . mkdir mydir
pwd pwd
cd /Users/invite
cd ..
pwd
pwd
cd /Users
cd .. pwd
pwd cd /
cd pwd
cd /Users/invite
http://www.tel4vn.com/
cd ~/mydir
17
Redirect, Append and Pipe
Redirect and append
l  Output of command is displayed on screen.

l  Using “>”, you can redirect the output from screen to a file.

l  Using “>>” you can append the output to the bottom of the file.

Pipe
l  Some commands require input from a file or other commands.

l  Using “|”, you can use output from other command as input to

the command.

18 http://www.tel4vn.com/
Redirect, Append and Pipe

Commands
l  head show first several lines and omit other lines.
l  tail show last several lines and omit other lines.
tail -f /var/log/message
l  grep search the content of files
grep 'tel4vn' * -R

19 http://www.tel4vn.com/
Redirect, Append and Pipe
l  Use redirect
ls -all > test.txt

l Use append
ls -all >> test.txt

l  Use pipe


ps -ef | grep python

20 http://www.tel4vn.com/
Permission
l  All of files and directories have owner and permission.
l  There are three types of permission, readable, writeable and
executable.
l  Permissions are given to three kinds of group. owner, group
member and others.

Example:
ls -l .bash_profile
-rw-r--r-- 1 cnotred cnotred 191 Jan 4 13:11 .bash_profile

r:readable, w:writable, x: executable

21 http://www.tel4vn.com/
Permission
Command
l  chmod change file mode, add or remove
permission
l  chown change owner of the file

Example:
chmod a+w filename
add writable permission to all users
chmod o-x filename
remove executable permission from others
chmod a+x
Gives permission to the usser to execute a file

u: user (owner), g: group, o: others a: all


22 http://www.tel4vn.com/
Permission
l  Check permission
ls –l .bash_profile
cp .bash_profile sample.txt
ls –l sample.txt

l  Remove readable permission from all.


chmod a-r sample.txt
ls –l sample.txt
less sample.txt

l  Add readable & writable permissions to file owner.


chmod u+rw sample.txt
ls –l sample.txt
less sample.txt
rm sample.txt
23 http://www.tel4vn.com/
Process Management
l  Process is a unit of running program.

l  Each process has some information, like process ID, owner,
priority, etc.
Example: Output of “top” command"

24 http://www.tel4vn.com/
Process Management
Commands

l  kill Stop a program. The program is specified by process ID.


kill 1718
l  killall Stop a program. The program is specified by command
name.
killall -9 mysqld
l  ps -ef Show process status
l  top Show system usage statistics

25 http://www.tel4vn.com/
Process Management
l  Check your process.
ps
ps –u

l  Check process of all users.


top (To quit top, press “q”)
ps –e
ps –ef

l  Find your process.


ps –ef | grep cnotred

l  Check all using ports.


netstat -ntulp
26 http://www.tel4vn.com/
Install Software
•  ALWAYS update the repository first
•  Ubuntu: apt-get update, apt-get upgrade
•  CentOS: yum update
•  From binary file:
•  Ubuntu: dpkg -i package_name.deb
•  CentOS: rpm -Uvh package_name.rpm
•  By commands
•  Ubuntu:
•  apt-get update
•  apt-get install package_name
•  CentOS:
•  yum update
27 http://www.tel4vn.com/
•  yum -y install package_name
Install software
l  From source
l  MUST install some basic packages first:
-  CentOS: yum -y install make bison bison-devel ncurses ncurses-
devel zlib zlib-devel openssl openssl-devel gnutls-devel gcc gcc-c+
+ kernel-devel flex which
-  Ubuntu: apt-get install install build-essential g++ libncurses5-dev
flex bison
l  Download:
-  wget http://link_for_downloading_package
-  svn checkout http://svn.asterisk.org/svn/asterisk/trunk asterisk
-  git clone git://git.freeswitch.org/freeswitch.git
28 http://www.tel4vn.com/
Install Software
•  Extract:
•  package_name.tar.gz → tar zxvf package_name.tar.gz
•  package_name.tar.bz2 → tar jxvf package_name.tar.bz2
•  package_name.zip → unzip package_name.zip
•  Compile and install (read INSTALL or README file first)
•  cd /path/package_source_file
•  ./configure
•  make
•  make install

29 http://www.tel4vn.com/
Text Editor

vi
l  Programs & configuration files are text file.
l  There are some other popular text editors: nano, pico,
gedit ...
l  Although they are very powerful and useful, it is also true that
they are complicated for beginners and difficult to learn.
l  vi is an easy and simple alternative.

30 http://www.tel4vn.com/
Text Editor
l  Basic commands (press ESC to switch to command mode)
-  :wq → save and quit
-  :q! → quit but not save
-  /abc → search abc in that file, press n to see the next result, press N to go
back.
-  :180 → jump to line with number 180
-  Shift-g → jump to the end of file
-  x → delete character at cursor location
-  dd → delete one line at cursor location
-  u → undo any change from that file

31 http://www.tel4vn.com/
Foreground and Background

l  Running job has two modes, “foreground” and “background”

l  If program is running as “background”,


the program keeps running even after your session was closed

l  If program is running as “foreground”,


Ctrl-C stop program
Ctrl-Z let program background

32 http://www.tel4vn.com/
Foreground and Background

l  To run programs in background mode, use “&”


[tel4vn@lappy]$ command &

l  To get background job back into foreground mode, use “fg”
command.
[tel4vn@lappy]$ fg → check !!!!!

33 http://www.tel4vn.com/
Remote Login & File Transfer
l  SSH:
l  SSH server:
-  Ubuntu: apt-get install openssh-server
-  CentOS: yum -y install openssh
l  SSH Clients:
-  can use with some ssh clients: Putty (Windows), Pac(Linux)
-  Ubuntu: apt-get install openssh-client
-  CentOS: yum install openssh-clients
ssh 192.168.1.50
ssh root@192.168.1.50
•  Filezilla
•  Host: 192.168.1.50
•  Username: tel4vn
•  Password: Passw0rd
34
•  Port: 22
http://www.tel4vn.com/
35 http://www.tel4vn.com/
Monitor services

•  Check:
l  ps -ef | grep process_name

l  netstat -ntulp

•  Start: /etc/init.d/process_name start


•  Stop: /etc/init.d/process_name stop

36 http://www.tel4vn.com/
Debug network problem
l  Ping ip address
l  If using Virtualbox: NAT or Bridge ?

l  Check network configuration (if using desktop version, MUST

configure network on the GUI)


l  Ping local ip address, then ping public ip address

l  Ping domain


l  Ping dns server ip address

l  Check dns configuration

-  vi /etc/resolv.conf
-  vi /etc/hosts
37 http://www.tel4vn.com/
Set static ip address
l  CentOS
l  vi /etc/sysconfig/network-scripts/ifcfg-eth0

l  Configure as below:

DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.50
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
HWADDR=.....
ONBOOT=yes
l  Restart network: /etc/init.d/network restart

l  Test: ping google.com

38 http://www.tel4vn.com/
Set static ip address(cont)
l  Ubuntu
l  vi /etc/network/interfaces

l  Configure as below:

auto eth0
iface eth0 inet static
address 192.168.1.50
gateway 192.168.1.1
netmask 255.255.255.0
l  Restart network

/etc/init.d/networking restart
l  Test: ping google.com

39 http://www.tel4vn.com/
Check iptables
l  iptables -L → check all current rules
l  iptables-save >> /etc/rules.save → backup rules
l  iptables-restore < /etc/rules.save → restore rules from file
l  /etc/init.d/iptables start/stop → monitor service

40 http://www.tel4vn.com/
Set environment variables
l  vi ~/.bashrc
l  Add as below:
l  PATH=$PATH:/path_to_where_application_is/bin

l  export PATH

l  source ~/.bashrc

41 http://www.tel4vn.com/
Reference

l  http://www.ee.surrey.ac.uk/Teaching/Unix/
l  http://www.linuxtopia.org/online_books/
linux_for_beginners_index.html

42 http://www.tel4vn.com/
THE END

43 http://www.tel4vn.com/

You might also like