目錄
1.echo、cat與printf
2. > 操作符 與 >> 操作符
3. < 操作符
4.消息傳送 + linux文件深入
5.文件類型
6.mv命令
7.時間相關指令
8.查找命令
9.grep命令
10.zip/unzip/tar命令
11.scp命令
12.bc命令
13.uname 指令
14.快捷鍵大全
15.關機/重啟/睡眠
16.shell(外殼程序)運行原理
1.echo、cat與printf
echo:打印字符串(會把test.c當作字符串),格式是 echo linux
cat:打印指定文件中內容,格式是 cat test.c
printf:不解釋了,格式是 printf "hello linux "
[root@VM-16-3-centos ~]# cat
aabb
aabb
bbcc
bbcc
ddee
ddee
^C
[root@VM-16-3-centos ~]#
[root@VM-16-3-centos ~]# cat /var/log/messages
[root@VM-16-3-centos ~]# more /var/log/messages
May 26 21:46:03 VM-16-3-centos kernel: Initializing cgroup subsys cpuset
May 26 21:46:03 VM-16-3-centos kernel: Initializing cgroup subsys cpu
May 26 21:46:03 VM-16-3-centos kernel: Initializing cgroup subsys cpuacct
May 26 21:46:03 VM-16-3-centos kernel: Linux version 3.10.0-1160.119.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Tue Jun 4 14:43:51 UTC 2024
May 26 21:46:03 VM-16-3-centos kernel: Command line: BOOT_IMAGE=/boot/vmlinuz-3.10.0-1160.119.1.el7.x86_64 root=UUID=4b499d76-769a-40a0-93dc-4a31a59add28 ro crashkernel=2G-8G:256M,8G-16G:512M,16G-:768M console=ttyS0,115200 consol
e=tty0 panic=5 net.ifnames=0 biosdevname=0 intel_idle.max_cstate=1 intel_pstate=disable processor.max_cstate=1 amd_iommu=on iommu=pt LANG=en_US.UTF-8
May 26 21:46:03 VM-16-3-centos kernel: e820: BIOS-provided physical RAM map:
May 26 21:46:03 VM-16-3-centos kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
May 26 21:46:03 VM-16-3-centos kernel: BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
May 26 21:46:03 VM-16-3-centos kernel: BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
May 26 21:46:03 VM-16-3-centos kernel: BIOS-e820: [mem 0x0000000000100000-0x000000007ffddfff] usable
May 26 21:46:03 VM-16-3-centos kernel: BIOS-e820: [mem 0x000000007ffde000-0x000000007fffffff] reserved
May 26 21:46:03 VM-16-3-centos kernel: BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
May 26 21:46:03 VM-16-3-centos kernel: BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
May 26 21:46:03 VM-16-3-centos kernel: NX (Execute Disable) protection: active
May 26 21:46:03 VM-16-3-centos kernel: SMBIOS 2.8 present.
May 26 21:46:03 VM-16-3-centos kernel: DMI: Tencent Cloud CVM, BIOS seabios-1.9.1-qemu-project.org 04/01/2014
May 26 21:46:03 VM-16-3-centos kernel: Hypervisor detected: KVM
May 26 21:46:03 VM-16-3-centos kernel: e820: last_pfn = 0x7ffde max_arch_pfn = 0x400000000
May 26 21:46:03 VM-16-3-centos kernel: PAT configuration [0-7]: WB WC UC- UC WB WP UC- UC
May 26 21:46:03 VM-16-3-centos kernel: found SMP MP-table at [mem 0x000f6bb0-0x000f6bbf] mapped at [ffffffffff200bb0]
May 26 21:46:03 VM-16-3-centos kernel: Using GB pages for direct mapping
May 26 21:46:03 VM-16-3-centos kernel: RAMDISK: [mem 0x35aa8000-0x36d4bfff]
May 26 21:46:03 VM-16-3-centos kernel: Early table checksum verification disabled
May 26 21:46:03 VM-16-3-centos kernel: ACPI: RSDP 00000000000f69d0 00014 (v00 BOCHS )
May 26 21:46:03 VM-16-3-centos kernel: ACPI: RSDT 000000007ffe27f5 00030 (v01 BOCHS BXPCRSDT 00000001 BXPC 00000001)
May 26 21:46:03 VM-16-3-centos kernel: ACPI: FACP 000000007ffe2639 00074 (v01 BOCHS BXPCFACP 00000001 BXPC 00000001)
May 26 21:46:03 VM-16-3-centos kernel: ACPI: DSDT 000000007ffe0040 025F9 (v01 BOCHS BXPCDSDT 00000001 BXPC 00000001)
May 26 21:46:03 VM-16-3-centos kernel: ACPI: FACS 000000007ffe0000 00040
May 26 21:46:03 VM-16-3-centos kernel: ACPI: APIC 000000007ffe26ad 00080 (v01 BOCHS BXPCAPIC 00000001 BXPC 00000001)
May 26 21:46:03 VM-16-3-centos kernel: ACPI: SRAT 000000007ffe272d 000C8 (v01 BOCHS BXPCSRAT 00000001 BXPC 00000001)
May 26 21:46:03 VM-16-3-centos kernel: SRAT: PXM 0 -> APIC 0x00 -> Node 0
May 26 21:46:03 VM-16-3-centos kernel: SRAT: PXM 0 -> APIC 0x01 -> Node 0
May 26 21:46:03 VM-16-3-centos kernel: SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]
May 26 21:46:03 VM-16-3-centos kernel: SRAT: Node 0 PXM 0 [mem 0x00100000-0x7fffffff]
May 26 21:46:03 VM-16-3-centos kernel: NUMA: Node 0 [mem 0x00000000-0x0009ffff] + [mem 0x00100000-0x7ffddfff] -> [mem 0x00000000-0x7ffddfff]
May 26 21:46:03 VM-16-3-centos kernel: NODE_DATA(0) allocated [mem 0x7ffb7000-0x7ffddfff]
May 26 21:46:03 VM-16-3-centos kernel: kvm-clock: cpu 0, msr 0:7ff66001, primary cpu clock
May 26 21:46:03 VM-16-3-centos kernel: kvm-clock: Using msrs 4b564d01 and 4b564d00
May 26 21:46:03 VM-16-3-centos kernel: kvm-clock: using sched offset of 8738820158 cycles
May 26 21:46:03 VM-16-3-centos kernel: Zone ranges:
May 26 21:46:03 VM-16-3-centos kernel: DMA [mem 0x00001000-0x00ffffff]
May 26 21:46:03 VM-16-3-centos kernel: DMA32 [mem 0x01000000-0xffffffff]
May 26 21:46:03 VM-16-3-centos kernel: Normal empty
May 26 21:46:03 VM-16-3-centos kernel: Movable zone start for each node
May 26 21:46:03 VM-16-3-centos kernel: Early memory node ranges
May 26 21:46:03 VM-16-3-centos kernel: node 0: [mem 0x00001000-0x0009efff]
--More--(0%)
cat默認是讀取輸入文件(鍵盤輸入文件)的內容,因此后續我們輸入什么,他就給我們輸出什么;cat -n 文件 是把文件內容分段加上行號,tac 命令是反向打印文件內容
為什么會用到cat、tac?
因為在linux中,因為我們有時候不想打開文件,只是想查看文件內容,所以用到了這兩個命令
cat /var/log/messages:查看該服務器的日志文件內容,日志里記錄了我們所有的操作
此時先打印的操作都是最老的,但如果我們想查看最新的操作(例如這臺服務器為什么掛掉了)呢?需要不斷刷屏直到最后幾條日志文件才能查看,這個時候我們就可以用到tac命令了
more:只打印一屏幕的內容,防止日志文件刷屏;此時more命令還未結束,如果此時我們想查看某天的(例如五月28)日志文件內容,我們可以通過 /May 28 這條指令來查看(如下所示),然后通過回車不斷往后查看;旁邊的百分比--More--(0%)指的是,當前日志文件查看到哪個位置;最后就是按q鍵,退出more命令
less:可以網上翻又可以往下翻,要好于more指令(只可以向下翻);通過?鍵往下翻,通過?鍵往上翻,退出按q鍵
head:只打印文件開頭的內容(日志文件頭是最老的操作!!!)
tail:只打印文件末尾的內容
head、tail后都可以加上 -num (num是一個數字),代表只查看num行內容
可以結合 > 操作符 與 head或tail,把一部分內容存到某個文件,然后對這個小文件進行操作
也可以結合head、tail,例如我要對日志文件的第500-510行文件進行查看;那么就先提取開頭的510行,然后對提取完的510行再提取末尾的10行,代碼如下所示
| 操作符:名為管道,在對某個文件進行完某一個操作以后,會把操作完的文件遞交到管道后所跟的操作,然后進行一步一步的操作,最后輸出最后所有操作結束以后的內容
wc(word count):統計總共有多少文字內容,和管道結合以后會有下面的效果;后面跟著的是 -l ,lines即文字內容行數
/May 28
...skipping
May 27 23:59:01 VM-16-3-centos systemd: Started Session 1978 of user root.
May 27 23:59:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:00:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:00:01 VM-16-3-centos systemd: Started Session 1980 of user root.
May 28 00:00:01 VM-16-3-centos systemd: Started Session 1981 of user root.
May 28 00:00:01 VM-16-3-centos systemd: Started Session 1979 of user root.
May 28 00:00:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:01:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:01:01 VM-16-3-centos systemd: Started Session 1983 of user root.
May 28 00:01:01 VM-16-3-centos systemd: Started Session 1982 of user root.
May 28 00:01:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:02:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:02:01 VM-16-3-centos systemd: Started Session 1984 of user root.
May 28 00:02:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:03:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:03:01 VM-16-3-centos systemd: Started Session 1985 of user root.
May 28 00:03:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:04:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:04:01 VM-16-3-centos systemd: Started Session 1986 of user root.
May 28 00:04:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:05:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:05:01 VM-16-3-centos systemd: Started Session 1987 of user root.
May 28 00:05:01 VM-16-3-centos systemd: Started Session 1988 of user root.
May 28 00:05:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:06:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:06:01 VM-16-3-centos systemd: Started Session 1989 of user root.
May 28 00:06:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:07:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:07:01 VM-16-3-centos systemd: Started Session 1990 of user root.
May 28 00:07:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:08:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:08:01 VM-16-3-centos systemd: Started Session 1991 of user root.
May 28 00:08:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:09:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:09:01 VM-16-3-centos systemd: Started Session 1992 of user root.
May 28 00:09:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:10:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:10:01 VM-16-3-centos systemd: Started Session 1993 of user root.
May 28 00:10:01 VM-16-3-centos systemd: Started Session 1994 of user root.
May 28 00:10:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:11:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:11:01 VM-16-3-centos systemd: Started Session 1995 of user root.
May 28 00:11:01 VM-16-3-centos systemd: Removed slice User Slice of root.
May 28 00:12:01 VM-16-3-centos systemd: Created slice User Slice of root.
May 28 00:12:01 VM-16-3-centos systemd: Started Session 1996 of user root.
May 28 00:12:01 VM-16-3-centos systemd: Removed slice User Slice of root.
[root@VM-16-3-centos ~]# head -510 /var/log/messages | tail -10
May 26 21:46:04 VM-16-3-centos kernel: [TTM] Initializing DMA pool allocator
May 26 21:46:04 VM-16-3-centos kernel: [drm] fb mappable at 0xFC000000
May 26 21:46:04 VM-16-3-centos kernel: [drm] vram aper at 0xFC000000
May 26 21:46:04 VM-16-3-centos kernel: [drm] size 33554432
May 26 21:46:04 VM-16-3-centos kernel: [drm] fb depth is 16
May 26 21:46:04 VM-16-3-centos kernel: [drm] pitch is 2048
May 26 21:46:04 VM-16-3-centos kernel: fbcon: cirrusdrmfb (fb0) is primary device
May 26 21:46:04 VM-16-3-centos kernel: Console: switching to colour frame buffer device 128x48
May 26 21:46:04 VM-16-3-centos kernel: cirrus 0000:00:02.0: fb0: cirrusdrmfb frame buffer device
May 26 21:46:04 VM-16-3-centos kernel: [drm] Initialized cirrus 1.0.0 20110418 for 0000:00:02.0 on minor 0[root@VM-16-3-centos ~]# head -510 /var/log/messages | tail -10 | wc -l
10
2. > 操作符 與 >> 操作符
[root@VM-16-3-centos ~]# echo hello linux > hello.txt
[root@VM-16-3-centos ~]# ll
total 20
drwxr-xr-x 4 root root 4096 May 28 16:14 a
drwxr-xr-x 3 root root 4096 May 28 15:50 a-backup
-rw-r--r-- 1 root root 0 May 28 13:45 code.c
-rw-r--r-- 1 root root 12 May 29 20:03 hello.txt
-rw-r--r-- 1 root root 0 May 27 21:39 test1.c
-rw-r--r-- 1 root root 59 May 28 14:03 test.c
-rw-r--r-- 1 root root 32 May 28 15:49 tt.txt
[root@VM-16-3-centos ~]# cat hello.txt
hello linux
> 叫做輸出重定項,是專門用來把文本內容,寫入到某個文件中;類似于輸入文件流 stdin 或者 c++中的 >>,此處需要知道的是:linux中一切都是文件,輸入輸出也都用輸入輸出流來完成的;echo默認向預置好的輸出文件輸入,預置好的那個文件會自動幫我們輸出
a.后面文件不存在,新建之(可以通過該操作符代替touch)
b.后面文件存在,先清空再輸入
c.文件清空如下示
[root@VM-16-3-centos ~]# >hello.txt
[root@VM-16-3-centos ~]# cat hello.txt
[root@VM-16-3-centos ~]#
[root@VM-16-3-centos ~]# cat hello.txt
[root@VM-16-3-centos ~]# echo hello > hello.txt
[root@VM-16-3-centos ~]# cat hello.txt
hello
[root@VM-16-3-centos ~]# echo hello >> hello.txt
[root@VM-16-3-centos ~]# cat hello.txt
hello
hello
>> 叫做追加重定項,當我們不想清空文件時,就可以通過該操作符
3. < 操作符
與 2 所提到的 > 功能相反,叫做輸入重定項
4.消息傳送 + linux文件深入
?可以看到如果兩個超級管理員連接了同一臺服務器,那么 ll /dev/pts/ 目錄就能看到第二名用戶的信息;該目錄保存的是各個用戶的顯示器輸出文件,0代表的是第一位連接上服務器的用戶的輸出文件,1代表第二位;如果我們現在想要從左邊那個超級用戶窗口發送信息到右邊那個用戶窗口,就可以通過輸出重定項來實現;c 開頭的文件叫做字符文件,說明這個文件內容與字符串相關
為什么 ll 命令輸入以后,都會在對應的設備終端上打印呢?
就是因為每次一個新用戶連接服務器以后,都會根據連接順序分配一個新的輸入文件給到新用戶?
我們甚至可以在 .c 文件中通過fopen打開別的用戶的輸出文件,然后給別人寫一段死循環程序(請勿這么做)
5.文件類型
- d 目錄文件
- c 字符文件,與鍵盤、顯示器和終端相關,輸入的數據具有順序性
- b 塊設備文件,與磁盤有關
- l 連接文件
- p 管道文件
- s socket文件
- - 普通文件
brw-rw---- 1 root disk 253, 0 May 26 21:46 /dev/vda
brw-rw---- 1 root disk 253, 1 May 26 21:46 /dev/vda1
每臺電腦都會有上面的那種文件,那些文件是磁盤文件;所以最好不要對這些文件進行修改,修改了之后可能windows系統要出大問題
linux中,系統不看文件后綴,工具(例如gcc)關心文件后綴;在windows中,我們想要修改一個 .c 文件的后綴,隨便修改以后如果我們把文件在vscode打開,不是報錯就是無法識別文件
6.mv命令
mv用來 更改普通文件名稱與所處位置 或者 刪除文件 或者 更改目錄所處位置,mv即move的縮寫
[root@VM-16-3-centos ~]# ll
total 36
drwxr-xr-x 4 root root 4096 May 28 16:14 a
drwxr-xr-x 3 root root 4096 May 28 15:50 a-backup
-rw-r--r-- 1 root root 69 May 29 21:36 code.x
-rw-r--r-- 1 root root 12 May 29 20:11 hello.txt
-rwxr-xr-x 1 root root 8360 May 29 21:37 mycmd
-rw-r--r-- 1 root root 0 May 27 21:39 test1.c
-rw-r--r-- 1 root root 59 May 28 14:03 test.c
-rw-r--r-- 1 root root 32 May 28 15:49 tt.txt
[root@VM-16-3-centos ~]# mv test.c ..
[root@VM-16-3-centos ~]# ll
total 32
drwxr-xr-x 4 root root 4096 May 28 16:14 a
drwxr-xr-x 3 root root 4096 May 28 15:50 a-backup
-rw-r--r-- 1 root root 69 May 29 21:36 code.x
-rw-r--r-- 1 root root 12 May 29 20:11 hello.txt
-rwxr-xr-x 1 root root 8360 May 29 21:37 mycmd
-rw-r--r-- 1 root root 0 May 27 21:39 test1.c
-rw-r--r-- 1 root root 32 May 28 15:49 tt.txt
[root@VM-16-3-centos ~]# cd ../
[root@VM-16-3-centos /]# ls
a.txt bin boot data dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys test.c tmp usr var
如上所示,通過move操作將test.c文件移動到了上層目錄,需要注意的是move還可移動目錄,所以move的移動操作就很像剪切
mv與alias之別
mv:更換普通文件文件名稱
alias:更換命令名稱
mv格式:mv code.c code.txt (如果重命名的是普通文件,當code.txt位置不是目錄,那么就是命名;并且move還能對目錄進行重命名,格式與普通文件一樣,同時對新名字沒有任何要求)
alias格式:alias zhangsan=pwd
7.時間相關指令
date 指令
指定格式顯?時間: date +%Y:%m:%d
?法: date [OPTION]... [+FORMAT]
在顯???,使?者可以設定欲顯?的格式,格式設定為?個加號后接數個標記,其中常?的標記 列表如下
- ?%X : 相當于 %H:%M:%S
- ?%d : ? (01..31) ? %m : ?份 (01..12)
- ?%Y : 完整年份 (0000..9999)
- ?%F : 相當于 %Y-%m-%d
- ?%H : ?時(00..23)
- ?%M : 分鐘(00..59)
- ?%S : 秒(00..61)
- 時間->時間戳:date?+%s(獲取時間戳到目前所經過的總秒數)
- 時間戳->時間:date -d@1508749502
- Unix時間戳(英?為Unix epoch, Unix time, POSIX time 或 Unix timestamp)是從1970年1?1 ?(UTC/GMT的午夜)開始所經過的秒數,不考慮閏秒
[root@VM-16-3-centos ~]# date -d@0
Thu Jan 1 08:00:00 CST 1970
注:中國處在東八區,所以時間戳從8:00:00開始算
cal命令可以?來顯?公歷(陽歷)?歷。公歷是現在國際通?的歷法,?稱格列歷,通稱陽歷。“陽 歷”?名“太陽歷”,系以地球繞?太陽?周為?年,為西?各國所通?,故?名“西歷”。
命令格式: cal 參數 [年份]
功能:?于查看?歷等時間信息,如只有?個參數,則表?年份(1-9999),如有兩個參數,則表??份 和年份
常?選項:
- -3 顯?系統前?個?,當前?,下?個?的?歷
- -j 顯?在當年中的第?天(?年?期按天算,從1?1號算起,默認顯?當前?在?年中的天數)
- -y 顯?當前年份的?歷
8.查找命令
which:只會去查找命令文件
whereis:以字符串為格式,去查找linux系統中存在該字符串的文件(非常不常用,linux系統指的是系統自帶的文件)
find:會查詢系統+用戶創建的內容,-name 是根據名字進行查找的命令行選項
[root@VM-16-3-centos ~]# whereis man
man: /usr/bin/man /usr/share/man /usr/share/man/man7/man.7.gz /usr/share/man/man1/man.1.gz /usr/share/man/man1p/man.1p.gz[root@VM-16-3-centos ~]# find ~ -name *.c
/root/test1.c
[root@VM-16-3-centos ~]# find -name *.c
./test1.c
9.grep命令
grep是根據給定的字符串,過濾整個文件的信息,找出有給定字符串的文件or目錄or文本輸出
如果想要查詢日志文件中最新的錯誤信息,那么就在后面再跟一個tail操作即可
grep還被用來查找某條字符串出現在某文本的第幾行,比如現在有個 .c 文件里面寫了int main,那么就可以通過該命令去找到,前面寫名第幾行需要加上 -n 命令行選項
grep還有一個 -v ,v 是reverse的縮寫,是grep命令的逆操作;還有 -i ,i 是ignore的縮寫,指忽略后面字符串的大小寫
10.zip/unzip/tar命令
打包和壓縮是什么?
打包是把各種各樣的文件,搞到一個文件夾中;此時的文件可能很大,傳輸比較慢,那么我們就可以壓縮這個文件夾,然后以壓縮包格式傳輸給其他主機
打包的意義:只需要傳輸一個文件,防止文件丟失
壓縮的意義:把打包后的大文件,進行存儲空間的壓縮;能節約磁盤空間的同時,網絡傳輸的速度也能夠加快
zip/unzip:
可能需要自己來安裝這個命令,安裝命令如下代碼所示
當我們要把 a 目錄打包,那么命令格式如下
zip -r a.zip a ( -r 一定要加,要不然無法把整個目錄+目錄中內容一起壓縮,只會將目錄壓縮)
當我們需要解壓,格式如下
unzip a.zip
可以通過 -d 命令行選項,解壓到指定目錄;例如我們想解壓到a-backup目錄,格式如下
unzip a.zip -d /a-backup
tar:
格式如下tar [-cxtzjvf] 自己取的名字 已存在的文件/目錄名 [-C /root]
- -c:建??個壓縮?件的參數指令(create的意思)
- -x:解開?個壓縮?件的參數指令!
- -t:查看tarfile??的?件!
- -z:是否同時具有gzip的屬性?亦即是否需要?gzip壓縮?
- -j:是否同時具有bzip2的屬性?亦即是否需要?bzip2壓縮?
- -v:壓縮的過程中顯??件!這個常?,但不建議?在背景執?過程!
- -f:使?檔名,請留意,在f之后要?即接檔名喔!不要再加參數!
- -C:解壓到指定?錄
注意事項:f 要緊跟著文檔名,創建是小寫c,指定目錄是大寫C,不管是壓縮還是解壓都需要聲明以哪種方式(gzip/bzip2)
gzip是一種常用的文件壓縮工具,主要用于單個文件的壓縮。它將文件壓縮為.gz格式,并且以較快的速度提供良好的壓縮比。
bzip2也是一種常見的壓縮工具,與gzip相比,它提供了更高的壓縮率,但壓縮和解壓縮的速度較慢。
yum install -y zip unzipyum install -y lrzsz
[root@linux ~]$ tar -cvf /tmp/etc.tar /etc<==僅打包,不壓縮!
[root@linux ~]$ tar -zcvf /tmp/etc.tar.gz /etc <==打包后,以gzip壓縮
[root@linux ~]$ tar -jcvf /tmp/etc.tar.bz2 /etc <==打包后,以bzip2壓縮
sz:
可能需要自己來安裝,安裝命令如上代碼所示
該安裝命令是用來把linux中的zip格式文件,發送到當前windows系統上
rz:
從windows系統上獲取壓縮包,直接輸入命令即可操作
具體用法如下圖所示
11.scp命令
scp命令叫做遠程拷貝命令,功能和cp一模一樣,只是scp是向別的云服務器下的主機or該云服務器下的其他機器
格式
scp 源文件 用戶名@指定服務器公網ip:/home/……(指定目錄)
12.bc命令
bc命令就相當于linux系統里的一個簡單計算器
13.uname 指令
linux的體系結構是什么?
體系結構指的是我們用的這臺云服務器的cpu設計,cpu的架構決定了我們很多編程寫法,例如我的windows體系架構就是i5-13500HX的架構
X86_64 就是 X64 ||? X86_32 就是 X86
uname -r :查看該linux操作系統的內核版本與體系架構
uname -a :詳細輸出所有信息,依次為內核名稱,主機名,內核版本號,內核版本,硬件名,處理器類型,硬件平臺類型,操作系統名稱
14.快捷鍵大全
1.按兩次tab鍵:給出有某個字符or字符串的全部命令(什么都不加,默認輸出全部命令)
2.ctrl+c:停止程序
3.ctrl+r:給出有某個字符or字符串的所有歷史指令
4.上下鍵:查看歷史語句(可以通過history命令一次性查看所有歷史命令,最多紀錄? ? ?1000-2000? ?條)
5.ctrl+d:斷開當前用戶與云服務器的連接
6.ctrl+shift+c:復制
7.ctrl+shift+v:黏貼
15.關機/重啟/睡眠
shutdown:關機
- -h:將系統的服務停掉后,?即關機。
- -r:在將系統的服務停掉之后就重新啟動
- -tsec:-t后?加秒數,亦即『過?秒后關機』的意思
halt:睡眠(掛起)
reboot:重啟
16.shell(外殼程序)運行原理
這樣的一條被稱為了命令行,是由外殼程序打印出來的;外殼程序會把用戶輸入的字符串,交給操作內核(這邊需要用到命令行解釋器),然后由操作內核進行運算,等運算結束以后就會返回給用戶;存在外殼程序的意義就在于:方便用戶操作、保護內核
?從技術?度,Shell的最簡單定義:命令?解釋器(commandInterpreter)
主要包含:
? 將使?者的命令翻譯給核?(kernel)處理。
? 同時,將核?的處理結果翻譯給使?者。
幫助理解:如果說你是?個悶騷且害羞的程序員,那shell就像媒婆,操作系統內核就是你們村頭漂亮的且有讓你?動的MM?花。你看上了?花,但是有不好意思直接表?,那就讓你你家?找媒婆幫你提親,所有的事情你都直接跟媒婆溝通,由媒婆(對應外殼程序統稱)轉達你的意思給?花,?我們找到媒婆姓王,所以我們叫它王婆,它對應我們常使?的bash(一個具體的外殼程序,bash是其中之一)。
外殼程序 -> 進程 -> 新命令到來 -> 創建子進程(外殼程序不能掛,子進程可以掛)
對?windowsGUI,我們操作windows不是直接操作windows內核,?是通過圖形接?,點擊,從 ?完成我們的操作(?如進?D盤的操作,我們通常是雙擊D盤盤符.或者運?起來?個應?程序)。
shell 對于Linux,有相同的作?,主要是對我們的指令進?解析,解析指令給Linux內核。反饋結果在 通過內核運?出結果,通過shell解析給??。