Anda di halaman 1dari 100

Security Level: B

Linux Fundamental
ISSUE1.0
www.huawei.com

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

The course narrates the history


and running theory of Linux OS.
Also, some basic commands and
tips for daily operation and
maintenance of Linux OS are
mentioned in the course.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Reference
Linux Bible 2007
Linux in a Nutshell 5th Edition
Tips And Techniques For Everyday

Use

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

After finishing the course, you should be able to


know the history of Linux OS
know the fundamentals of Linux OS
master the use of common commands
know the common tips of Linux OS
know how to handle some simple and common
problems of Linux OS

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.1 Linux fundamentals


Chap.2 Linux commands
Chap.3 Linux tips
Chap.4 Handling method for
common problems

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.1 Linux fundamentals


1.1 What is Linux
1.2 How to install Linux OS
1.3 How to start and shut
down Linux OS
1.4 How to study Linux OS

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

The history of Linux


BSD in 1977
and system V
in 1980

Solaris AIX
and HP_UNIX
etc.

Small
Smallarchives
archivessystem
system
Unix
Unix

The first and formal


Unix kernel in 1973

Some
Someimportant
importantUnix
Unixbranches
branches
Kinds
Kindsofofdifferent
differentUnix
Unixversion
version

Linus Torvalds of
Finland College in
1991

Small file server


system of Ken
Thompson in 1969

GNU
GNUand
andFSF
FSF

HUAWEI TECHNOLOGIES CO., LTD.

Linux
Linux
HUAWEI Confidential

GNU and FSF


organizations are
created by Stallman in
1984

Linux components
Linux Shell

Linux
Kernel

Practical
tools

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Linux user environment


Kernel
Shell bash csh ksh
Terminal Emulator putty xmanager
X Window xfree86
Window Manager KMW
Desktop Environment Gnome KDE

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Linux characteristics
Open The system keeps to the standards in the world
Multi-user The system resource can be occupied by different users.
Multi-task Different tasks can be executed simultaneously and separately.
Friendly user interface System kernel can be invoked friendly via user
interface (compared to Unix).
Independency of devices All devices is looked as a file.
Plenty of network function FTP,HTTP and TELNET etc can be supported.
Reliable system security PAM etc
Good transplantable ability Linux can be executed in different platform
Free Linux is a free software and any one can get and do with the source
codes .

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Terms related to Linux


Business software, sharing software and free software

Business software User should buy the software and get the technology support
from the developer. In addition, the software cannot be modified and spread by the
user.
Sharing software: The software can be used free but cannot be modified and spread.
Free software: Everyone can get the source codes free, and can modify or spread the
software.

FSF : free software foundation


GPL : general public license
Kernel version

Stable version The source codes will not changed and only patch version will be
issued. The version number is even such as 2.4 or 2.6.
development version : The source codes will be improved and new features will be
imbedded. The version number is odd such as 2.5.
distribution version: some tools such as system tool, applicable tools, network tools and
compile files will be issued with the software.
HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Mainstream version of Linux


Red Hat Enterprise Linux

Suse Linux Enterprise Server

Debian

Ubuntu

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Fedora Core

OpenSuse

System directories of Linux

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Devices and file system of Linux


File categories

Regular file
Directory file
Link file
Device file
# cd /etc ; ls -al
# cd /dev ; ls al

Sockets and Pipe

- - Regular files, namely the binary and ascii files


d Directories file
l Symbolic links files
b Block-special device files
c Character-special device files
HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Devices and file system of Linux


Right of the file
For a file, these are three types of different users.

U means the owner of the file.


G means the group of the file.
O means the other users of the file.
For each type of user of the file, there are three types of different right.

R means the user can read the file.


W means the user can write the file.
X means the user can execute the file. And for directory , X means the user can
enter the directory.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Devices and file system of Linux


File system
Definition of file system: the way to organize the data or some kind of
protocol.
Definition of mount the procedure of associating the file system and
the device.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Devices and file system of Linux


