日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux 基础知识及命令总结

發布時間:2024/9/3 linux 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 基础知识及命令总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.mkdir?? 創建目錄 -p 創建多級目錄? mkdir -p /data/test

-m, --mode=模式 設置權限模式(類似chmod),而不是rwxrwxrwx 減umask

-p, --parents 需要時創建目標目錄的上層目錄,但即使這些目錄已存在也不當作錯誤處理

  • [root@wen data]# mkdir test/test{1..3} -p? #創建一個目錄再在下面創建幾個目錄

[root@wen data]# tree test

test

├── test1

├── test2

└── test3

2.ls??? list? 查看目錄文件? ls /etc/目錄

-l (long)長格式,-d 查看目錄

-i inode節點號 , -h 人類可讀

3.cd cd /etc? 切換目錄路徑

4.pwd?? 顯示當前所在目錄

5.touch 創建文件,不存在即創建,存在就改變訪問時間戳,atime

6.echo?? 打印輸出內容,配合 >(重定向,會清除之前內容),>>(在尾部追加內容) 可以為文件追加內容

[root@wen 926]# echo {1..9}

1 2 3 4 5 6 7 8 9

  • [root@wen data]# cat >fade.txt

fade walk

^C

[root@wen data]# cat fade.txt

fade walk

  • [root@wen data]# cat >>fade.txt<<efo? #efo 可以是任意字符

> i am studing linux

> efo

[root@wen data]# cat fade.txt

fade walk

i am studing linux

  • [root@wen data]# echo mygirl 1>walk.txt 2>&1? #正確,錯誤都輸入到walk.txt

[root@wen data]# cat walk.txt

mygirl

[root@wen data]# ech mygirl 1>walk.txt 2>&1?? #正確,錯誤都輸入到walk.txt,等同于 &>1

[root@wen data]# cat walk.txt

-bash: ech: command not found

  • [root@wen data]# echo? mygirl &>>walk.txt???? #追加

[root@wen data]# cat walk.txt

-bash: ech: command not found

mygirl

[root@wen data]# ech? mygirl &>>walk.txt

[root@wen data]# cat walk.txt

-bash: ech: command not found

mygirl

-bash: ech: command not found

  • [root@wen data]# ech? mygirl 1>>walk.txt 2>>walk.txt?? #重定向前面的數字要緊跟著

[root@wen data]# cat walk.txt

-bash: ech: command not found

mygirl

-bash: ech: command not found

-bash: ech: command not found

7.cat? 查看文件內容 cat fade.txt

-n 匹配排序,cat /rtc/log -n

[root@wen data]# cat walk.txt -n

???? 1????????-bash: ech: command not found

???? 2????????mygirl

???? 3????????-bash: ech: command not found

???? 4????????-bash: ech: command not found

8.vi windows記事本,簡單??? vim 復雜編輯器,功能復雜,高亮,自動縮進(寫shell/python腳本用)

9.xargs? 從標準輸入獲取內容創建和執行命令? -n 數字,分組

10.cp? copy? 拷貝文件或目錄,默認不能拷貝目錄,?? -r :遞歸,用于復制目錄

-a :相當于-pdr,? -p:連同檔案的屬性一起復制過去,而非使用默認屬性

  • [root@wen data]# touch test.txt

[root@wen data]# touch /data/926/test.txt

[root@wen data]# cp /data/test.txt /data/926/test.txt

cp:是否覆蓋"/data/926/test.txt"? y

[root@wen data]# \cp /data/test.txt /data/926/test.txt????????????? #\cp,不再提示覆蓋與否,…\rm ,\mv

[root@wen data]# /bin/cp /data/test.txt /data/926/test.txt????????? #不再提示覆蓋與否

11.rm? remove 刪除目錄和文件 -f(force)強制,-r 遞歸,用于刪除目錄?

rm -fr "文件名" 強制刪除目錄不提示,非常危險

強調:刪除命令要慎用,非常危險,刪除前一定要先備份一份

  • [root@wen data]# touch stu{0..6}

