Linux Fundamental
ISSUE1.0
www.huawei.com
HUAWEI Confidential
HUAWEI Confidential
Reference
Linux Bible 2007
Linux in a Nutshell 5th Edition
Tips And Techniques For Everyday
Use
HUAWEI Confidential
HUAWEI Confidential
HUAWEI Confidential
HUAWEI Confidential
Solaris AIX
and HP_UNIX
etc.
Small
Smallarchives
archivessystem
system
Unix
Unix
Some
Someimportant
importantUnix
Unixbranches
branches
Kinds
Kindsofofdifferent
differentUnix
Unixversion
version
Linus Torvalds of
Finland College in
1991
GNU
GNUand
andFSF
FSF
Linux
Linux
HUAWEI Confidential
Linux components
Linux Shell
Linux
Kernel
Practical
tools
HUAWEI Confidential
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 Confidential
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.
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
Debian
Ubuntu
HUAWEI Confidential
Fedora Core
OpenSuse
HUAWEI Confidential
Regular file
Directory file
Link file
Device file
# cd /etc ; ls -al
# cd /dev ; ls al
HUAWEI Confidential
HUAWEI Confidential
HUAWEI Confidential
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 Confidential
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 Confidential
HUAWEI Confidential
HUAWEI Confidential
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 Confidential
HUAWEI Confidential
HUAWEI Confidential
HUAWEI Confidential
HUAWEI Confidential
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
/etc/inittab
HUAWEI Confidential
RUNLEVEL
ACTION
Power-off
Single-user mode
Free mode
Restart
HUAWEI Confidential
shutdown -h now
halt the most violent mode to shut down the host, equivalent to press the power-off
button.
HUAWEI Confidential
HUAWEI Confidential
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 Confidential
HUAWEI Confidential
HUAWEI Confidential
adduser useradd)
Add or update the user information
Comman
d
meaning
adduser
Add an
user
HUAWEI Confidential
example
useradd
-d
/home/db2
inst
db2inst
userdel
Delete an user
command
meaning
userdel
Delete the
user
userdel -rf
username
HUAWEI Confidential
example
userdel -rf db2inst
passwd
Set or modify the user mode
command
meaning
passwd
Set or modify
the user
password
HUAWEI Confidential
example
passwd db2inst
date
Display or modify current time of the system
Comman Meaning
d
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 Confidential
hwclock clock
Display or set current time of the hardware
Comman
d
Meanin
g
hwclock
Display
or set
current
time of
the
hardware
Example
hwclock
hwclock
hwclock w
hwclock w
hwclock s
HUAWEI Confidential
hwclock s
uptime
Display the running duration
Comman
d
Meaning
uptime
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 Confidential
free
Show the usage of memory
Comman
d
Meaning
free
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
example
iostat
iostat
iostat m
iostat 1
iostat m n
HUAWEI Confidential
iostat 1 10
mpstat
Show the statistics related to CPU
Comman
d
Meaning
mpstat
Show the
statistics
related to CPU
mpstat m
mpstat P ALL
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
Example
vmstat
vmstat
vmstat a
vmstat 1
vmstat a b
vmstat 1 10
Show the statistics in a
seconds, totally b times
HUAWEI Confidential
ps
Show the processes of the system
Comman
d
Meaning
ps
Show the
processes
ps
ps
ps ef|grep
keyword
ps ef|grep hlr
ps aux
ps aux
HUAWEI Confidential
Example
kill
Send signal to certain process
Comman
d
Meaning
kill
Send signal
to certain
process
HUAWEI Confidential
Example
Kill -9 40000
top
Show the processes executing
Comman
d
Meaning
Example
top
Show the
processes
executing
top
top
top b
HUAWEI Confidential
top -b
uname
Show the system information
Comman
d
Meaning
uname
Show the
system
information
Example
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
Example
hostname
Show or
modify the
host name
hostname
hostname
hostname name1
hostname
hle_db01
HUAWEI Confidential
who w
Show the user online
Comman
d
Meaning
who
Show the
user online
Example
who
who
who -r
HUAWEI Confidential
last
Display the information of the user logged
Comman
d
Meaning
last
Display the
information of the
user logged
HUAWEI Confidential
example
last
Meaning
halt
Restart or
shutdown
the host
reboot
poweroff
Shut down
the host
Restart the
host
Shutdown
the host
HUAWEI Confidential
example
sync halt
shutdown
Restart or shut down the host
Comman
d
Meaning
shutdown
Restart or
shut down
the host
Shut down
the host
right now
Restart the
host right
now
HUAWEI Confidential
example
chkconfig
Check or set the services of the host
Comman
d
Meaning
chkconfig
Check or
set the
services of
the host
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 Confidential
chkconfig d xinetd
crontab
Query or set the timed task
Comman
d
Meaning
crontab
Query or
set the
timed task
Example
crontab -e
crontab -e
crontab -l
crontab -l
HUAWEI Confidential
dmesg
Query the boot message
Comman
d
Meaning
example
dmesg
Query the
boot
message
dmesg >
/tmp/dmesg.txt
HUAWEI Confidential
HUAWEI Confidential
fdisk
Partition tool of Linux
Comman
d
Meaning
fdisk
Partition tool of
Linux
fdisk -l
Query current
partition of the host
HUAWEI Confidential
Example
fdisk -l
fsck
Repair the file system
Comman
d
Meaning
fsck
fsck -a
HUAWEI Confidential
Example
fsck -a
df
Query the hard disk usage of partition
Comman
d
Meaning
df
df -k
HUAWEI Confidential
Example
df -k
du
Query the hard disk usage of file
Comman
d
Meaning
du
du -a
HUAWEI Confidential
Example
du -a
sync
Synchronize between memory and hard disk
Comman
d
Meaning
sync
Synchronize
between
memory and
hard disk
Synchronize
between memory
and hard disk and
then restart the
host
HUAWEI Confidential
Example
sync sync init6
HUAWEI Confidential
cat
Show the content of ascii file
Comman
d
Meaning
cat
Show the
content of ascii
file
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
Example
tail f file
tail f
/opt/hlr/hdu/ds/log/xxxx.
log
tail n 20
/opt/hlr/hdu/ds/log/xxxx.
log
HUAWEI Confidential
more (less)
Show the content of the file in page
Comman
d
Meaning
more
Show the
content of the
file in page
HUAWEI Confidential
Example
more
/opt/hlr/hdu/ds/log/xxxx.log
tar
Pack or unpack the file
Comman
d
tar
Meaning
Pack or
tar zcvf xxxx.tar.gz
unpacek the file
xxxx
Example
tar zcvf hlr.tar.gz hlr
HUAWEI Confidential
diff
Differentiate two files
Comman
d
Meaning
diff
Differentiate
two files
HUAWEI Confidential
Example
diff a.txt b.txt
find
Search the file
Comman Meaning
d
find
Search
the file
Search
the file
filename
with initial
path /
HUAWEI Confidential
Example
whereis
Show the path of the file
Comman
d
Meaning
whereis
Example
whereis ls
ls: /bin/ls
/usr/share/man/man1/ls.1.gz
/
usr/share/man/man1p/ls.1p.g
z
HUAWEI Confidential
chmod
Change the right of the file
Comman
d
chmod
Meaning
Change the
right of the
file
HUAWEI Confidential
example
chmod 700 /tmp/1.txt
chown
Change the owner of the file
Command
chown
Meaning
Change the
owner of the
file
HUAWEI Confidential
example
chown hlr:db2grp1
ntpdate.out
HUAWEI Confidential
ifconfig
Show or set the network device
Comman Meaning
d
ifconfig
Show or set
the network
device
Example
ifconfig
ifconfig
ifconfig a
ifconfig a
ifocnfig ethX IP
ifconfig eth1
172.18.100.0
ifconfig ethX
down
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
HUAWEI Confidential
Example
ethtool eth1
netstat
Show the network information
Comman
d
netstat
Meaning
Show the
network
information
Example
netstat -rn
netstat -rn
netstat -an
netstat an
HUAWEI Confidential
route
Set the route information
Comman
d
route
Meaning
Set the
route
information
route add
route delete
Example
HUAWEI Confidential
ping
Check the network connection
Comman
d
ping
Meaning
Check the
network
connection
HUAWEI Confidential
Example
ping 10.85.156.1
scp
Copy the file remotely
Comman
d
Meaning
scp
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 Confidential
HUAWEI Confidential
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.
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 Confidential
HUAWEI Confidential
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 Confidential
HUAWEI Confidential
Find and kill the process occupying the file you want to delete.
fuser filename
fuser k filename
HUAWEI Confidential
HUAWEI Confidential
uname -a
cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/partitions
lspci
HUAWEI Confidential
HUAWEI Confidential
HUAWEI Confidential
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 Confidential
HUAWEI Confidential
HUAWEI Confidential
Chap.4 Common
problems
4.1 SSH problem
4.2 network problem
4.3 login problem
HUAWEI Confidential
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 Confidential
Summary
common problems
HUAWEI Confidential
Security Level: B
Thank You
www.huawei.com
www.huawei.com
HUAWEI Confidential