溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Linux的簡(jiǎn)單介紹和基礎(chǔ)命令

發(fā)布時(shí)間:2020-07-11 07:25:01 來(lái)源:網(wǎng)絡(luò) 閱讀:230 作者:wx5d8a05337d6b9 欄目:云計(jì)算

一、Linux簡(jiǎn)要介紹

  1. Linux命令基礎(chǔ)
  2. Linux命令幫助
  3. 目錄與文件基本操作

Linux家族

  1. Redhat 紅帽 三個(gè)認(rèn)證 (開(kāi)源但是不免費(fèi))---》社區(qū)(系統(tǒng)開(kāi)發(fā)者)---》Centos(服務(wù)器端)
  2. Ubuntu 最好的客戶(hù)端系統(tǒng),開(kāi)源純免費(fèi)(軟件開(kāi)發(fā)人群)
  3. Debian ---》kali Linux(專(zhuān)用工具資源占用很少) 樹(shù)莓派
  4. suse Linux---》ISP(電信,移動(dòng),聯(lián)通) 定制版

shell——Linux系統(tǒng)的一種特殊程序——“翻譯官”

用戶(hù)登錄Linux系統(tǒng)時(shí)就自動(dòng)加載一個(gè)shell程序,Bash是Linux系統(tǒng)中默認(rèn)使用的shell程序

Linux的內(nèi)核是由C語(yǔ)言開(kāi)發(fā)出來(lái)的(面向過(guò)程的語(yǔ)言),應(yīng)用程序是用c++開(kāi)發(fā)

編譯器—— gcc gcc-c++ jdk(Java的編譯器)Python的編譯器就是Python2/3

源碼文件———》(編譯器)——》執(zhí)行文件

Linux命令的分類(lèi)

  1. 內(nèi)部命令
  2. 外部命令
通用的命令行使用格式:

命令字 [選項(xiàng)] [參數(shù)] (對(duì)應(yīng)于操作、功能、操作對(duì)象)

  1. -單個(gè)字符的組合
  2. -- 單詞

對(duì)root@localhost ~]# 的介紹

  1. root ——當(dāng)前用戶(hù)
  2. @ ——分隔符
  3. localhost ——主機(jī)名字
  4. ~ ——當(dāng)前目錄位置
  5. #——管理員
  6. $ ——普通用戶(hù)

路徑簡(jiǎn)介

絕對(duì)路徑:例如——/etc/sysconfig/network-scripts/

相對(duì)路徑(以當(dāng)前所在位置的路徑):例如——sysconfig/

家目錄:管理員(/root) 普通用戶(hù)(/home)

根目錄: /

二、Linux命令集(結(jié)合實(shí)例)

cd:切換工作目錄

pwd:查看當(dāng)前所在的絕對(duì)目錄路徑

[root@lokott ~]# cd /etc/sysconfig/network-scripts/  //進(jìn)入絕對(duì)路徑下的文件夾
[root@lokott network-scripts]# pwd      //顯示當(dāng)前所在的目錄的絕對(duì)路徑
/etc/sysconfig/network-scripts
[root@lokott network-scripts]# cd - //返回上次進(jìn)入的目錄命令,即cd /etc/sysconfig/network-scripts/
/root
[root@lokott ~]# cd -
/etc/sysconfig/network-scripts
[root@lokott network-scripts]# cd ..    //返回上層目錄 
[root@lokott sysconfig]# cd ../../    //返回上兩層目錄 
[root@lokott /]# 

ls:顯示當(dāng)前目錄的內(nèi)容

  1. -l 顯示文件詳細(xì)信息
  2. -a 查看隱藏文件
  3. -A 查看除了. .. 的隱藏文件
  4. -d 顯示本目錄的信息
  5. -h 友好形式顯示帶有單位的信息
  6. -R 遞歸顯示
  7. -- color 以顏色區(qū)分文件類(lèi)型
    1. 黑色(數(shù)據(jù)文件)
    2. 藍(lán)色(目錄)
    3. 紅色(壓縮包)
    4. 綠色(執(zhí)行文件/命令文件/腳本)
    5. 天藍(lán)色(鏈接文件)
    6. 黃的(設(shè)備文件/磁盤(pán)文件)