[root@wen data]# find /data -type f -name "stu*" |xargs

/data/stu1 /data/stu4 /data/stu6 /data/stu3 /data/stu2 /data/stu0 /data/stu5

[root@wen data]# find /data -type f -name "stu*" |xargs -n 1

/data/stu1

/data/stu4

/data/stu6

/data/stu3

/data/stu2

/data/stu0

/data/stu5

[root@wen data]# find /data -type f -name "stu*" |xargs -n 2? #分組

/data/stu1 /data/stu4

/data/stu6 /data/stu3

/data/stu2 /data/stu0

/data/stu5

  • [root@wen data]# find /data -type f -name "stu*" |xargs rm -f??? #find找到,管道xargs刪除
  • [root@wen data]# touch stu{0..6}

[root@wen data]# find /data -type f -name "stu*" -exec rm {} \;? #另一種刪除方法

[root@wen data]# ls

12.mv?? move 移動文件和目錄

14.find?? 查找? -type 文件類型(f(file),d(diretory),c(character),b(block),s(socket),l(link))

-name? "文件名",-mtime 時間,按修改時間查找,時間數字

+7 7天以前? 7 第7天? -7最近7天

15.*grep?? linux三劍客老三? 過濾需要的內容,-v 排除內容?

-C #除了顯示匹配行外,顯示該行前后的num行

-B #除了顯示匹配行外,顯示該行之前的num行

-A #除了顯示匹配行外,顯示該行之后的num行?????? 例子查看19-(5)

  • [root@wen data]# cat fade.txt

fade walk

i am studing linux

[root@wen data]# grep -v fade fade.txt

i am studing linux

[root@wen data]# grep -v f fade.txt

i am studing linux

[root@wen data]# grep -v i fade.txt

fade walk

[root@wen data]# grep fade fade.txt

fade walk

16.head??? 頭,頭部?? 讀取文件的前n行,默認前10行,-n 數字,習慣-5,忽略-n

17.tail?? 尾巴?????? 輸出文件的后n行,默認后10行,-n 數字,習慣-5,忽略-n

[root@wen data]# seq 20 > num.txt

[root@wen data]# head num.txt

1

2

3

4

5

6

7

8

9

10

[root@wen data]# tail num.txt

11

12

13

14

15

16

17

18

19

20

[root@wen data]# head -3 num.txt

1

2

3

[root@wen data]# tail -3 num.txt

18

19

20

18.alias?? 查看設置別名,unalias取消別名

  • [root@wen data]# alias rm='echo this command does not allow to use'

[root@wen data]# alias|grep rm

alias rm='echo this command does not allow to use'

[root@wen data]# rm

this command does not allow to use

定義別名永久生效:? /etc/profile? 全局生效?? ~/.bashrc? 當前用戶生效

分享鏈接 http://oldboy.blog.51cto.com/2561410/699046

19.seq?? 序列

[root@wen data]# seq -s '*' 10?? #以"*"為間隔符

1*2*3*4*5*6*7*8*9*10

[root@wen data]# seq 1 2 10????? #以1為起點,2為間隔,10為終點

1

3

5

7

9

[root@wen data]# seq 0 2 10

0

2

4

6

8

10

  • [root@wen data]# seq 100 >ett.txt???? #查看ett.txt內第20到25行的內容(常見考題)

1. [root@wen data]# head -25 ett.txt|tail -6

20

21

22

23

24

25

2. [root@wen data]# sed -n '20,25p' ett.txt? #更高效的方法

20

21

22

23

24

25

3. [root@wen data]# awk '19<NR && NR<26' ett.txt

20

21

22

23

24

25

4. [root@wen data]# awk '{if(NR >19 && NR< 26) printf $0 "\n"}' ett.txt

20

21

22

23

24

25

5. [root@wen data]# grep 22 -C 2 ett.txt? #除了顯示匹配行外,顯示該行前后的num行

20

21

22

23

24

6. [root@wen data]# grep 25 -B 5 ett.txt? #除了顯示匹配行外,顯示該行之前的num行

