天天看點

檔案管理基礎指令1.21. type 顯示指令的類型2. find 查找和搜尋檔案3. rz 上傳4. sz 下載下傳5. wget 聯網下載下傳6. curl 通路網站7. sort 排序8. uniq 去重9. cut 取列10. tr 替換 删除11. wc 統計

文章目錄

  • 1. type 顯示指令的類型
  • 2. find 查找和搜尋檔案
  • 3. rz 上傳
  • 4. sz 下載下傳
  • 5. wget 聯網下載下傳
  • 6. curl 通路網站
  • 7. sort 排序
  • 8. uniq 去重
  • 9. cut 取列
  • 10. tr 替換 删除
  • 11. wc 統計

1. type 顯示指令的類型

type      #顯示指令的類型

選項:
    -a		#顯示内置指令的絕對路徑  
	
	-p		#隻顯示指令的絕對路徑
	
# help 指令可以顯示系統中所有的内置指令 	

[[email protected] ~]# type cd   
cd is a shell builtin      #内置指令
[[email protected] ~]# type -a cd   #顯示内置指令的絕對路徑
cd is a shell builtin   
cd is /usr/bin/cd

[[email protected] ~]# type ping
ping is /usr/bin/ping
[[email protected] ~]# type -p ping   #隻顯示指令的絕對路徑
/usr/bin/ping
[[email protected] ~]# type -ap cp    #顯示内置指令的絕對路徑 内置指令必須加a
/usr/bin/cp


           

2. find 查找和搜尋檔案

find      #檔案查找指令包括隐藏檔案     指定路徑查找   根據名稱  大小  權限  時間等查找 

選項:
  -type			#根據類型查找 

	   f		    #普通檔案
	
	   d		    #目錄
	
  -name			#根據名稱進行查找  

	   "*xxx"	#以任意開頭的,xxx為結尾的檔案 
		
	   "xxx*"	#以xxx開頭,任意字元為結尾的檔案  
		
	   "*xxx*"	#查找檔案名稱中包含xxx的

  -iname		#查找的時候忽略大小寫  

  -maxdepth	    #查找目錄的層級  根據目錄層級進行查找

   *		    #特殊符号  通配符  不是正則     所有的意思

                  指令   目錄    類型   普通檔案   根據名稱   叫什麼名字
[[email protected] ~]# find   /etc   -type      f      -name     "hostname"		#精确查找 
/etc/hostname
                  指令    目錄   類型     目錄     忽略大小寫   名字
[[email protected] ~]# find   /root  -type      d      -iname      "zzc"
/root/zzc
/root/ZZC

#查找以hostname開頭的檔案   "xxx*"	#以xxx開頭,任意字元為結尾的檔案
[[email protected] ~]# find  /opt/    -name  "hostname*" 
/opt/hostname
/opt/hostnamectl

#查找以hostname為結尾的檔案  "*xxx"	#以任意開頭的,xxx為結尾的檔案 
[[email protected] ~]# find   /opt/  -name  "*hostname"
/opt/hostname
/opt/test_hostname

#查找檔案名稱包含hostname的檔案包括隐藏檔案    "*xxx*"  #查找檔案名稱中包含xxx的
[[email protected] ~]# find  /opt/  -name "*hostname*"
/opt/hostname
/opt/hostnamectl
/opt/test_hostname
/opt/test_hostname.txt

[[email protected] ~]# touch   /opt/.hostname.log
[[email protected] ~]# find  /opt/  -name "*hostname*"
/opt/hostname
/opt/hostnamectl
/opt/test_hostname
/opt/test_hostname.txt
/opt/.hostname.log

#查找根目錄下前四個目錄的所有已oldbboy開頭的檔案
[[email protected] ~]# find / -maxdepth 4 -type f -name "oldboy*"
/etc/oldboy.txt
/root/oldboy.txt
/test/123/456/oldboy.txt

#根據目錄的層級查找
[[email protected] ~]# find  /  -maxdepth  2   -type  d   -name  "hostname"
/root/hostname
[[email protected] ~]# 


           

3. rz 上傳

rz      #将本地的檔案上傳到Linux作業系統
#不能上傳目錄,需要将目錄打成一個壓縮包進行上傳     隻能上傳 4G以下的檔案

#rz上傳 sz下載下傳指令安裝包
[[email protected] ~]# yum  install  lrzsz   -y

選項:
   -E   #當上傳的檔案已經存在時,系統會進行重命名   會在原來的檔案名稱後面加上.數字  從0開始
   
[[email protected] ~]# rz  -E
[[email protected] ~]# ll
total 32
-rw-r--r--. 1 root root 13140 Jul  7 12:23 day03.md
-rw-r--r--. 1 root root 13140 Jul  7 12:23 day03.md.0

           

4. sz 下載下傳

sz          #将Linux系統的檔案下載下傳到本地

[[email protected] ~]# sz passwd

           