Device
The information of all devices supported by Linux is stored in the /dev folder.

Physical device: the device can be seen and touched and can be partitioned,
such as the hard disk.
Logical device: The physical device will changed into logical device after being
capsulated by some software. And the logical device can be plotted by logical
volume.
Nude device: There is no physical partitions or logical volumes in the device. And
the way of data organization is decided by the database.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Devices and file system of Linux


Device type

Character device
Block device
Network device
Character device The device is accessed by asc stream, such as the
character terminal and serial device.
Block device The device is accessed by data block, such as the hard
disk and CD.
Network device The device is used for data exchange between
different hosts.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Input and output technology of Linux

Stdin (abbr. of Standard input) the default device is keyboard.


Stdout (abbr. of Standard output) the default device is screen and we can
see all the output of the system, such as the serial port.
Stderr (abbr. of Standard error output) the default device is screen.
Tips:
You can use symbol < to relocate the input source.
You can use symbol > to relocate the output objective.
You can use symbol | to filter the result and make the result filtered as the
input source of following filter.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Common log files of Linux


/var/log/boot.msg This log file records the information when the hosts is
started and we can also the information use demsg command.
/var/log/messages This log file records the running information for most
of the system services.
Notes: With this file, we can determine the hosts is normal or not.
/var/log/wtmp This log file records the login information of the host. This
file is a binary file and we can use last command to read the file.
/var/log/lastlog This file records the login way of the last user.
/var/log/faillog This file records the login information for failure.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

The Linux version used by M2000


Suse Linux Enterprise Server 10
SUSE is the abbreviation of German Software und System
Entwicklung, which is a business company founded in 1992.
SUSE is purchased by Novell in 2004, and from then on the
technology support of SUSE Linux is offered.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

SLES 10
Disk partition and file system mount
We can df and mount commands to check the disk partition and file system mount.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.1 Linux fundamentals


1.1 What is Linux
1.2 How to install Linux OS
1.3 How to start and shut
down Linux OS
1.4 How to study Linux OS

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

How to install SLES10


Installation mode
The installation mode based on CD/DVD

The installation mode based on VNC (for IBM machine)

The installation mode based on network

The installation mode based on AutoYast

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

How to install SUSE10


Installation process
Choose the installation mode when started
Choose the installation language
Choose the installation configuration
Determine the hard disk partition and formatting
Install the SUSE10 system and according sortware package
Configure the system, including:

the password of root user


network configuration
update and services of the system
user configuration
Device configuration
HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.1 Linux fundamentals


1.1 What is Linux
1.2 How to install Linux OS
1.3 How to start and shut
down Linux OS
1.4 How to study Linux OS

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Startup and shutdown of Linux


Startup
Phase III

Phase I
poweron
FLOPPY

BIOS

CDROM

harddisk

SCSI sda

Loading kernel

MBR
Bootloader
grub

Detect hardware
Init hardware

rc.local
rc.sysinit
Init

Phase II
Phase IV

HUAWEI TECHNOLOGIES CO., LTD.

/etc/inittab

HUAWEI Confidential

Startup and shutdown of Linux


runlevel
Different run-level can determine the application that the host can be offered.

RUNLEVEL

ACTION

Power-off

Single-user mode

Local multi-user mode (network cannot be used)

Network multi-user mode (default run-level of M2000 )

Free mode

Network multi-user mode with graphic interface

Restart

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Startup and shutdown of Linux


Shutdown
For Dos or Windows OS, we can shutdown the host by pressing power-off button directly.
For Linux, when you determine to shutdown the hosts, you should:

know who is using the host


notify that you will shutdown the host (optional)
use sync command to synchronize the date before shutdown
The procedure of shutdown for Linux

Send shutdown signal to the host and notify the users


Stop all the processes in the host
unload all the devices
Commands for shut down Linux

init 0(the safest mode to shutdown the host)