20

21

22

23

24

25

7. [root@wen data]# grep 20 -A 5 ett.txt? #除了顯示匹配行外,顯示該行之后的num行

20

21

22

23

24

25

20.sed??? linux三劍客老二,流編輯器,實現對文件的增刪改替換查? s,g常聯合使用,表示對當前進行全局匹配替換

參數 -n 取消默認輸出, -c 允許多項編輯, -I 修改文件內容

[root@wen data]# echo mygirl >>fade.txt

[root@wen data]# sed -i 's#mygirl#jujingyi#g' fade.txt

[root@wen data]# cat fade.txt

fade walk

i am studing linux

jujingyi

  • [root@wen data]# echo dream-girl{01..04} > /data/girl/del.sh

[root@wen data]# find /data -type f -name '*.sh' |xargs cat

dream-girl01 dream-girl02 dream-girl03 dream-girl04

[root@wen data]# find /data -type f -name '*.sh' |xargs sed 's#dream-girl*#jujingyi#g'

jujingyi01 jujingyi02 jujingyi03 jujingyi04

[root@wen data]# find /data -type f -name '*.sh' |xargs sed 's#.*#jujingyi#g'

jujingyi

[root@wen data]# find /data -type f -name '*.sh' |xargs sed -i 's#dream*#jujingyi#g'

[root@wen data]# find /data -type f -name '*.sh' |xargs cat

  • jujingyi-girl01 jujingyi-girl02 jujingyi-girl03 jujingyi-girl04

[root@wen data]# echo dream-girl{01..04} > /data/girl/del.sh

[root@wen data]# sed -i 's#dream-*#beautiful#g' `find /data -type f -name '*.sh'`? #替換方法二

[root@wen data]# find /data -type f -name '*.sh' |xargs cat

beautifulgirl01 beautifulgirl02 beautifulgirl03 beautifulgirl04

21.linux系統查看命令幫助的手段

a.man 命令名/配置文件 b.命令 --help (稍微簡單的幫助)? c.搜索引擎“linux 命令名”,info? d.help 命令名,特殊bash內置命令

22.常用快捷鍵

Ctrl +c 終止當前任務命令或程序

Ctrl +d退出當前用戶環境,相當于

Ctrl +l 清屏,相當于clear命令

23.查看系統64位,內核

[root@wen data]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[root@wen data]# uname -r

2.6.32-573.el6.x86_64

[root@wen data]# uname -m

x86_64

24.tree 查看目錄結構?? 沒有則安裝 yum -y install tree

tree -L 1 ,查看當前下一層目錄

25.linux 基礎知識

一,分區

一塊硬盤:主分區,擴展分區,邏輯分區

主分區+擴展分區的數量 <= 4,其中一個主分區可以用一個擴展分區,擴展分區最多只能有一個

擴展分區不能直接使用,還需要在上面創建邏輯分區,邏輯分區可有多個

主分區 + 擴展分區 編號只能1~4,邏輯分區的編號只能從5開始

1.常規分區:數據不是特別重要的業務(集群的某個節點)

/boot? 引導分區 200M

swap?? 交換分區? 內存的1.5倍,內存大于 8G,就給 8~16G

/????? 根分區,所有目錄頂點? 剩余所有空間

2.數據重要(數據庫,存儲服務區)

/boot? 引導分區 200M

swap?? 交換分區? 內存的1.5倍,內存大于 8G,就給 8~16G

/???? ?根分區,所有目錄頂點? 100~200G

/data? 所有,存放數據

3.特大網站,門戶(產品線特別多,需求)

/boot? 引導分區 200M

swap?? 交換分區? 內存的1.5倍,內存大于 8G,就給 8~16G

??? /????? 根分區,所有目錄頂點? 100~200G

剩余空間不分配,哪個部門領到了服務器,根據需求再進行分區

