第1章 磁盤管理
1.1 必須要了解的。
1.1.1 ps aux 命令中 RSS 與VSZ的含義
rss 進程占用的物理內存的大小 單位:kb ;
vsz 進程占用的虛擬的內存大小(物理內存+swap)
1.1.2 top命令的參數
M 按照內存使用率排序
P 按照cpu的使用率排序
1.1.3 htop 命令的安裝方法
要配置 epel源
http://mirrors.aliyun.com
1.2 磁盤分區之parted + gpt
1.2.1 fdisk 與 parted 的區別
fdisk mbr 分區表 硬盤容量小於2TB
parted gpt 分區表 硬盤容量大於2TB
1.2.2 查看下幫助信息
[root@znix ~]# parted /dev/sdc
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) h
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
創建分區表
mkpart PART-TYPE [FS-TYPE] START END make a partition
創建一個分區
mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system
創建一個分區 分區帶着文件系統
print [devices|free|list,all|NUMBER] display the partition table, available
devices, free space, all found partitions, or a particular partition
顯示分區信息
rm NUMBER delete partition NUMBER
刪除一個分區
1.2.3 創建分區表
[root@znix ~]# parted /dev/sdc
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt #創建GPT分區表
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1.2.4 mkpart 可以使用的PART-TYPE類型
GPT 格式可以創建N個主分區,所以類型都選為主分區即可。
(parted) help mkpart
mkpart PART-TYPE [FS-TYPE] START END make a partition
PART-TYPE is one of: primary, logical, extended
主分區 ,邏輯分區 ,擴展分區
1.2.5 對磁盤進行分區
(parted) mkpart primary 0 10
Warning: The resulting partition is not properly aligned for best performance.
提示分區沒有對齊,這個錯誤無視即可。
Ignore/Cancel? I 忽略/取消
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 10.0MB 9983kB primary
1.2.6 再創建一個分區
(parted) mkpart primary 10 20
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 10.0MB 9983kB primary
2 10.5MB 19.9MB 9437kB primary
⚠注意:parted 創建分區實時生效,比較危險。
1.3 使用parted命令非交互式創建分區
[root@znix ~]# parted /dev/sdc mkpart primary 50 100
Information: You may need to update /etc/fstab.
[root@znix ~]# parted /dev/sdc print #顯示磁盤的格式
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 50.0MB 50.0MB primary
2 50.3MB 99.6MB 49.3MB primary
1.4 創建swap分區及使用
【JAVA環境常見】linux內存不夠用,會使用swap分區。
1.4.1 手動添加swap空間,創建一個文件
使用dd 命令創建一個塊文件。
[root@znix ~]# dd if=/dev/zero of=/tmp/100M bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 2.96654 s, 35.3 MB/s
[root@znix ~]# ll -h /tmp/100M
-rw-r--r-- 1 root root 100M Sep 18 10:01 /tmp/100M
1.4.2 查看創建出來的文件的類型
現在的類型為data 數據塊。
[root@znix ~]# file /tmp/100M
/tmp/100M: data
1.4.3 將這個文件變成swap
mkswap命令將文件類型格式化成swap格式
[root@znix ~]# mkswap /tmp/100M
mkswap: /tmp/100M: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=81fa08be-a18f-4bc6-b950-fa3d90f969a1
1.4.4 修改之后的文件類型:
[root@znix ~]# file /tmp/100M
/tmp/100M: Linux/i386 swap file (new style) 1 (4K pages) size 25599 pages
1.4.5 讓這個文件起作用,將swap空間添加到系統中
實例1-1 查看swap的所使用情況
[root@znix ~]# free -h
total used free shared buffers cached
Mem: 474M 465M 8.8M 252K 15M 357M
-/+ buffers/cache: 93M 381M
Swap: 767M 0B 767M
實例1-2 使用swap命令將swap文件,添加到系統中。
[root@znix ~]# swapon /tmp/100M
實例1-3 現在查看 swap的使用情況
[root@znix ~]# free -h
total used free shared buffers cached
Mem: 474M 465M 8.7M 252K 15M 357M
-/+ buffers/cache: 93M 381M
Swap: 867M 0B 867M
實例1-4 查看swap的詳細信息,使用 swap -s 。
[root@znix ~]# swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 786428 0 -1
/tmp/100M file 102396 0 -2
1.4.6 如何讓添加的swap文件永久生效
1)把命令放入/etc/rc.local 開機自啟動文件中。
a) swapon /tmp/100M 命令
2)寫入/etc/fstab 文件中
/tmp/100M swap swap defaults 0 0
第5列 dump備份
第6列 磁盤檢查
1.5 文件系統
1.5.1 文件系統的作用:
文件系統決定文件在磁盤上是怎么存放的
1.5.2 文件系統的組成:
超級塊 super block· dumpe2fs -h /dev/sdb1 顯示超級快中的信息。
[root@znix ~]# dumpe2fs -h /dev/sdb1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 7101630b-b325-49d1-92b9-0a500c2a07f6
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 25896
Block count: 103424
Reserved block count: 5171
Free blocks: 94502
Free inodes: 25885
First block: 1
Block size: 1024 # block的大小
Fragment size: 1024
Reserved GDT blocks: 256
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 1992
Inode blocks per group: 249
Flex block group size: 16
Filesystem created: Fri Sep 15 12:01:27 2017
Last mount time: Fri Sep 15 12:02:37 2017
Last write time: Fri Sep 15 16:38:30 2017
Mount count: 1 #掛載的次數
Maximum mount count: -1
……
1.6 常用的文件系統
opensuse linux 默認文件系統 ReiserFS
Centos7 采用 XFS 文件系統
Centos6 采用ext4 文件系統
Centos5 采用ext3 文件系統
IBM 的 AIX使用JFS 日志文件系統。
1.6.1 查看系統中的文件系統
df -T 參數,顯示的是分區的文件類型 type 。
[root@znix ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 8.8G 2.1G 6.3G 26% /
tmpfs tmpfs 238M 0 238M 0% /dev/shm
/dev/sda1 ext4 190M 40M 141M 22% /boot
tmpfs 是臨時文件系統,速度較快。
1.6.2 文件系統使用范圍
ReiserFS 適用於大量小文件的
xfs 適合數據庫
ext4 使用較廣,適用於大多數的用途。
ext2 沒有日志的功能 (速度較快)
1.7 測試磁盤的讀寫速度
1.7.1 測試寫入速度 dd 命令
[root@znix ~]# dd if=/dev/zero of=/tmp/100M bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 2.96654 s, 35.3 MB/s
[root@znix ~]# ll -h /tmp/100M
-rw-r--r-- 1 root root 100M Sep 18 10:01 /tmp/100M
1.7.2 測試讀取速度 hdparm
[root@znix ~]# hdparm -t /dev/sdb
/dev/sdb:
Timing buffered disk reads: 102 MB in 0.81 seconds = 125.23 MB/sec
第2章 sed命令詳解
2.1 sed 命令的作用
sed 取某一行 查找替換。
增加 刪除 修改 查詢
sed == stream editor 字符流編輯器
sed命令的格式:
sed '找誰干啥' files
pattern space 模式空間
hold space 保留空間
2.2 sed常用命令的功能
2.2.1 環境准備
[root@znix ~]# cat person.txt
101,clsn,CEO
102,znix,CTO
103,Nmtui,COO
104,yy,CFO
105,hehe,CIO
2.3 查詢過程
2.3.1 指定行號
[root@znix ~]# sed -n '3p' person.txt
103,Nmtui,COO
2.3.2 指定內容,p顯示
[root@znix ~]# sed -n '/yy/p' person.txt
104,yy,CFO
2.3.3 查找連續的行(指定行號)
[root@znix ~]# sed -n '1,5p' person.txt
101,clsn,CEO
102,znix,CTO
103,Nmtui,COO
104,yy,CFO
105,hehe,CIO
2.3.4 從包含101的行,到包含103的行
[root@znix ~]# sed -n '/101/,/103/p' person.txt
101,clsn,CEO
102,znix,CTO
103,Nmtui,COO
2.3.5 從某一行到最后一行
$在sed中表示最后一行。
[root@znix ~]# sed -n '$p' person.txt
105,hehe,CIO
[root@znix ~]# sed -n '2,$p' person.txt
102,znix,CTO
103,Nmtui,COO
104,yy,CFO
105,hehe,CIO
2.3.6 找第1,4,5行
一行中有多個命令用;分隔。
[root@znix ~]# sed '1p;4p;5p' -n person.txt
101,clsn,CEO
104,yy,CFO
105,hehe,CIO
2.4 sed的刪除測試
d 刪除
2.4.1 刪除第一行
加上-i 參數,刪除文件的內容
[root@znix ~]# sed '1d' person.txt
102,znix,CTO
103,Nmtui,COO
104,yy,CFO
105,hehe,CIO
2.4.2 顯示不包含clsn的行
!表示取反
[root@znix ~]# sed '/clsn/d' person.txt
102,znix,CTO
103,Nmtui,COO
104,yy,CFO
105,hehe,CIO
105,hehe,CIO
[root@znix ~]# sed -n '/clsn/!p' person.txt
102,znix,CTO
103,Nmtui,COO
104,yy,CFO
105,hehe,CIO
2.5 插入
2.5.1 i 插入到文件的行的上一行 insert
[root@znix ~]# sed '3i 100,znix,OOO' person.txt #i之后的空格就可以不些
101,clsn,CEO
102,znix,CTO
100,znix,OOO
103,Nmtui,COO
104,yy,CFO
105,hehe,CIO
2.5.2 a 追加到文件的行的下一行 append
[root@znix ~]# sed '3a 100,znix,OOO' person.txt #a之后的空格就可以不些
101,clsn,CEO
102,znix,CTO
103,Nmtui,COO
100,znix,OOO
104,yy,CFO
105,hehe,CIO
第3章 linux里面與windows互相傳文件
3.1 使用 lrzsz ,需要yum 安裝
[root@znix ~]# yum install lrzsz
rz 把文件上傳到linux (直接把windows文件拖到xshell窗口即可)
sz 把linux的文件下載到windows中.
3.2 把文件打包,壓縮。
打包格式要在linux和windows 中都可以使用,可以選擇zip格式。
[root@znix ~]# zip -r /tmp/etc_$(date +%F).zip /etc/
adding: etc/ (stored 0%)
adding: etc/passwd (deflated 61%)
adding: etc/ltrace.conf (deflated 73%)
adding: etc/filesystems (deflated 16%)
……
3.3 下載文件
[root@znix ~]# sz /tmp/ser_2017-09-08_16.tar.gz
3.4 長傳文件
[root@znix ~]# rz