[root@lokott ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  note  shell  公共  模板  視頻  圖片  文檔  下載  音樂(lè)  桌面
[root@lokott ~]# cd shell/
[root@lokott shell]# ls 
1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello
[root@lokott shell]# ls -a
.  ..  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello
[root@lokott shell]# ls -A
1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello
[root@lokott shell]# ls -l
總用量 24
-rwxr-xr-x. 1 root root 111 10月 25 19:10 1.sh
-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh
-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh
-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh
-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh
-rwxr-xr-x. 1 root root  26 10月 25 19:37 6.sh
drwxr-xr-x. 2 root root  18 10月 30 13:53 hello
[root@lokott shell]# ls -R
.:
1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello

./hello:
0.sh
[root@lokott shell]# ls -d
.
[root@lokott shell]# ls -ah
.  ..  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello

[root@lokott shell]# ls -lR
.:
總用量 24
-rwxr-xr-x. 1 root root 111 10月 25 19:10 1.sh
-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh
-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh
-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh
-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh
-rwxr-xr-x. 1 root root  26 10月 25 19:37 6.sh
drwxr-xr-x. 2 root root  18 10月 30 13:53 hello

./hello:
總用量 0
-rwxrwxrwx. 1 root root 0 10月 30 13:53 0.sh
[root@lokott shell]# 

alias:給命令取一個(gè)別名

du:統(tǒng)計(jì)目錄及文件空間占用情況

  1. -a
  2. -h 友好顯示
  3. -s

which: 查找命令存放目錄

  1. 搜索范圍由環(huán)境變量PATH決定

mkdir:創(chuàng)建目錄

  1. -p遞歸嵌套創(chuàng)建

touch:創(chuàng)建文件

[root@lokott shell]# alias c='clear'   //clear是表示清屏相當(dāng)于Ctrl+l的操作
[root@lokott shell]# which c   
alias c='clear'
    /usr/bin/clear
[root@lokott shell]# which clear
/usr/bin/clear
[root@lokott shell]# mkdir linux
[root@lokott shell]# ls
1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello  linux
[root@lokott shell]# touch 0.sh
[root@lokott shell]# ls
0.sh  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello  linux
[root@lokott shell]# du -ah
4.0K    ./1.sh
4.0K    ./2.sh
4.0K    ./3.sh
4.0K    ./4.sh
4.0K    ./5.sh
4.0K    ./6.sh
0   ./hello/0.sh
0   ./hello
0   ./linux
0   ./0.sh
24K .
[root@lokott shell]# du -sh
24K .
[root@lokott shell]# du -as             //不可以設(shè)置選項(xiàng)為-as(h)
du: 不能既顯示總用量,同時(shí)又顯示每個(gè)項(xiàng)目
Try 'du --help' for more information.
[root@lokott shell]# 
[root@lokott shell]# mkdir -p  /2019/2018/2017   //連續(xù)創(chuàng)建文件夾
[root@lokott shell]# cd /2019/2018/2017/
[root@lokott 2017]# touch {1..10}.txt  //..表示創(chuàng)建連續(xù)10個(gè)名為1-10的txt文件
[root@lokott 2017]# ls
10.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt

下面的操作過(guò)程中會(huì)出現(xiàn)文件節(jié)點(diǎn)(inode值):文件在磁盤(pán)中存儲(chǔ)的標(biāo)識(shí)序列
ln:創(chuàng)建鏈接文件(類(lèi)似于Windows系統(tǒng)的快捷方式)

  1. 軟鏈接:相當(dāng)于快捷方式 -s
  2. 硬鏈接:給文件取別名(無(wú)法創(chuàng)建硬鏈接文件夾)
[root@lokott shell]# ln -s 1.sh 8.sh
[root@lokott shell]# ln 1.sh 10.sh
[root@lokott shell]# ls -l
總用量 28
-rwxrwxrwx. 1 root root   0 10月 30 13:59 0.sh
-rwxr-xr-x. 2 root root 111 10月 25 19:10 10.sh  //硬鏈接
-rwxr-xr-x. 2 root root 111 10月 25 19:10 1.sh
-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh
-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh
-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh
-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh
-rwxr-xr-x. 1 root root  26 10月 25 19:37 6.sh
lrwxrwxrwx. 1 root root   4 10月 30 14:07 8.sh -> 1.sh  //軟鏈接
drwxr-xr-x. 2 root root  18 10月 30 13:53 hello
drwxr-xr-x. 2 root root   6 10月 30 13:59 linux
[root@lokott shell]# ls -ih   //顯示文件節(jié)點(diǎn)值的大小
19397655 0.sh  20564913 10.sh  20564913 1.sh  20564915 2.sh  20564917 3.sh  20564916 4.sh  20564918 5.sh  20564919 6.sh  19134334 8.sh  20565286 hello  35183604 linux
//上面文件左邊的就是該文件的文件節(jié)點(diǎn)(inode值)軟鏈接與源文件的文件節(jié)點(diǎn)是非一致的,而硬鏈接的文件節(jié)點(diǎn)與源文件是一致的 

cp :復(fù)制文件或目錄 源|目標(biāo)

  1. -f 不詢(xún)問(wèn)
  2. -i 詢(xún)問(wèn)是否覆蓋原有
  3. -p 保持源文件的用戶(hù)權(quán)限不變,權(quán)限高用戶(hù)使用
  4. -r 遞歸復(fù)制

rm:刪除

  1. -i:默認(rèn)提醒
  2. -rf :強(qiáng)制遞歸刪除

mv:移動(dòng)文件或目錄

[root@lokott shell]# cd hello/
[root@lokott hello]# ls
0.sh
[root@lokott hello]# cp ../5.sh .
[root@lokott hello]# ls
0.sh  5.sh
[root@lokott hello]# cp -i ../5.sh .
cp:是否覆蓋"./5.sh"? yes
[root@lokott hello]# cp -f ../5.sh .    //猜測(cè)被alias了
cp:是否覆蓋"./5.sh"? y
[root@lokott hello]# 
[root@lokott hello]# which cp     //查看cp命令果然是被alias更改了
alias cp='cp -i'
    /usr/bin/cp
[root@lokott hello]# cp -r ../linux/ .   //遞歸復(fù)制上層路徑linux文件夾的所有內(nèi)容到當(dāng)前路徑(目前無(wú)內(nèi)容)
[root@lokott hello]# ls
0.sh  5.sh  linux
[root@lokott hello]# cd linux/
[root@lokott linux]# ls
[root@lokott linux]# mkdir 2020         //創(chuàng)建文件夾
[root@lokott linux]# ls
2020
[root@lokott linux]# cd 2020/
[root@lokott 2020]# touch 2.txt         //創(chuàng)建文件
[root@lokott 2020]# cd ../../
[root@lokott hello]# ls
0.sh  5.sh  linux
[root@lokott hello]# mv linux/ ../          //移動(dòng)文件夾
mv:是否覆蓋"../linux"? y
[root@lokott hello]# cd ..
[root@lokott shell]# ls
0.sh  10.sh  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  8.sh  hello  linux
[root@lokott shell]# ls -l linux/
總用量 0
drwxr-xr-x. 2 root root 19 10月 30 14:15 2020
[root@lokott shell]# cp -r linux/  hello/   //遞歸復(fù)制linux文件夾的所有內(nèi)容到hello文件夾中
[root@lokott shell]# cd hello/
[root@lokott hello]# ls
0.sh  5.sh  linux
[root@lokott hello]# ls -l linux/
總用量 0
drwxr-xr-x. 2 root root 19 10月 30 14:16 2020
[root@lokott hello]# ls -lR linux/          //遞歸查看拷貝過(guò)來(lái)的文件夾的信息
linux/:
總用量 0
drwxr-xr-x. 2 root root 19 10月 30 14:16 2020

linux/2020:
總用量 0
-rw-r--r--. 1 root root 0 10月 30 14:16 2.txt

通配符

  1. ?表示一個(gè)
  2. *表示多個(gè)

find:查找文件或目錄

find 【查找范圍】【選項(xiàng)】[表達(dá)式]

  1. -name:根據(jù)目標(biāo)名字查找
  2. -type:根據(jù)文件類(lèi)型查找
  3. -size:根據(jù)大小查找
  4. -user:根據(jù)文件的用戶(hù)所有者查找
[root@lokott hello]# find . -name "*.sh"  //*號(hào)表示通配符
./0.sh
./5.sh
[root@lokott hello]# find . -type f
./0.sh
./5.sh
./linux/2020/2.txt
[root@lokott hello]# find . -size -10k
.
./0.sh
./5.sh
./linux
./linux/2020
./linux/2020/2.txt
./ifcfg-ens33
[root@lokott hello]# find . -size -10k | du -ah
0   ./0.sh
4.0K    ./5.sh
0   ./linux/2020/2.txt
0   ./linux/2020
0   ./linux
4.0K    ./ifcfg-ens33
8.0K    .
centos7系統(tǒng)啟動(dòng)的命令清單
1. init 0 關(guān)機(jī)
2. init 1 單用戶(hù)模式(系統(tǒng)維護(hù),破解密碼)
3. init 2 多用戶(hù)模式無(wú)網(wǎng)絡(luò)
4. init 3 多用戶(hù)模式有網(wǎng)絡(luò)  *
5. init 4 保留
6. init 5多用戶(hù)模式圖形化界面有網(wǎng)絡(luò)
7. init 6 重啟 (reboot)

三、Linux的目錄結(jié)構(gòu)

樹(shù)形目錄結(jié)構(gòu)

/etc 管理員的家目錄

/home 普通用戶(hù)家目錄

/bin 所有用戶(hù)的命令文件目錄

/sbin 管理員命令文件目錄

/boot 啟動(dòng)分區(qū)(grub啟動(dòng)菜單,壓縮內(nèi)核等)

/usr 應(yīng)用程序目錄

/etc 配置文件目錄

/var 可變長(zhǎng)文件目錄(日志)

/dev  設(shè)備文件目錄(磁盤(pán),光驅(qū))

/tmp 臨時(shí)文件

/proc 硬件信息(CPU 內(nèi)存)

/lib 服務(wù)管理文件(systemctl)

查看文件內(nèi)容命令

cat [] 文件名 ... :查看文件內(nèi)容

more [] 文件名 .. :全屏方式分頁(yè)顯示文件內(nèi)容

less [] 文件名 ... :more命令的擴(kuò)展 END 可以查找 (man less進(jìn)行查看,這邊不是非常方便演示效果)

head 看文件開(kāi)頭一部分內(nèi)容(默認(rèn)為10行)

tail:看文件尾部的內(nèi)容(默認(rèn)10行)

[root@lokott hello]# cat ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="0d6ffef5-693f-4d48-88b5-d2e1a66cf9c4"
DEVICE="ens33"
ONBOOT="yes"
[root@lokott hello]# more ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="0d6ffef5-693f-4d48-88b5-d2e1a66cf9c4"
DEVICE="ens33"
ONBOOT="yes"
root@lokott hello]# head ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
[root@lokott hello]# tail ifcfg-ens33 
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="0d6ffef5-693f-4d48-88b5-d2e1a66cf9c4"
DEVICE="ens33"
ONBOOT="yes" 