二,硬盤

  • 系統的第一塊IDE接口的硬盤稱為? /dev/had
  • 系統的第二塊IDE接口的硬盤稱為? /dev/hdb
  • 系統的第一塊SCSI接口的硬盤稱為? /dev/sda
  • 系統的第二塊SCSI接口的硬盤稱為? /dev/sdb

價格與性能:SSD>SAS>SATA

三,其他硬件

1.網站PC服務器

Dell(普遍)

1u = 4.45cm---->R420,410,620,630

2u--->R730,720,710

2.raid卡及其介紹

詳見linux筆記

26.stat? 查看目錄或文件的狀態?? display file or file system status

27.檢查網絡服務

ssh服務是否好的 檢測辦法:從哪個機器連就在那個機器上操作

telnet 192.168.59.131 22(服務器的IP和port)在windows上操作

不通的可能原因:

a.物理鏈路是否有問題,ping 192.168.59.131?

b.服務器端防火墻阻擋

[root@wen data]# /etc/init.d/iptables stop

iptables:將鏈設置為政策 ACCEPT:filter??????????????????? [確定]

iptables:清除防火墻規則:???????????????????????????????? [確定]

iptables:正在卸載模塊:??????? ???????????????????????????[確定]

c.端口沒有開放,服務器沒有監聽你連接的端口

[root@wen data]# netstat -lntup |grep 22? #以ssh服務22端口為例

tcp??????? 0????? 0 0.0.0.0:22????????????????? 0.0.0.0:*?????????????????? LISTEN????? 1503/sshd??????????

tcp??????? 0????? 0 :::22?????????? ????????????:::*??????????????????????? LISTEN????? 1503/sshd??????????

[root@wen data]# netstat -lntup |grep sshd

tcp??????? 0????? 0 0.0.0.0:22????????????????? 0.0.0.0:*?????????????????? LISTEN????? 1503/sshd??????????

tcp??????? 0????? 0 :::22????? ?????????????????:::*??????????????????????? LISTEN????? 1503/sshd??????????

[root@wen data]# /etc/init.d/sshd restart??? #重啟ssh服務

  • 網卡配置???? 剛安裝的linux 網絡服務默認是關閉的,需要手動調整

?#更改配置文件將ONBOOT=no改成yes

[root@wen data]# sed -i 's#ONBOOT=no#ONBOOT=yes#g' /etc/sysconfig/network-scripts/ifcfg-eth0

[root@wen data]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

TYPE=Ethernet

ONBOOT=yes

[root@wen data]# service network restart?? #重啟網絡服務生效

  • 小節:linux客戶端DNS可以在網卡配置文件里設置(ifcfg-eth0)

linux客戶端DNS也可以在/etc/resolv.conf里設置

網卡里的設置DNS優先于/etc/resolv.conf,如果重啟網絡網卡的DNS會覆蓋/etc/resolv.conf的設置

  • [root@wen ~]# cat /etc/resolv.conf

; generated by /sbin/dhclient-script

search localdomain

nameserver 192.168.59.2????????? #DNS

[root@wen ~]# /etc/init.d/network restart? ??#重啟網卡

[root@wen ~]# setup "network configuration" "DNS configuration"? 就是修改/etc/resolv.conf

28.rz,上傳 sz,下載命令 可執行 yum install lrzsz -y yum groupinstall 或 "Dial-up Networking Soupport" -y 命令來安裝

29.su? 切換用戶? su 和 su -的區別

30.linux 命令提示符由PS1 環境變量控制

[root@wen data]# set|grep PS1

PS1='[\u@\h \W]\$ '

[root@wen data]# PS1='[\u@\h \W\t]\$ '?? #可以通過全局變量配置/etc/profile,使其永久生效

[root@wen data01:35:17]#??????????????? #提示符添加顯示時間

31.克隆機?? 1).編輯eth0的配置文件:

[root@wen data01:4]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

刪除 HWADDR=00:0c:29:e9:95:dd 和 UUID

???? ?2).如果有必要再清空如下文件:

?> /etc/udev/rules.d/70-persistent-net.rules

3).最后reboot

總結

以上是生活随笔為你收集整理的linux 基础知识及命令总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。