補充 /etc/hostname :CenOS7主機名配置文件 /etc/sysconfig/network C6主機名配置文件 修改主機名 永久生效 臨時改一下 /etc/sysctl.conf Linux內核參數信息文件※※※※※ 調整Linux系統、優化需要配置這個文件 sysctl p 讓修 ...
-
補充
/etc/hostname :CenOS7主機名配置文件
[root@oldboyedu ~]# cat /etc/hostname oldboyedu
/etc/sysconfig/network C6主機名配置文件
[root@oldboy ~]# cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=oldboy
-
修改主機名
-
永久生效
[root@oldboyedu ~]# hostnamectl set-hostname oldboy [root@oldboyedu ~]# hostname oldboy
-
臨時改一下
[root@oldboyedu ~]# hostname sun [root@oldboyedu ~]# hostname sun
-
/etc/sysctl.conf Linux內核參數信息文件※※※※※
調整Linux系統、優化需要配置這個文件
sysctl -p 讓修改後的文件生效
-
一、/usr目錄 用戶相關
1、 /usr/local:源碼編譯安裝軟體預設的位置路徑
- 軟體安裝(瞭解):
- rpm安裝
- rpm -ivh 軟體包的包名.rpm(幾乎不用)
- yum安裝,rpm包管理器,智能幫我們找一個軟體包需要的依賴包(推薦)
- 本質就是rpm安裝。自動解決依賴,自動使用rpm命令實現安裝。
- 源代碼安裝。
- rpm安裝
2./usr/src:存放源碼文件的目錄
二、/var/目錄 Linux記錄各種日誌目錄
1./var/log:記錄系統及軟體運行信息文件所在的目錄
log日誌信息====電腦運行行為
2./var/log/messages:Linux系統級別日誌文件*****
記錄Linux系統運行行為的文件,正常行為 非正常行為。
[root@oldboyedu ~]# tail /var/log/messages
Apr 7 19:22:12 oldboyedu NetworkManager[1134]: <info> [1586258532.0068] policy: set-hostname: set hostname to 'oldboy' (from system configuration)
Apr 7 19:22:12 oldboyedu dbus[887]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr 7 19:22:12 oldboyedu systemd: Starting Network Manager Script Dispatcher Service...
Apr 7 19:22:12 oldboyedu systemd-hostnamed: Changed host name to 'oldboy'
Apr 7 19:22:12 oldboyedu dbus[887]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr 7 19:22:12 oldboyedu systemd: Started Network Manager Script Dispatcher Service.
Apr 7 19:22:12 oldboyedu nm-dispatcher: req:1 'hostname': new request (2 scripts)
Apr 7 19:22:12 oldboyedu nm-dispatcher: req:1 'hostname': start running ordered scripts...
Apr 7 19:22:12 oldboyedu nm-dispatcher: req:2 'hostname': new request (2 scripts)
Apr 7 19:22:12 oldboyedu nm-dispatcher: req:2 'hostname': start running ordered scripts...
3./var/log/secure:用戶登錄信息日誌文件(安全日誌文件)
[root@oldboyedu ~]# tail /var/log/secure
Apr 7 19:19:55 oldboyedu polkitd[880]: Loading rules from directory /usr/share/polkit-1/rules.d
Apr 7 19:19:55 oldboyedu polkitd[880]: Finished loading, compiling and executing 2 rules
Apr 7 19:19:55 oldboyedu polkitd[880]: Acquired the name org.freedesktop.PolicyKit1 on the system bus
Apr 7 19:19:58 oldboyedu sshd[1489]: Server listening on 0.0.0.0 port 22.
Apr 7 19:19:58 oldboyedu sshd[1489]: Server listening on :: port 22.
Apr 7 19:20:05 oldboyedu sshd[3398]: reverse mapping checking getaddrinfo for bogon [10.0.0.1] failed - POSSIBLE BREAK-IN ATTEMPT!
Apr 7 19:20:05 oldboyedu sshd[3398]: Accepted password for root from 10.0.0.1 port 53921 ssh2
Apr 7 19:20:05 oldboyedu sshd[3398]: pam_unix(sshd:session): session opened for user root by (uid=0)
Apr 7 19:22:11 oldboyedu polkitd[880]: Registered Authentication Agent for unix-process:9178:14338 (system bus name :1.23 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Apr 7 19:22:12 oldboyedu polkitd[880]: Unregistered Authentication Agent for unix-process:9178:14338 (system bus name :1.23, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
4./var/log/dmesg:記錄硬體信息載入情況的日誌文件
[root@oldboyedu ~]# tail /var/log/dmesg
[ 5.706282] cryptd: max_cpu_qlen set to 1000
[ 5.811659] AVX2 version of gcm_enc/dec engaged.
[ 5.811662] AES CTR mode by8 optimization enabled
[ 5.850428] Adding 786428k swap on /dev/sda2. Priority:-2 extents:1 across:786428k FS
[ 5.869213] XFS (sda1): Mounting V5 Filesystem
[ 6.104993] alg: No test for __gcm-aes-aesni (__driver-gcm-aes-aesni)
[ 6.110197] alg: No test for __generic-gcm-aes-aesni (__driver-generic-gcm-aes-aesni)
[ 6.122383] XFS (sda1): Ending clean mount
[ 6.336590] ppdev: user-space parallel port driver
[ 6.642353] type=1305 audit(1586258394.437:4): audit_pid=792 old=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:auditd_t:s0 res=1
- 對應命令dmesg
三、/proc下的重要路徑知識
1./proc/meminfo 查系統記憶體
[root@oldboyedu ~]# cat /proc/meminfo
MemTotal: 3861320 kB
MemFree: 3484452 kB
MemAvailable: 3449064 kB
Buffers: 2076 kB
Cached: 151372 kB
SwapCached: 0 kB
Active: 113984 kB
Inactive: 108704 kB
Active(anon): 69920 kB
Inactive(anon): 11140 kB
Active(file): 44064 kB
Inactive(file): 97564 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 786428 kB
SwapFree: 786428 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 69264 kB
Mapped: 27244 kB
Shmem: 11820 kB
Slab: 68860 kB
SReclaimable: 27848 kB
SUnreclaim: 41012 kB
KernelStack: 3776 kB
PageTables: 4372 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 2717088 kB
Committed_AS: 269960 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 185700 kB
VmallocChunk: 34359310332 kB
HardwareCorrupted: 0 kB
AnonHugePages: 8192 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 89920 kB
DirectMap2M: 3055616 kB
DirectMap1G: 3145728 kB
-
對應命令:free
[root@oldboyedu ~]# free total used free shared buff/cache available Mem: 3861320 195676 3484348 11820 181296 3448960 Swap: 786428 0 786428 [root@oldboyedu ~]# free -m #以兆顯示 total used free shared buff/cache available Mem: 3770 191 3402 11 177 3368 Swap: 767 0 767
2./proc/cpuinfo 查看CPU
[root@oldboyedu ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
stepping : 3
microcode : 0x25
cpu MHz : 3199.073
cache size : 6144 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm invpcid_single ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt arat spec_ctrl intel_stibp flush_l1d arch_capabilities
bogomips : 6398.14
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:
3./proc/loadavg 查看負載(系統繁忙程度的一個綜合指標)
[root@oldboyedu ~]# cat /proc/loadavg
0.00 0.02 0.05 2/110 9288
-
對應命令:uptime
[root@oldboyedu ~]# uptime 19:35:30 up 15 min, 1 user, load average: 0.00, 0.02, 0.05 系統時間 啟動狀態 開機時間 登入用戶 平均負載 1分鐘 5分鐘 15分鐘
4、/proc/mounts 當前設備掛載列表信息文件
[root@oldboyedu ~]# tail /proc/mounts
cgroup /sys/fs/cgroup/cpuset cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuset 0 0
configfs /sys/kernel/config configfs rw,relatime 0 0
/dev/sda3 / xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0
selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=31,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13527 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,seclabel,relatime 0 0
mqueue /dev/mqueue mqueue rw,seclabel,relatime 0 0
/dev/sda1 /boot xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0
tmpfs /run/user/0 tmpfs rw,seclabel,nosuid,nodev,relatime,size=386132k,mode=700 0 0
四、CentOS6啟動流程
五、CentOS7啟動流程
六、vi/vim編輯器
普通模式:
:set nu 顯示行號
普通模式:移動游標:
行尾 $
行首 0
文件尾部 G
文件開頭 gg
到指定行 阿拉伯數字gg
普通模式:搜索與替換操作
向下搜索 /3306 繼續搜 按n,反向搜N
向上搜索 ?80 繼續搜 按n,反向搜N
普通模式:替換
:%s/A/B/g
:%s#world#oldgirl#g
/#還可以用@等特殊字元替換,實際就是分隔符。
s是替換 g表示全局(所有)
指定行號替換:
:4,6s/oldboy/oldgirl/g
普通模式:複製、粘貼、刪除等操作
刪除單行 dd(剪切)
刪除多行 ndd n用任意數字替換
撤銷 u
單行複製 yy
多行複製 nyy n用任意數字替換
粘貼 p
進入編輯模式命令
i 插入*****
A 追加 行尾插入
o 下一行開頭插入
O 上一行開頭插入
a 游標下一個字元插入
命令行模式
:wq 退出並保存
:wq! 退出並強制保存,“!”為強制的意思
:q! 強制退出,不保存
:set nu 顯示行號
:set nonu 與set nu相反,取消行號
七、命令
1、cat 查看文件內容
[root@oldboyedu ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
stepping : 3
microcode : 0x25
cpu MHz : 3199.073
cache size : 6144 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
2.head查看文件開頭(預設前10行)
- -n查看多少行
[root@oldboyedu ~]# seq 30 >test.txt
[root@oldboyedu ~]# cat test.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@oldboyedu ~]# head -n 5 test.txt
1
2
3
4
5
3.tail 查看文件尾部(預設最後10行)
- -n查看多少行
[root@oldboyedu ~]# tail test.txt
21
22
23
24
25
26
27
28
29
30
[root@oldboyedu ~]# tail -n 5 test.txt
26
27
28
29
30
- -f 動態查看(用於查看Linux日誌文件)
[root@oldboyedu ~]# tail -f test.txt
21
22
23
24
25
26
27
28
29
30
4.tac按行翻轉文件內容(和cat相反)
5.rev左右按字元翻轉行的內容
6、tr 替換或刪除字元
-
translate or delete characters(替換或刪除字元)
- Linux中嚴格區分字母的大小寫
- 替換的單位是字元
[root@localhost ~]# cat > text.txt << END > Welcome to oldboy training. > we are excellent. > END [root@localhost ~]# cat text.txt Welcome to oldboy training. we are excellent. #示例一,替換單個字元 [root@localhost ~]# tr "w" "1" < text.txt Welcome to oldboy training. 1e are excellent. #示例二,替換多個字元(被替換的字母個數與替換的字元個數相等) [root@localhost ~]# tr "a-b" "0-3" < text.txt Welcome to old1oy tr0ining. we 0re excellent. #示例三,替換成轉義字元 [root@localhost ~]# tr "a-b" "\t" < text.txt Welcome to old oy tr ining. we re excellent. [root@localhost ~]# tr "a-b" "\n" < text.txt Welcome to old oy tr ining. we re excellent.
7、grep文本過濾
- print lines matching a pattern(列印行匹配一個模式/樣式)
[root@localhost ~]# grep "oldboy" text.txt
Welcome to oldboy training.
-
--color=auto 過濾內容加色(預設紅色)
-
-v 取反
[root@localhost ~]# grep -v "oldboy" text.txt we are excellent.
-
-i 不區分大小寫
[root@localhost ~]# grep "w" text.txt we are excellent. [root@localhost ~]# grep -i "w" text.txt Welcome to oldboy training. we are excellent.
-
-n 顯示行號
[root@localhost ~]# grep -n "w" text.txt 2:we are excellent. [root@localhost ~]# grep -ni "w" text.txt 1:Welcome to oldboy training. 2:we are excellent.
-
-o 只顯示過濾的內容(預設按行過濾)
[root@localhost ~]# cat text.txt Welcome to oldboy training. we are excellent. [root@localhost ~]# echo "oldboy1" >> text.txt [root@localhost ~]# cat text.txt Welcome to oldboy training. we are excellent. oldboy1 [root@localhost ~]# grep -oi "oldboy" text.txt oldboy oldboy [root@localhost ~]# grep -o "oldboy" text.txt oldboy oldboy
-
-E 擴展的grep,即egrep
[root@localhost ~]# grep -E "to|are" text.txt Welcome to oldboy training. we are excellent. [root@localhost ~]# egrep "to|are" text.txt Welcome to oldboy training. we are excellent.
8、重定向符號的核心知識
-
>或1>標準輸出重定向
- 箭頭方向就是數據流向,把左邊的數據流向到右邊。
- 會清空右邊之前的數據。
[root@localhost ~]# cp text.txt{,.ori} [root@localhost ~]# ls anaconda-ks.cfg text.txt text.txt.ori [root@localhost ~]# cat text.txt Welcome to oldboy training. we are excellent. oldboy1 [root@localhost ~]# > text.txt [root@localhost ~]# cat text.txt
-
>>或1>>追加輸出重定向
- 箭頭方向就是數據流向,把左邊的數據流向到右邊。
- 把內容追加到文件內容尾部
[root@localhost ~]# cat text.txt Welcome to oldboy training. we are excellent. oldboy1 [root@localhost ~]# echo "sun">> text.txt [root@localhost ~]# cat text.txt Welcome to oldboy training. we are excellent. oldboy1 sun
-
<或0<標準輸入重定向。
- 箭頭方向就是數據流向。
[root@localhost ~]# tr "w" "0" < text.txt Welcome to oldboy training. 0e are excellent. oldboy1 sun
-
<<或0<<追加輸入重定向
[root@localhost ~]# cat >> text.txt << END > 123 > 234 > END [root@localhost ~]# cat text.txt Welcome to oldboy training. we are excellent. oldboy1 sun 123 234 [root@localhost ~]# cat text.txt Welcome to oldboy training. we are excellent. oldboy1 sun 123 234 [root@localhost ~]# cat > text.txt << END > 123 > 234 > end > END [root@localhost ~]# cat text.txt 123 234 end
-
2>標準錯誤輸出重定向
- 會清空保存錯誤日誌的文件(每次看只能看見最近一次的錯誤)
-
2>>標準錯誤追加輸出重定向
[root@localhost ~]# ca text.txt 1>> text1.txt 2>> text2.txt [root@localhost ~]# ls anaconda-ks.cfg text1.txt text2.txt text.txt text.txt.ori [root@localhost ~]# cat text1.txt [root@localhost ~]# cat text2.txt -bash: ca: command not found #正確日誌和錯誤日誌寫到一個文件里 [root@localhost ~]# ca text.txt 1>> text1.txt 2>&1 [root@localhost ~]# cat text1.txt -bash: ca: command not found [root@localhost ~]# ca text.txt 1>> text1.txt 2>&1 [root@localhost ~]# cat text1.txt -bash: ca: command not found -bash: ca: command not found
-
數字1:標準輸出
-
數字0:標準輸入
-
數字2:錯誤輸出