統(tǒng)計(jì)文件內(nèi)容

wc(默認(rèn)全部統(tǒng)計(jì))

  1. -l :統(tǒng)計(jì)行數(shù)
  2. -w:統(tǒng)計(jì)單詞統(tǒng)計(jì)數(shù)
  3. -c:統(tǒng)計(jì)字節(jié)數(shù)
[root@lokott hello]# cat 5.sh 
#!/bin/bash
read -p "please input a ip address!" ip
ping -c1 $ip &>/dev/null
if [ $? -eq 0 ]
then 
    echo "$ip is up."
else 
    echo "$ip is down"
fi
[root@lokott hello]# wc -l 5.sh 
9 5.sh
[root@lokott hello]# wc -w 5.sh 
30 5.sh
[root@lokott hello]# wc -c 5.sh 
147 5.sh
[root@lokott hello]# 

檢索和過(guò)濾文件內(nèi)容

grep命令:在文件中查找不顯示包含指定字符串的行

  • grep [options] PATTERN [FILE...]
  • grep [options] [-e PATTERN | -f FILE] [FILE...]
  1. -i :忽略大小寫(xiě)
  2. -v:反轉(zhuǎn)查找,輸出與查找條件不相符的行
[root@lokott hello]# grep -i up 5.sh 
    echo "$ip is up."
