Linux中基本命令(續)

2021-09-13 01:26:56 字數 3275 閱讀 6697

1.軟鏈結 (可以跨分割槽,但原始檔不可刪除)

[root@gao test]# ln -s /test/haha.txt /tmp/hi.txt      //建立檔案軟鏈結

[root@gao test]# ln -s /test /tmp //建立 /test 和 /tmp 目錄的軟連線

[root@gao test]# rm /test/haha.txt;cat /tmp/hi.txt

rm:是否刪除普通空檔案 "/test/haha.txt"?y

cat: /tmp/hi.txt: 是乙個目錄 //刪除原始檔後,鏈結無法使用

2.硬鏈結 (不可以跨分割槽,但可以將原始檔刪除)

[root@gao test]# ln /test/hello.txt /test/hi.txt 

ln: 無法建立硬鏈結"/test/hi.txt": 檔案已存在

[root@gao test]# ln /test/hello.txt /test/haha.txt

[root@gao test]# rm /test/hello.txt 

rm:是否刪除普通空檔案 "/test/hello.txt"?y

[root@gao test]# ls

haha.txt hi.txt //刪除原始檔後,鏈結檔案仍可以正常使用

1.gzip

格式:gzip [選項]…[檔名稱]…

[root@gao test]# gzip haha.txt 

[root@gao test]# ls

\haha.txt.gz hi.txt //檔案壓縮後名為haha.txt.gz

-d //直接解壓

[root@gao test]# gzip -d haha.txt.gz 

[root@gao test]# ls

haha.txt hi.txt //解壓gz檔案

-c //保留原始檔

[root@gao test]# gzip -c like > like.gz     //保留原始檔壓縮

gzip: like is a directory -- ignored // like是乙個目錄 --忽略

[root@gao test]# ls

haha.txt hi.txt like like.gz

–r //遞迴壓縮指定目錄

[root@gao test]# gzip -r ike
–n //代表級別數

[root@gao test]# gzip -1 haha.txt                                   

[root@gao test]# ls //指定壓縮的級別,-1是最快(壓縮效率低)-9最慢(壓縮效率高)

haha.txt.gz hi.txt like like.gz 預設壓縮級別-6

2.bzip2

[root@gao test]# bzip2 haha.txt           

[root@gao test]# ls

haha.txt.bz2 hi.txt //檔案壓縮後名為haha.txt.bz2(壓縮率高,但是速度比gzip差),預設壓縮級別-9

–d//解壓檔案

[root@gao test]# bzip2 -d haha.txt.bz2 

[root@gao test]# ls

haha.txt hi.txt

–k //保留原始檔壓縮

[root@gao test]# bzip2 -k haha.txt

[root@gao test]# ls

haha.txt haha.txt.bz2 hi.txt

注意gzip與bzip2 工具不可以直接對目錄做打包操作

3.tar 打包與解包檔案

格式:tar 模式 [選項][路徑]…

模式:-c 建立打包檔案

- - delete 從檔案中刪除檔案

- r 追加檔案至打包文件

- t 列出打包文件的內容

- x 釋放打包檔案

選項:-c 指定解壓路徑

-f 指定打包後的檔名稱

-j 打包後通過bzip2格式壓縮

–remove-files 打包後刪除原始檔

-z 打包後通過gzip格式壓縮

[root@gao test]# tar -cf etc.tar /etc/            //將/etc/目錄打包儲存為etc.tar

[root@gao test]# tar -czf haha.txt.bz2 /test //將/test目錄打包並壓縮為haha.txt.bz2

[root@gao test]# tar --delete etc/hosts -f etc.tar //從打包檔案中刪除檔案hosts

[root@gao test]# tar -xzf haha.txt.bz2 -c /tmp //指定解壓路徑為/tmp

[root@gao test]# tar -czf haha.txt.bz2 /var/log/messages --remove-files //打包壓縮後刪除原始檔

1.tab 自動補齊命令或路徑

2.history 顯示所有命令記錄

3.快捷鍵ctrl+l或輸入clear清屏

4.輸入which find 返回find命令的實際儲存位置/bin/find

1.輸入man ls讀取man手冊

2.info ls檢視lnfo資訊

3.ls - -hepl

linux中的基本命令

pwd 顯示當前目錄 ls 顯示當前目錄內容 cd 目錄切換 rm rf 路徑 刪除資料夾 rm f file 刪除檔案 ps ef grep smart 檢視程序 kill 9 程序id號 殺死程序 chmod 777 test.sh 賦予檔案許可權 4 r 2 w 1 x vim 可執行檔案 編...

linux基礎 基本命令(中)

定時任務 unameuname rcat proc cpuinfocat proc meminfodatecal 年份date s 2020 8 26 date s 11 40 30df lhdu sh 目錄fsck 磁碟mountmount 磁碟umount 磁碟free mtoprpm qa g...

linux基本命令

linux常用命令 基礎 eg man ls 就可以檢視ls相關的用法 注 按q鍵或者ctrl c退出,在linux下可以使用ctrl c終止當前程式執行。2.ls 檢視目錄或者檔案的屬 列舉出任一目錄下面的檔案 eg ls usr man ls l a.d表示目錄 directory 如果是乙個 ...