5. wget 聯網下載下傳

wget     #聯網下載下傳

#軟體包
[[email protected] ~]# yum  install  -y  wget

選項:  
	-O(大寫)		#指定下載下傳的路徑和名稱  
	
	-q		#靜默輸出  
	
	--limit-rate=10k		#限制下載下傳的速率     k  ===KB    m  == MB
	
[[email protected] ~]# wget www.baidu.com
--2020-07-10 16:22:58--  http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 112.80.248.76, 112.80.248.75
Connecting to www.baidu.com (www.baidu.com)|112.80.248.76|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html’

100%[=========================================>] 2,381       --.-K/s   in 0s      

2020-07-10 16:22:58 (105 MB/s) - ‘index.html’ saved [2381/2381]


[[email protected] ~]# wget http://nginx.org/download/nginx-1.18.0.zip
--2020-07-10 16:25:32--  http://nginx.org/download/nginx-1.18.0.zip
Resolving nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|62.210.92.35|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1711619 (1.6M) [application/zip]
Saving to: ‘nginx-1.18.0.zip’

100%[=========================================>] 1,711,619   38.1KB/s   in 54s    

2020-07-10 16:26:26 (31.0 KB/s) - ‘nginx-1.18.0.zip’ saved [1711619/1711619]

[[email protected] ~]# ll
total 1692
-rw-r--r--. 1 root root    9810 Jul  8 00:06 download.html
-rw-r--r--. 1 root root    2381 Jul 10 16:22 index.html
-rw-r--r--. 1 root root 1711619 Apr 21 22:33 nginx-1.18.0.zip
-

#指定下載下傳路徑及名稱 
[[email protected] ~]# wget -O /opt/nginx-org http://nginx.org/download/nginx-1.18.0.zip--2020-07-10 16:30:23--  http://nginx.org/download/nginx-1.18.0.zip
Resolving nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|62.210.92.35|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1711619 (1.6M) [application/zip]
Saving to: ‘/opt/nginx-org’

100%[=========================================>] 1,711,619   25.6KB/s   in 48s    

2020-07-10 16:31:11 (35.0 KB/s) - ‘/opt/nginx-org’ saved [1711619/1711619]

[[email protected] ~]# ll /opt
total 1984
-rw-r--r--. 1 root root 1711619 Apr 21 22:33 nginx-org

#靜默下載下傳,不顯示下載下傳過程
[[email protected] ~]# wget  -q  http://nginx.org/download/nginx-1.19.1.tar.gz
[[email protected] ~]# ll
total 2100
-rw-r--r--. 1 root root   41240 Mar 23 00:20 032220_1620_Zabbix1.png
-rw-r--r--. 1 root root    9810 Jul  8 00:06 download.html
-rw-r--r--. 1 root root    2381 Jul 10 11:57 index.html
-rw-r--r--. 1 root root 1039530 Apr 21 22:33 nginx-1.18.0.tar.gz
-rw-r--r--. 1 root root 1047223 Jul  7 23:59 nginx-1.19.1.tar.gz


#限制下載下傳速率
[[email protected] ~]# wget   --limit-rate=10k   http://nginx.org/download/nginx-1.18.0.tar.gz ^C
[[email protected] ~]# rm -rf ./*
[[email protected] ~]# wget   --limit-rate=10k   http://nginx.org/download/nginx-1.18.0.tar.gz
--2020-07-10 12:11:13--  http://nginx.org/download/nginx-1.18.0.tar.gz
Resolving nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|62.210.92.35|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1039530 (1015K) [application/octet-stream]
Saving to: ‘nginx-1.18.0.tar.gz’

32% [========================>] 335,872     10.0KB/s  eta 70s   



           

6. curl 通路網站

curl		#利用URL規則在指令行下面工作的檔案傳輸工具   聯網下載下傳   測試網站  通路網站 

選項:  
	-o		#把通路的内容寫入到一個指定的檔案中
	
	-s		#靜默輸出  不顯示通路寫入的過程 


[[email protected] ~]# curl  -o  ./baidu.html    www.baidu.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2381  100  2381    0     0    311      0  0:00:07  0:00:07 --:--:--   657
[[email protected] ~]# ll
total 1356
-rw-r--r--. 1 root root    2381 Jul 10 12:15 baidu.html


[[email protected] ~]# curl  -s   -o   ./nginx.tar.gz    http://nginx.org/download/nginx-1.18.0.tar.gz



           

7. sort 排序

sort     #排序    将不相同的行進行排序在一起     預設是根據第一列進行排序  預設是以空白字元為分割符  預設以字母進行排序

選項:
	-k		#指定哪一列排序
	
	-n		#以數值大小的方式進行排序 
	
	-r		#倒叙排序  

	-t		#指定分隔符  