shutdown -h now

halt the most violent mode to shut down the host, equivalent to press the power-off
button.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.1 Linux fundamentals


1.1 What is Linux
1.2 How to install Linux OS
1.3 How to start and shut
down Linux OS
1.4 How to study Linux OS

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

How to study Linux OS


Suggestion

Learn to use man and whatis command


Linux is a system sensitive to small letter and capital.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Questions
What is the OS type used by M2000 software?
How many stages are there for startup of Linux?
How to use commands to shut down the host?
How to get the online help of the command?

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.1 Linux fundamentals


Chap.2 Linux commands
Chap.3 Linux tips
Chap.4 Handling method for
common problems

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.2 Linux commands


2.1 System management commands
2.2 Storage management commands
2.3 File management commands
2.4 Network management commands

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

adduser useradd)
Add or update the user information

Comman
d

meaning

adduser

Add an
user

General usage and description


useradd -d /home/xxxx
xxxx

HUAWEI TECHNOLOGIES CO., LTD.

Add an user xxxx with its


home folder /home/xxxx

HUAWEI Confidential

example
useradd
-d
/home/db2
inst
db2inst

userdel
Delete an user
command

meaning

userdel

Delete the
user

Common usage and description

HUAWEI TECHNOLOGIES CO., LTD.

userdel -rf
username

Delete the user


username and its
home folder forcibly

HUAWEI Confidential

example
userdel -rf db2inst

passwd
Set or modify the user mode
command

meaning

passwd

Set or modify
the user
password

Common usage and description


passwd username

HUAWEI TECHNOLOGIES CO., LTD.

Set or modify the


password of user
username

HUAWEI Confidential

example
passwd db2inst

date
Display or modify current time of the system
Comman Meaning
d

Common usage and


description

example

date

date

date

Display of modify
current time settings

Query current
time

date
Modify current
[MMDDhhmm[ time settings
date 112711162007
[CC]YY][.ss]]

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

hwclock clock
Display or set current time of the hardware
Comman
d

Meanin
g

hwclock

Display
or set
current
time of
the
hardware

Common usage and description

Example

hwclock

Query the time

hwclock

hwclock w

Synchronize the time of


system with hardware

hwclock w

hwclock s

HUAWEI TECHNOLOGIES CO., LTD.

Synchronize the hardware


time with system

HUAWEI Confidential

hwclock s

uptime
Display the running duration
Comman
d

Meaning

uptime

Display the running


duration of the host

Common usage and


description
uptime

Display the running


duration of the host

Example
uptime

The output will print the information of current time, running duration, the user number logged
on the system and the average load of last 1.5 and 15 minutes. For example:
11:16am up 6 days 0:45, 2 users, load average: 0.14, 0.11, 0.09

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

free
Show the usage of memory
Comman
d

Meaning

free

Show the usage of


memory

HUAWEI TECHNOLOGIES CO., LTD.

Common usage and


description
free

Show the usage of


memory

HUAWEI Confidential

example
free

iostat
Show the statistics of CPU and I/O
Comman
d

Meaning

iostat

Show the
statistics of
CPU and I/O

Common usage and description

example

iostat

Show the statistics once

iostat

iostat m

Show the statistics in m


seconds
Show the statistics in m
seconds, totally n times

iostat 1

iostat m n

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

iostat 1 10

mpstat
Show the statistics related to CPU
Comman
d

Meaning

mpstat

Show the
statistics
related to CPU

Common usage and description

mpstat m

mpstat P ALL

HUAWEI TECHNOLOGIES CO., LTD.

Show the statistics


every m seconds
Show the CPU
statistics of all
CPUs

HUAWEI Confidential

example

iostat 1

mpstat P ALL

vmstat
Show the statistics of virtual memory
Comman
d

Meaning

vmstat

Show the
statistics of
virtual memory

Common usage and description

Example

vmstat

Show the statistics once

vmstat

vmstat a

Show the statistics in a