[root@lokott hello]# grep -v 'bash$' /etc/passwd 
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
libstoragemgmt:x:998:996:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
colord:x:997:995:User for colord:/var/lib/colord:/sbin/nologin
saslauth:x:996:76:Saslauthd user:/run/saslauthd:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
chrony:x:995:991::/var/lib/chrony:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
geoclue:x:994:989:User for geoclue:/var/lib/geoclue:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
setroubleshoot:x:993:988::/var/lib/setroubleshoot:/sbin/nologin
sssd:x:992:987:User for sssd:/:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:991:986::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
root@lokott hello]# grep -v 'bash$' /etc/passwd | wc -l  //將結(jié)果寫(xiě)入管道后用wc命令顯示結(jié)果數(shù)量
40
[root@lokott hello]# 

Ctrl + r 可以進(jìn)行命令的搜索

[root@lokott hello]# vim ifcfg-ens33 用快捷鍵!進(jìn)入下面的模式輸入之前敲擊過(guò)的命令會(huì)自動(dòng)查找
(reverse-i-search)`v': vim ifcfg-ens33

壓縮命令

gzip命令和bzip2命令:制作壓縮文件、解壓縮文件

  1. -9表示的是高壓縮比
  2. -d進(jìn)行解壓縮
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  linux
[root@lokott hello]# gzip -9 0.sh 5.sh 
[root@lokott hello]# ls
0.sh.gz  5.sh.gz  ifcfg-ens33  linux
[root@lokott hello]# gzip -d 0.sh.gz 
[root@lokott hello]# gzip -d 5.sh.gz 
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  linux
[root@lokott hello]# bzip2 -9 0.sh 5.sh 
[root@lokott hello]# bzip2 -d 0.sh.bz2 
[root@lokott hello]# bzip2 -d 5.sh.bz2 
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  linux
[root@lokott hello]# 

tar命令:制作歸檔文件、釋放歸檔文件

  1. -c:創(chuàng)建文件包
  2. -x:解壓文件包
  3. -v:顯示詳細(xì)過(guò)程
  4. -f: 執(zhí)行
  5. -p:保留原有權(quán)限
  6. -t:查看壓縮包的內(nèi)容
  7. -C:解壓到某個(gè)地方去
  8. -z:gz格式
  9. -j:bz2格式
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  linux
[root@lokott hello]# tar czvf if.tar.gz ifcfg-ens33 
ifcfg-ens33
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  if.tar.gz  linux
[root@lokott hello]# tar xzvf if.tar.gz -C ../
ifcfg-ens33
[root@lokott hello]# cd ..
[root@lokott shell]# ls
0.sh  10.sh  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  8.sh  hello  ifcfg-ens33  linux
[root@lokott shell]# 
//如果是bz2格式就將文件格式的后綴名更換后用j替換z的命令

四、文本編輯器vi/vim(對(duì)vim編輯器的熟練操作可以提高工作效率)

作用

  1. 創(chuàng)建或修改文本文件
  2. 維護(hù)Linux系統(tǒng)中的各種配置文件

命令模式、輸入模式、末行模式(底線(xiàn)命令模式)轉(zhuǎn)換關(guān)系和操作

Linux的簡(jiǎn)單介紹和基礎(chǔ)命令

vim編輯器的相關(guān)操作命令

行號(hào)設(shè)置操作

  1. :set nu
  2. :set nu!和:set nonu 取消行號(hào) 注意?。?!記住切換為末行模式(底線(xiàn)命令模式)

定位行(命令模式下)

  1. gg:定位到開(kāi)頭
  2. G:定位到結(jié)尾
  3. 3G:3表示行號(hào),定位到第三行

復(fù)制粘貼刪除

  1. x:刪除光標(biāo)處的單個(gè)字符
  2. dd :刪除當(dāng)前光標(biāo)所在行
  3. dw:刪除光標(biāo)所在位置的一個(gè)單詞
  4. #dd :刪除從光標(biāo)所在行開(kāi)始的#行內(nèi)容
  5. ddp:上下行調(diào)換位置
  6. yy:復(fù)制改行到剪切板
  7. nyy:復(fù)制n行到剪切板
  8. p:粘貼

vim編輯器中的其他操作

shift+r 替換 在光標(biāo)處進(jìn)行替換

PG UP 向上翻頁(yè)

PG DN 向下翻頁(yè)

:e ~/install.log 打開(kāi)新的文件進(jìn)行編輯(末行模式下)

:r file——在編輯的數(shù)據(jù)中,讀入另一個(gè)檔案的數(shù)據(jù)。亦即將 『filename』 這個(gè)檔案內(nèi)容加到游標(biāo)所在行后面(末行模式下)

:w /opt/test.txt 將該文件寫(xiě)入到opt下并且重新命名為test.txt文件但是不保持與源文件相同權(quán)限

:n1,n2s/word1/word2/g 在n1到n2行之間將所有的word1換為word2

:%s/word1/word2/g 將所有的word1換為word2

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI