Linux Overview: Huy Nguyen
Linux Overview: Huy Nguyen
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
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
5 http://www.tel4vn.com/
Unix Overview (cont.)
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.
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 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
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
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
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
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
25 http://www.tel4vn.com/
Process Management
l Check your process.
ps
ps –u
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
32 http://www.tel4vn.com/
Foreground and Background
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
36 http://www.tel4vn.com/
Debug network problem
l Ping ip address
l If using Virtualbox: NAT or Bridge ?
- 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
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
38 http://www.tel4vn.com/
Set static ip address(cont)
l Ubuntu
l vi /etc/network/interfaces
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
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/