seconds once

vmstat 1

vmstat a b

vmstat 1 10
Show the statistics in a
seconds, totally b times

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

ps
Show the processes of the system

Comman
d

Meaning

Common usage and description

ps

Show the
processes

ps

Show the shell used

ps

ps ef|grep
keyword

Show the process related to


keyword

ps ef|grep hlr

ps aux

Show all process

ps aux

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Example

kill
Send signal to certain process

Comman
d

Meaning

kill

Send signal
to certain
process

Common usage and description


kill -9 PID

HUAWEI TECHNOLOGIES CO., LTD.

Kill the process with process


number ID PID

HUAWEI Confidential

Example
Kill -9 40000

top
Show the processes executing

Comman
d

Meaning

Common usage and description

Example

top

Show the
processes
executing

top

Show the processes


executing dynamically with
interactive mode

top

top b

Show the processes


executing dynamically without
interactive mode

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

top -b

uname
Show the system information
Comman
d

Meaning

uname

Show the
system
information

Common usage and description


uname -a

Example

Show all information of the


system.

uname -a

host
Kernel
number
kernel
HUAWEI TECHNOLOGIES CO., LTD.

OS
version
Processor
type
HUAWEI Confidential

Host
type

Hardware
platform

hostname
Show the host name
Comman
d

Meaning

Common usage and description

Example

hostname

Show or
modify the
host name

hostname

Show the host name

hostname

hostname name1

Modify the host name

hostname
hle_db01

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

who w
Show the user online
Comman
d

Meaning

who

Show the
user online

Common usage and description

Example

who

show the online user information

who

Show the online user information,


including current operation and
CPU overload etc.

Show current run-level


Who r

HUAWEI TECHNOLOGIES CO., LTD.

who -r

HUAWEI Confidential

last
Display the information of the user logged
Comman
d

Meaning

last

Display the
information of the
user logged

HUAWEI TECHNOLOGIES CO., LTD.

Common usage and description


last

Display the information of the


user logged

HUAWEI Confidential

example
last

halt reboot poweroff


Restart or shut down the host
Comman
d

Meaning

halt

Restart or
shutdown
the host

reboot
poweroff

Common usage and description


sync sync halt

sync sync reboot

sync sync poweroff

HUAWEI TECHNOLOGIES CO., LTD.

Shut down
the host
Restart the
host

Shutdown
the host

HUAWEI Confidential

example
sync halt

sync sync reboot

sync sync poweroff

shutdown
Restart or shut down the host

Comman
d

Meaning

Common usage and description

shutdown

Restart or
shut down
the host

sync sync shutdown


t 0 h now

Shut down
the host
right now

sync sync shutdown


t 0 h now

sync sync shutdown


t 0 Fr now

Restart the
host right
now

sync sync shutdown


t 0 Fr now

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

example

chkconfig
Check or set the services of the host
Comman
d

Meaning

chkconfig

Check or
set the
services of
the host

Common usage and description


chkconfig a
servicename

Example
chkconfig a xinetd

chkconfig d
servicename

Add service
servicename to
the host
Remove
service
servicename of
the host

chkconfig l

chkconfig l

Query the
sevices

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

chkconfig d xinetd

crontab
Query or set the timed task

Comman
d

Meaning

crontab

Query or
set the
timed task

Common usage and description

Example

crontab -e

Add or remove the timed


task

crontab -e

crontab -l

Query the timed task of the


host

crontab -l

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

dmesg
Query the boot message

Comman
d

Meaning

Common usage and description

example

dmesg

Query the
boot
message

dmesg > /dir/file

dmesg >
/tmp/dmesg.txt

HUAWEI TECHNOLOGIES CO., LTD.

Query the boot


message and save
the query result to
the file /dir/file

HUAWEI Confidential

Chap.2 Linux commands


2.1 System management commands
2.2 Storage management commands
2.3 File management commands
2.4 Network management commands

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

