linux 基础命令总结
1.mkdir 創(chuàng)建目錄 -p 創(chuàng)建多級目錄 mkdir -p /data/test -m, --mode=模式 設置權(quán)限模式(類似chmod),而不是rwxrwxrwx 減umask -p, --parents 需要時創(chuàng)建目標目錄的上層目錄,但即使這些目錄已存在也不當作錯誤處理 ○ [root@wen data]# mkdir test/test{1..3} -p #創(chuàng)建一個目錄再在下面創(chuàng)建幾個目錄 [root@wen data]# tree test test ├── test1 ├── test2 └── test3
2.ls list 查看目錄文件 ls /etc/目錄 -l (long)長格式,-d 查看目錄 -i inode節(jié)點號 , -h 人類可讀
3.cd cd /etc 切換目錄路徑
4.pwd 顯示當前所在目錄
5.touch 創(chuàng)建文件,不存在即創(chuàng)建,存在就改變訪問時間戳,atime
6.echo 打印輸出內(nèi)容,配合 >(重定向,會清除之前內(nèi)容),>>(在尾部追加內(nèi)容) 可以為文件追加內(nèi)容
1 [root@wen 926]# echo {1..9}2 1 2 3 4 5 6 7 8 93 ○ [root@wen data]# cat >fade.txt4 fade walk5 ^C6 [root@wen data]# cat fade.txt7 fade walk8 ○ [root@wen data]# cat >>fade.txt<<efo #efo 可以是任意字符9 > i am studing linux 10 > efo 11 [root@wen data]# cat fade.txt 12 fade walk 13 i am studing linux 14 ○ [root@wen data]# echo mygirl 1>walk.txt 2>&1 #正確,錯誤都輸入到walk.txt 15 [root@wen data]# cat walk.txt 16 mygirl 17 [root@wen data]# ech mygirl 1>walk.txt 2>&1 #正確,錯誤都輸入到walk.txt,等同于 &>1 18 [root@wen data]# cat walk.txt 19 -bash: ech: command not found 20 ○ [root@wen data]# echo mygirl &>>walk.txt #追加 21 [root@wen data]# cat walk.txt 22 -bash: ech: command not found 23 mygirl 24 [root@wen data]# ech mygirl &>>walk.txt 25 [root@wen data]# cat walk.txt 26 -bash: ech: command not found 27 mygirl 28 -bash: ech: command not found 29 ○ [root@wen data]# ech mygirl 1>>walk.txt 2>>walk.txt #重定向前面的數(shù)字要緊跟著 30 [root@wen data]# cat walk.txt 31 -bash: ech: command not found 32 mygirl 33 -bash: ech: command not found 34 -bash: ech: command not found View Code7.cat 查看文件內(nèi)容 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 found8.vi windows記事本,簡單 vim 復雜編輯器,功能復雜,高亮,自動縮進(寫shell/python腳本用)
9.xargs 從標準輸入獲取內(nèi)容創(chuàng)建和執(zhí)行命令 -n 數(shù)字,分組
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 "文件名" 強制刪除目錄不提示,非常危險 強調(diào):刪除命令要慎用,非常危險,刪除前一定要先備份一份
1 ○ [root@wen data]# touch stu{0..6}2 [root@wen data]# find /data -type f -name "stu*" |xargs3 /data/stu1 /data/stu4 /data/stu6 /data/stu3 /data/stu2 /data/stu0 /data/stu54 [root@wen data]# find /data -type f -name "stu*" |xargs -n 15 /data/stu16 /data/stu47 /data/stu68 /data/stu39 /data/stu2 10 /data/stu0 11 /data/stu5 12 [root@wen data]# find /data -type f -name "stu*" |xargs -n 2 #分組 13 /data/stu1 /data/stu4 14 /data/stu6 /data/stu3 15 /data/stu2 /data/stu0 16 /data/stu5 17 ○ [root@wen data]# find /data -type f -name "stu*" |xargs rm -f #find找到,管道xargs刪除 18 ○ [root@wen data]# touch stu{0..6} 19 [root@wen data]# find /data -type f -name "stu*" -exec rm {} \; #另一種刪除方法 20 [root@wen data]# ls View Code12.mv move 移動文件和目錄
14.find 查找 -type 文件類型(f(file),d(diretory),c(character),b(block),s(socket),l(link)) -name "文件名",-mtime 時間,按修改時間查找,時間數(shù)字 +7 7天以前 7 第7天 -7最近7天15.*grep linux三劍客老三 過濾需要的內(nèi)容,-v 排除內(nèi)容 -C #除了顯示匹配行外,顯示該行前后的num行 -B #除了顯示匹配行外,顯示該行之前的num行 -A #除了顯示匹配行外,顯示該行之后的num行 例子查看19-(5)
1 ○ [root@wen data]# cat fade.txt2 fade walk3 i am studing linux4 [root@wen data]# grep -v fade fade.txt5 i am studing linux6 [root@wen data]# grep -v f fade.txt7 i am studing linux8 [root@wen data]# grep -v i fade.txt9 fade walk 10 [root@wen data]# grep fade fade.txt 11 fade walk View Code16.head 頭,頭部 讀取文件的前n行,默認前10行,-n 數(shù)字,習慣-5,忽略-n
17.tail 尾巴 輸出文件的后n行,默認后10行,-n 數(shù)字,習慣-5,忽略-n
1 [root@wen data]# seq 20 > num.txt2 [root@wen data]# head num.txt3 14 25 36 47 58 69 7 10 8 11 9 12 10 13 [root@wen data]# tail num.txt 14 11 15 12 16 13 17 14 18 15 19 16 20 17 21 18 22 19 23 20 24 [root@wen data]# head -3 num.txt 25 1 26 2 27 3 28 [root@wen data]# tail -3 num.txt 29 18 30 19 31 20 View Code18.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 序列
1 [root@wen data]# seq -s '*' 10 #以"*"為間隔符2 1*2*3*4*5*6*7*8*9*103 [root@wen data]# seq 1 2 10 #以1為起點,2為間隔,10為終點4 15 36 57 78 99 [root@wen data]# seq 0 2 10 10 0 11 2 12 4 13 6 14 8 15 10 16 * [root@wen data]# seq 100 >ett.txt #查看ett.txt內(nèi)第20到25行的內(nèi)容(常見考題) 17 1) [root@wen data]# head -25 ett.txt|tail -6 18 20 19 21 20 22 21 23 22 24 23 25 24 2) [root@wen data]# sed -n '20,25p' ett.txt #更高效的方法 25 20 26 21 27 22 28 23 29 24 30 25 31 3) [root@wen data]# awk '19<NR && NR<26' ett.txt 32 20 33 21 34 22 35 23 36 24 37 25 38 4) [root@wen data]# awk '{if(NR >19 && NR< 26) printf $0 "\n"}' ett.txt 39 20 40 21 41 22 42 23 43 24 44 25 45 5) [root@wen data]# grep 22 -C 2 ett.txt #除了顯示匹配行外,顯示該行前后的num行 46 20 47 21 48 22 49 23 50 24 51 6) [root@wen data]# grep 25 -B 5 ett.txt #除了顯示匹配行外,顯示該行之前的num行 52 20 53 21 54 22 55 23 56 24 57 25 58 7) [root@wen data]# grep 20 -A 5 ett.txt #除了顯示匹配行外,顯示該行之后的num行 59 20 60 21 61 22 62 23 63 24 64 25 View Code20.sed linux三劍客老二,流編輯器,實現(xiàn)對文件的增刪改替換查 s,g常聯(lián)合使用,表示對當前進行全局匹配替換 參數(shù) -n 取消默認輸出, -c 允許多項編輯, -I 修改文件內(nèi)容
1 [root@wen data]# echo mygirl >>fade.txt2 [root@wen data]# sed -i 's#mygirl#jujingyi#g' fade.txt3 [root@wen data]# cat fade.txt4 fade walk5 i am studing linux6 jujingyi7 ? [root@wen data]# echo dream-girl{01..04} > /data/girl/del.sh8 [root@wen data]# find /data -type f -name '*.sh' |xargs cat9 dream-girl01 dream-girl02 dream-girl03 dream-girl04 10 [root@wen data]# find /data -type f -name '*.sh' |xargs sed 's#dream-girl*#jujingyi#g' 11 jujingyi01 jujingyi02 jujingyi03 jujingyi04 12 [root@wen data]# find /data -type f -name '*.sh' |xargs sed 's#.*#jujingyi#g' 13 jujingyi 14 [root@wen data]# find /data -type f -name '*.sh' |xargs sed -i 's#dream*#jujingyi#g' 15 [root@wen data]# find /data -type f -name '*.sh' |xargs cat 16 ? jujingyi-girl01 jujingyi-girl02 jujingyi-girl03 jujingyi-girl04 17 [root@wen data]# echo dream-girl{01..04} > /data/girl/del.sh 18 [root@wen data]# sed -i 's#dream-*#beautiful#g' `find /data -type f -name '*.sh'` #替換方法二 19 [root@wen data]# find /data -type f -name '*.sh' |xargs cat 20 beautifulgirl01 beautifulgirl02 beautifulgirl03 beautifulgirl04 View Code21.linux系統(tǒng)查看命令幫助的手段 a.man 命令名/配置文件 b.命令 --help (稍微簡單的幫助) c.搜索引擎“l(fā)inux 命令名”,info d.help 命令名,特殊bash內(nèi)置命令
22.常用快捷鍵 Ctrl +c 終止當前任務命令或程序 Ctrl +d退出當前用戶環(huán)境,相當于 Ctrl +l 清屏,相當于clear命令
23.查看系統(tǒng)64位,內(nèi)核 [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 查看目錄結(jié)構(gòu) 沒有則安裝 yum -y install tree tree -L 1 ,查看當前下一層目錄
25.linux 基礎(chǔ)知識 一,分區(qū) 一塊硬盤:主分區(qū),擴展分區(qū),邏輯分區(qū) 主分區(qū)+擴展分區(qū)的數(shù)量 <= 4,其中一個主分區(qū)可以用一個擴展分區(qū),擴展分區(qū)最多只能有一個 擴展分區(qū)不能直接使用,還需要在上面創(chuàng)建邏輯分區(qū),邏輯分區(qū)可有多個 主分區(qū) + 擴展分區(qū) 編號只能1~4,邏輯分區(qū)的編號只能從5開始 1.常規(guī)分區(qū):數(shù)據(jù)不是特別重要的業(yè)務(集群的某個節(jié)點) /boot 引導分區(qū) 200M swap 交換分區(qū) 內(nèi)存的1.5倍,內(nèi)存大于 8G,就給 8~16G / 根分區(qū),所有目錄頂點 剩余所有空間 2.數(shù)據(jù)重要(數(shù)據(jù)庫,存儲服務區(qū)) /boot 引導分區(qū) 200M swap 交換分區(qū) 內(nèi)存的1.5倍,內(nèi)存大于 8G,就給 8~16G / 根分區(qū),所有目錄頂點 100~200G /data 所有,存放數(shù)據(jù) 3.特大網(wǎng)站,門戶(產(chǎn)品線特別多,需求) /boot 引導分區(qū) 200M swap 交換分區(qū) 內(nèi)存的1.5倍,內(nèi)存大于 8G,就給 8~16G / 根分區(qū),所有目錄頂點 100~200G 剩余空間不分配,哪個部門領(lǐng)到了服務器,根據(jù)需求再進行分區(qū) 二,硬盤 ? 系統(tǒng)的第一塊IDE接口的硬盤稱為 /dev/had ? 系統(tǒng)的第二塊IDE接口的硬盤稱為 /dev/hdb ? 系統(tǒng)的第一塊SCSI接口的硬盤稱為 /dev/sda ? 系統(tǒng)的第二塊SCSI接口的硬盤稱為 /dev/sdb 價格與性能:SSD>SAS>SATA 三,其他硬件 1.網(wǎng)站PC服務器 Dell(普遍) 1u = 4.45cm---->R420,410,620,630 2u--->R730,720,710 2.raid卡及其介紹 詳見linux筆記
26.stat 查看目錄或文件的狀態(tài) display file or file system status
27.檢查網(wǎng)絡服務
1 ssh服務是否好的 檢測辦法:從哪個機器連就在那個機器上操作2 telnet 192.168.59.131 22(服務器的IP和port)在windows上操作3 不通的可能原因:4 a.物理鏈路是否有問題,ping 192.168.59.131 5 b.服務器端防火墻阻擋6 [root@wen data]# /etc/init.d/iptables stop7 iptables:將鏈設置為政策 ACCEPT:filter [確定]8 iptables:清除防火墻規(guī)則: [確定]9 iptables:正在卸載模塊: [確定] 10 c.端口沒有開放,服務器沒有監(jiān)聽你連接的端口 11 [root@wen data]# netstat -lntup |grep 22 #以ssh服務22端口為例 12 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1503/sshd 13 tcp 0 0 :::22 :::* LISTEN 1503/sshd 14 [root@wen data]# netstat -lntup |grep sshd 15 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1503/sshd 16 tcp 0 0 :::22 :::* LISTEN 1503/sshd 17 [root@wen data]# /etc/init.d/sshd restart #重啟ssh服務 18 ○ 網(wǎng)卡配置 剛安裝的linux 網(wǎng)絡服務默認是關(guān)閉的,需要手動調(diào)整 19 #更改配置文件將ONBOOT=no改成yes 20 [root@wen data]# sed -i 's#ONBOOT=no#ONBOOT=yes#g' /etc/sysconfig/network-scripts/ifcfg-eth0 21 [root@wen data]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 22 DEVICE=eth0 23 TYPE=Ethernet 24 ONBOOT=yes 25 [root@wen data]# service network restart #重啟網(wǎng)絡服務生效 26 ○ 小節(jié):linux客戶端DNS可以在網(wǎng)卡配置文件里設置(ifcfg-eth0) 27 linux客戶端DNS也可以在/etc/resolv.conf里設置 28 網(wǎng)卡里的設置DNS優(yōu)先于/etc/resolv.conf,如果重啟網(wǎng)絡網(wǎng)卡的DNS會覆蓋/etc/resolv.conf的設置 29 ○ [root@wen ~]# cat /etc/resolv.conf 30 ; generated by /sbin/dhclient-script 31 search localdomain 32 nameserver 192.168.59.2 #DNS 33 [root@wen ~]# /etc/init.d/network restart #重啟網(wǎng)卡 34 [root@wen ~]# setup "network configuration" "DNS configuration" 就是修改/etc/resolv.conf View Code28.rz,上傳 sz,下載命令 可執(zhí)行 yum install lrzsz -y yum groupinstall 或 "Dial-up Networking Soupport" -y 命令來安裝
29.su 切換用戶 su 和 su -的區(qū)別
30.linux 命令提示符由PS1 環(huán)境變量控制 [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
總結(jié)
以上是生活随笔為你收集整理的linux 基础命令总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VMware linux 克隆机的配置
- 下一篇: 10.27 sort