[[email protected] ~]# cat test.txt
a 3
c 5
e 8
b 4
g 9
d 12
[[email protected] ~]# sort -k2 test.txt    #指定第二列排序
d 12
a 3
b 4
c 5
e 8
g 9

[[email protected] ~]# sort -nk2 test.txt   #指定第二列按數值大小排序
a 3
b 4
c 5
e 8
g 9
d 12

[[email protected] ~]# sort -rnk2 test.txt   #指定第二列按數值大小倒序排列
d 12
g 9
e 8
c 5
b 4
a 3

[[email protected] ~]# sort -t ':' -nk3 passwd   #指定以 :為分隔符的第三列數值大小排序
root:x:0:0:root:/root:/bin/bash
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
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
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin



           

8. uniq 去重

uniq     #去重   去除重複的行   隻能去除相同相鄰的行     統計   将重複的行的次數統計出來    跟sort結合使用

|		#管道   将前面指令的執行結果交給後面的指令繼續執行   操作的是資料  

選項:
		-c		#統計重複的行的次數 
		
[[email protected] ~]# sort file.txt
123
123
456
abc
abc
qwe
[[email protected] ~]# sort file.txt | uniq  
123
456
abc
qwe

[[email protected] ~]# sort file.txt | uniq -c    #統計重複的行
      2 123
      1 456
      2 abc
      1 qwe
 
[[email protected] ~]# sort file.txt | uniq -c | sort
      1 456
      1 qwe
      2 123
      2 abc
[[email protected] ~]# sort file.txt | uniq -c | sort -n
      1 456
      1 qwe
      2 123
      2 abc
[[email protected] ~]# sort file.txt | uniq -c | sort -rn
      2 abc
      2 123
      1 qwe
      1 456


           

9. cut 取列

cut   #取列  awk指令的小弟  預設的分隔符為tab鍵   截取字段   截取你想要的内容

選項:
		-d		#指定分隔符 
		
		-f		#取出指定的列 
        
        -c		#取出指定的字元  按照行進行處理的 
 
[[email protected] ~]# cat test.txt
root:x:0:0:root:/root:/bin/bash
[[email protected] ~]# cut -d ":" -f7 test.txt    #指定以 : 為分隔符取第七列
/bin/bash

[[email protected] ~]# cut -d ":" -f1,7 test.txt  #指定以 :為分隔符取第一和第七列
root:/bin/bash

[[email protected] ~]# cut -d ":" -f4-7 test.txt  #指定以 : 為分隔符取第四到第七列
0:root:/root:/bin/bash

[[email protected] ~]# cat test.txt
root:x:0:0:root:/root:/bin/bash
[[email protected] ~]# cut -c 6 test.txt   #取第六個字元
x
[[email protected] ~]# cut -c 4,8 test.txt  #取第四個和第八個字元
t0
[[email protected] ~]# cut -c 3-7 test.txt  #取第三到第七的字元
ot:x:

#取出系統eth0的IP位址
[[email protected] ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.100  netmask 255.255.255.0  broadcast 10.0.0.255
        inet6 fe80::5169:baec:f4cd:6fb9  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:02:d2:3a  txqueuelen 1000  (Ethernet)
        RX packets 2524  bytes 206264 (201.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1280  bytes 138388 (135.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[[email protected] ~]# ifconfig eth0 | head -2 | tail -1 | cut -d " " -f10
10.0.0.100

[[email protected] ~]# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:02:d2:3a brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5169:baec:f4cd:6fb9/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[[email protected] ~]# ip a s eth0 | head -3 | tail -1 | cut -c 10-19
10.0.0.100


           

10. tr 替換 删除

tr   #替換或者删除字元的指令    隻能單對單的替換
選項:
	-d		#删除指定的字元
	
文法:
	tr   old   new   <   file  
   <		#标準輸入重定向
   
[[email protected] ~]# cat test.txt
root:x:0:0:root:/root:/bin/bash
[[email protected] ~]# tr "0" "7" < test.txt    #替換字元
root:x:7:7:root:/root:/bin/bash

[[email protected] ~]# cat test.txt             #删除字元
root:x:0:0:root:/root:/bin/bash
[[email protected] ~]# tr -d "0" < test.txt
root:x:::root:/root:/bin/bash


           

11. wc 統計

wc     ##統計    行數  位元組數  列數   行的長度 

選項:
	-l		#統計行數 
	
	-w		#統計列數,預設以空白字元為分隔符 
	
	-c		#統計位元組數 
	
	-L		#統計檔案中最長的行的長度
	
[[email protected] ~]# wc passwd
 21  39 974 passwd
[[email protected] ~]# wc -l passwd    #隻統計行數
21 passwd
[[email protected] ~]# wc -w passwd    #隻統計列數
39 passwd
[[email protected] ~]# wc -c passwd    #隻統計位元組數
974 passwd
[[email protected] ~]# wc -L passwd    #統計檔案中最長的行的長度
99 passwd	


           

繼續閱讀