fdisk
Partition tool of Linux

Comman
d

Meaning

fdisk

Partition tool of
Linux

Common usage and description

HUAWEI TECHNOLOGIES CO., LTD.

fdisk -l

Query current
partition of the host

HUAWEI Confidential

Example
fdisk -l

fsck
Repair the file system

Comman
d

Meaning

fsck

Repair the file


system

Common usage and description

HUAWEI TECHNOLOGIES CO., LTD.

fsck -a

Repair the file host


automatically

HUAWEI Confidential

Example
fsck -a

df
Query the hard disk usage of partition
Comman
d

Meaning

df

Query the hard


disk usage of
partition

Common usage and description

HUAWEI TECHNOLOGIES CO., LTD.

df -k

Query the hard disk


usage of partition in
Kilo-bytes

HUAWEI Confidential

Example
df -k

du
Query the hard disk usage of file
Comman
d

Meaning

du

Query the hard


disk usage of
file

Common usage and description

HUAWEI TECHNOLOGIES CO., LTD.

du -a

Query the hard disk


usage of file

HUAWEI Confidential

Example
du -a

sync
Synchronize between memory and hard disk

Comman
d

Meaning

sync

Synchronize
between
memory and
hard disk

Common usage and description


sync sync
init6

HUAWEI TECHNOLOGIES CO., LTD.

Synchronize
between memory
and hard disk and
then restart the
host

HUAWEI Confidential

Example
sync sync init6

Chap.2 Linux commands


2.1 System management commands
2.2 Storage management commands
2.3 File management commands
2.4 Network management commands

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

cat
Show the content of ascii file

Comman
d

Meaning

cat

Show the
content of ascii
file

Common usage and


description
cat file

HUAWEI TECHNOLOGIES CO., LTD.

Show the
content of
ascii file

HUAWEI Confidential

example
cat /opt/hlr/hdu/config/hlrcfg.xml

tail
Show the last part content of the file

Comman
d

Meaning

tail

Show the last


part content of
the file

Common usage and description

Example

tail f file

Show the last 10


rows of the file file

tail f
/opt/hlr/hdu/ds/log/xxxx.
log

tail n num file

Always show the last


num rows of the file
file even if the file is
changed real-time

tail n 20
/opt/hlr/hdu/ds/log/xxxx.
log

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

more (less)
Show the content of the file in page

Comman
d

Meaning

more

Show the
content of the
file in page

Common usage and description


more file

HUAWEI TECHNOLOGIES CO., LTD.

Show the content


of the file file in
page

HUAWEI Confidential

Example
more
/opt/hlr/hdu/ds/log/xxxx.log

tar
Pack or unpack the file

Comman
d
tar

Meaning

Common usage and description

Pack or
tar zcvf xxxx.tar.gz
unpacek the file
xxxx

tar zxvf xxxx.tar.gz

Pack the file with


packed name
xxxx.tar.gz

Example
tar zcvf hlr.tar.gz hlr

Unpack the file


xxxx.tar.gz
tar zxvf hlr.tar.gz

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

diff
Differentiate two files

Comman
d

Meaning

diff

Differentiate
two files

Common usage and description


diff file1 file2

HUAWEI TECHNOLOGIES CO., LTD.

Differentiate the file


file1 and file file2

HUAWEI Confidential

Example
diff a.txt b.txt

find
Search the file

Comman Meaning
d
find

Search
the file

Common usage and description


find / -name filename

HUAWEI TECHNOLOGIES CO., LTD.

Search
the file
filename
with initial
path /

HUAWEI Confidential

Example

find /opt/hlr -name


hlrcfg.xml

whereis
Show the path of the file

Comman
d

Meaning

whereis

Show the path


of the file

Common usage and


description
whereis file1

Show the path of


the file file1

Example
whereis ls
ls: /bin/ls
/usr/share/man/man1/ls.1.gz
/
usr/share/man/man1p/ls.1p.g
z

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

chmod
Change the right of the file
Comman
d
chmod

Meaning
Change the
right of the
file

Common usage and description


chmod 700 file1

HUAWEI TECHNOLOGIES CO., LTD.

Change the right


of file file1,and
only its owner can
read, write and
execute right.

HUAWEI Confidential

example
chmod 700 /tmp/1.txt

chown
Change the owner of the file
Command

chown

Meaning

Change the
owner of the
file

Common usage and description


chmod hlr:db2grp1
file1

HUAWEI TECHNOLOGIES CO., LTD.

Change the owner of


file file1, and new
owner and group is
hlr and db2grp1.

HUAWEI Confidential

example
chown hlr:db2grp1
ntpdate.out

Chap.2 Linux commands


2.1 System management commands
2.2 Storage management commands
2.3 File management commands
2.4 Network management commands

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

ifconfig
Show or set the network device
Comman Meaning
d
ifconfig

Show or set
the network
device

Common usage and description

Example

ifconfig

Show the active network


card

ifconfig

ifconfig a

Show all network card

ifconfig a

ifocnfig ethX IP

Set IP for network card


ethX

ifconfig eth1
172.18.100.0

ifconfig ethX
down

Deactivate the network


card ethX

ifconfig eth1 down

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

ethtool
Show or change the detailed information of network card
Com
mand
ethtool

Meaning
Show or change
the detailed
information of
network card

Common usage and description


ethtool ethX

HUAWEI TECHNOLOGIES CO., LTD.

Show the configuraion of


network card ethX

HUAWEI Confidential

Example
ethtool eth1

netstat
Show the network information
Comman
d
netstat

Meaning
Show the
network
information

Common usage and description

Example

netstat -rn

Show the route


information

netstat -rn

netstat -an

Show all network


connection information

netstat an

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

route
Set the route information
Comman
d
route

Meaning

Set the
route
information

Common usage and description

route add
route delete

HUAWEI TECHNOLOGIES CO., LTD.

Example

Add the route


information

route add default


10.85.156.1

Delete the route


information

route delete default


10.85.156.1

HUAWEI Confidential

ping
Check the network connection
Comman
d
ping

Meaning
Check the
network
connection

Common usage and description


ping hostIP

HUAWEI TECHNOLOGIES CO., LTD.

Check the network


connection between
local compute and
hostIP.

HUAWEI Confidential

Example
ping 10.85.156.1

scp
Copy the file remotely
Comman
d

Meaning

Common usage and description


scp file1 IP:/dir

scp

Copy the file


remotely

HUAWEI TECHNOLOGIES CO., LTD.

Copy local file file1


to remote host with
host ip IP and /dir
folder

HUAWEI Confidential

Example
scp a.txt
172.17.128.0:/tmp

Question
How to query and modify current time of the host?
How to query the statistics of CPU, memory and hard disk?
How to query current logging information of the host?
How to query configuration information of network card?
How to copy files between different hosts?
How to query partition information?

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.1 Linux fundamentals


Chap.2 Linux commands
Chap.3 Linux tips
Chap.4 Handling method for
common problems

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.3 Linux tips


3.1 Sharing files
3.2 Executing the script
3.3 File operation
3.4 Get the system
information

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Samba
Sharing the file between Linux and Window
Samba service is offered by Linux and is used to sharing the files between Linux
and Windows. Below are the simple steps to activate samba service. Also you can
refer to software installation manual for detailed steps.

Add samba user in samba configuration file.


Set password for samba user added.
Restart samba service to make the configuration file effective.
Check the samba service is OK or not.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

FTP
Transfer the file between Linux and Linux or Windows OS
You can activate it by following steps.

Edit the file /etc/xinetd.d/vsftpd by modifying the filed disable from yes to no.
Edit the file /etc/vsftpd.conf by activate the fields local_enable and write_enable.
Edit the file /etc/ftpusers by deactivate the root user.
Restart the FTP service with command /etc/init.d/xinetd restart
Check the FTP service is OK or not

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.3 Linux tips


3.1 Sharing files
3.2 Executing the script
3.3 File operation
3.4 Get the system
information

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Tips for command and script execution

User symbol & to put the command execution background, such as ls la &.
Use fg command to switchover from background to foreground, such as fg
command.
Use history command to query the history information of command execution.
Use script command to record the output information of the terminal. For example,
use script /tmp/1.log to record the output information of the terminal into file
/tmp/1.log.
Remember to use CTRL+d to terminate the recording procedure.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.3 Linux tips


3.1 Sharing files
3.2 Executing the script
3.3 File operation
3.4 Get the system
information

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Tips for file and fold operation


Use cd -command to go back to the folder last entered.
Use ls -R command to get the layer relation between files and folders.
Use tree command to show the structure of the folder.
Remove some files with odd name.

Remove the file with name a: rm ./-a rm -- -a

Remove the file with name \a : rm \\a

Find and kill the process occupying the file you want to delete.

fuser filename

fuser k filename

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.3 Linux tips


3.1 Sharing files
3.2 Executing the script
3.3 File operation
3.4 Get the system
information

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Get the system information


Get the OS and hardware information
Get the OS information

uname -a

Get the CPU information

cat /proc/cpuinfo

Get the memory information

cat /proc/meminfo

Get the partition information

cat /proc/partitions

Get the information of PCI devices

lspci

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Get the system information


Get the status information of the system
Show the top ten processes by consuming CPU

ps aux |head -1 ;ps aux |sort -rn +2 |head -10

Show the top ten process by consuming memory

ps aux |head -1 ;ps aux |sort -rn +3 |head -10

Show the top ten processes by handling time

ps vx |head -1 ;ps vx |grep -v PID |sort -rn +3 |head -10

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.1 Linux fundamentals


Chap.2 Linux commands
Chap.3 Linux tips
Chap.4 Handling method for
common problems

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.4 Common problems


4.1 SSH problem
4.2 network problem
4.3 login problem

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

SSH problem
hlr_dru01:/var/log # ssh 172.17.128.110
ssh: connect to host 172.17.128.110 port 22: No route to host
Possible reason 1: The network connection between the client and the
server is not OK.
Possible reason 2: If network connection is OK and authentication is
not OK, delete the file ~/.ssh/known_hosts of the client.
hlr_dru01:/var/log # ssh hlr_dru03
ssh: hlr_dru03: Temporary failure in name resolution
Possible reason: There is no reliable relation in the client. The solution
is editing the file /etc/hosts in the client by adding the IP of the host.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.4 Common problems


4.1 SSH problem
4.2 network problem
4.3 login problem

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

General handling method for network problem


Use ping command to test the network connection.
Check the physical connection of the network.
Check the status of network card.
Check the configuration of the network card.
Use netstat command to check the status of the network.
Use cpdump command to check the flux of the netork.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Chap.4 Common
problems
4.1 SSH problem
4.2 network problem
4.3 login problem

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Root user cannot login the host


Possible reason 1: The administrator forget the password of root user
Possible reason 2: The password of root user is changed by another one.

For both possible reason mentioned above, we can solve the problem by following
steps.
Boot the host from CD and enter single-user mode.
Use mount /dev/sda2 /mnt command to mount the / folder of the disk to /mnt.
Edit the /mnt/etc/passwd file by clear the password field (namely the second
column) of root user.
Edit the /mnt/etc/shadow file by clear the password field (namely the second
column) of root user.
After above two steps, the password of root user is null, and you can boot the
system with hard disk and enter the system with null password.

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Summary

Chap.1 Linux fundamentals


Chap.2 Linux commands
Chap.3 Linux tips
Chap.4 Handling method for

common problems

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Security Level: B

Thank You
www.huawei.com
www.huawei.com

HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI Confidential

Anda mungkin juga menyukai