好玩實用的Linux初學者命令40個,Get!

最近剛剛開始入門Linux,學了幾天,感覺還可以,所以分享一些Linux的干貨
以后有機會還會分享的,有問題可以公眾號:Wang的勝宴 消息發給我,我們一起探討,這個號沒有留言功能...
現在,當下,正著手準備考研的事了。

Tips:本文命令默認在Red Hat Enterprise Linux 7系統的root超級用戶下演示。


命令的一般格式:命令名稱 [命令參數] [命令對象]
命令名稱、命令參數、命令對象之間請用空格鍵*分隔。

命令參數還有長格式、短格式之分。

表格1-1 命令參數的長格式與短格式示例
長格式 man --help
短格式 man -h

- 你需要知道的Linux快捷鍵
Ctrl + C 終止命令的執行
Ctrl + Shift + C 復制
Ctrl + Shift + V 粘貼

干貨預警!!!

1. man man

man 是manual [用戶手冊] 的簡拼,這個命令是用來查看man命令自身的幫助信息,按q鍵退出幫助信息。

[root@wang的勝宴 Desktop]# man man
MAN(1)                                                     Manual pager utils                                                     MAN(1)

NAME
       man - an interface to the on-line reference manuals

SYNOPSIS
       man  [-C  file]  [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-m system[,...]] [-M path] [-S list] [-e extension]
       [-i|-I] [--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P pager] [-r prompt]  [-7]  [-E  encoding]  [--no-hyphen‐
       ation] [--no-justification] [-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ...
       man -k [apropos options] regexp ...
       man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...
       man -f [whatis options] page ...
       man  -l  [-C  file]  [-d]  [-D]  [--warnings[=warnings]]  [-R encoding] [-L locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p
       string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] file ...
       man -w|-W [-C file] [-d] [-D] page ...
       man -c [-C file] [-d] [-D] page ...
       man [-?V]

----------- 省略部分信息 ------------

表1-2:man命令幫助信息的結構以及意義,了解一下即可。

結構名稱 代表意義
NAME 命令的名稱
SYNOPSIS 參數的大致使用方法
DESCRIPTION 介紹說明
EXAMPLES 演示(附帶簡單說明)
OVERVIEW 概述
DEFAULTS 默認的功能
OPTIONS 具體的可用選項(帶介紹)
ENVIRONMENT 環境變量
FILES 用到的文件
SEE ALSO 相關的資料
HISTORY 維護歷史與聯系方式

2. echo [字符串 or $變量]

echo命令用于在終端控制臺輸出字符串或變量的值。

Tips:變量名在Linux系統中一般為全大寫的形式,echo $SHELL可以查看當前所用的shell解釋器。

[root@wang的勝宴 Desktop]# echo 'wang的勝宴'
wang的勝宴
[root@wang的勝宴 Desktop]# echo $SHELL
/bin/bash

3. date [選項] “+指定的格式”

date 命令用于顯示及設置系統的時間和日期。

表1-3:date命令中的參數以及作用

參數 作用
%t 跳格[Tab鍵]
%H 小時(00~23)
%I 小時(00~12)
%M 分鐘(00~59)
%S 秒(00~59)
%j 今年中的第幾天
[root@wang的勝宴 Desktop]# date
Thu Feb 14 10:56:24 CST 2019
[root@wang的勝宴 Desktop]# date "+%Y-%m-%d %H:%M:%S"
2019-02-14 10:57:02
[root@wang的勝宴 Desktop]# date -s "20180522 08:30:00"
Tue May 22 08:30:00 CST 2018
[root@wang的勝宴 Desktop]# date "+%j"
142

4. reboot

reboot命令用于重啟電腦。

5. poweroff

poweroff命令用于關機。

6. wget [參數] 下載地址

wget命令用于在終端下載網絡文件,類似于Python的爬蟲。

表1-4:wget命令的參數以及作用

參數 作用
-b 后臺下載模式
-P 下載到指定目錄
-t 最大嘗試次數
-c 斷點續傳
-p 下載頁面內所有資源,包括圖片、視頻等
-r 遞歸下載
[root@wang的勝宴 Desktop]# wget https://www.wang的勝宴.com/docs/wang的勝宴.pdf
--2017-08-24 19:30:12 -- https://www.wang的勝宴.com/docs/wang的勝宴.pdf
Resolving www.wang的勝宴.com (www.wang的勝宴.com)... 220.181.105.185
Connecting to www.wang的勝宴.com (www.wang的勝宴.com)|220.181.105.185|:80...connected.
HTTP request sent, awaiting response... 200 OK
Length: 45948568 (44M) [application/pdf]
Saving to: ‘wang的勝宴.pdf’
100%[===========================================>] 45,948,568 32.9MB/s in 1.3s
2017-08-24 19:30:14 (32.9 MB/s) - ‘wang的勝宴.pdf’ saved [45948568/45948568]

7. top

top命令用于動態地監視進程活動與系統負載等信息。

[root@wang的勝宴 Desktop]# top

top - 08:34:55 up 17 min,  2 users,  load average: 0.00, 0.08, 0.15
Tasks: 495 total,   1 running, 492 sleeping,   2 stopped,   0 zombie
%Cpu(s):  1.1 us,  0.7 sy,  0.0 ni, 98.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   2035648 total,   874812 used,  1160836 free,      928 buffers
KiB Swap:  2097148 total,        0 used,  2097148 free.   272132 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                
  1180 root      20   0  217300  31508   7796 S   3.6  1.5   0:11.88 Xorg                                                                   
  2375 root      20   0 1667972 228892  38632 S   3.0 11.2   0:55.15 gnome-shell                                                            
  2645 root      20   0  781580  20108  13064 S   2.0  1.0   0:02.88 gnome-terminal-                                                        
  2408 root      20   0  461356   7648   3364 S   0.7  0.4   0:01.58 ibus-daemon                                                            
   139 root      20   0       0      0      0 S   0.3  0.0   0:00.63 rcuos/1                                                                
   292 root      20   0       0      0      0 S   0.3  0.0   0:00.91 kworker/0:1                                                            
  2896 root      20   0  123920   1956   1152 R   0.3  0.1   0:00.12 top                                                                                                                     
----------- 省略部分信息 ------------                             

8. uptime

顯示系統運行時間等信息。

[root@wang的勝宴 Desktop]# uptime
 08:41:23 up 23 min,  2 users,  load average: 0.06, 0.04, 0.11

9. free -h

人性化顯示系統內存相關信息。
-m: 內存顯示為單位為M的形式。

[root@wang的勝宴 Desktop]# free -h
             total       used       free     shared    buffers     cached
Mem:          1.9G       874M       1.1G       9.9M       928K       267M
-/+ buffers/cache:       605M       1.4G
Swap:         2.0G         0B       2.0G
[root@wang的勝宴 Desktop]# free -m
             total       used       free     shared    buffers     cached
Mem:          1987        874       1113          9          0        267
-/+ buffers/cache:        605       1382
Swap:         2047          0       2047

10. ps aux

ps aux命令用于查看系統中的進程狀態。

表1-5:ps命令的參數以及作用

參數 作用
-a 顯示所有進程(包括其他用戶的進程)
-u 用戶以及其他詳細信息
-x 顯示沒有控制終端的進程

如前面所提到的,在Linux系統中的命令參數有長短格式之分,長格式和長格式之間不能合并,長格式和短格式之間也不能合并,但短格式和短格式之間是可以合并的,合并后僅保留一個-(減號)即可。另外ps命令可允許參數不加減號(-),因此可直接寫成ps aux的樣子。

[root@wang的勝宴 Desktop]# ps aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.1  0.3  53780  7696 ?        Ss   08:17   0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 24
root          2  0.0  0.0      0     0 ?        S    08:17   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    08:17   0:00 [ksoftirqd/0]
root          5  0.0  0.0      0     0 ?        S<   08:17   0:00 [kworker/0:0H]
root          7  0.0  0.0      0     0 ?        S    08:17   0:00 [migration/0]
root          8  0.0  0.0      0     0 ?        S    08:17   0:00 [rcu_bh]
----------- 省略部分信息 ------------            

Linux系統中時刻運行著許多進程,如果能夠合理地管理它們,則可以優化系統的性能。在Linux系統中,有5種常見的進程狀態,分別為運行、中斷、不可中斷、僵死與停止,其各自含義如下所示。
R(Running:運行):進程正在運行或在運行隊列中等待。
S(Sleeping:中斷):進程處于休眠中,當某個條件形成后或者接收到信號時,則脫離該 狀態。
D(不可中斷):進程不響應系統異步信號,即便用kill命令也不能將其中斷。
Z(zombie:僵死):進程已經終止,但進程描述符依然存在, 直到父進程調用wait4()系統函數后將進程釋放。
T(stop:停止):進程收到停止信號后停止運行。

11. pwd

查看當前處于的目錄路徑。

[root@wang的勝宴 Desktop]# pwd
/root/Desktop

12. ls -al

查看當前目錄下的所有文件。
-a:顯示所有文件,包括隱藏文件。
-l:查看文件的屬性、大小等詳細信息。
-d:查看目錄屬性信息。

[root@wang的勝宴 Desktop]# ls
chkhost.sh  chkscore.sh  example1.sh  example.sh  genuser.sh  mkcdrom.sh  users.txt
[root@wang的勝宴 Desktop]# ls -al
total 36
drwxr-xr-x.  2 root root 4096 Feb 13  2019 .
dr-xr-x---. 14 root root 4096 Feb 14  2019 ..
-rw-r--r--.  1 root root  135 Feb 13  2019 chkhost.sh
-rw-r--r--.  1 root root  293 Feb 13  2019 chkscore.sh
-rw-r--r--.  1 root root  127 Feb 13  2019 example1.sh
-rwxr--r--.  1 root root   54 Feb 13  2019 example.sh
-rw-r--r--.  1 root root  340 Feb 13  2019 genuser.sh
-rw-r--r--.  1 root root   98 Feb 13  2019 mkcdrom.sh
-rw-r--r--.  1 root root   33 Feb 13  2019 users.txt
[root@wang的勝宴 Desktop]# ls -ld 
drwxr-xr-x. 2 root root 4096 Feb 13  2019 .

13. cd

cd命令用于打開指定目錄。
Cd ~:打開用戶的home目錄。

Cd ..: 打開該目錄的上級目錄。

Cd -: 打開上一個操作目錄。

[root@wang的勝宴 ~]# cd /media/cdrom
[root@wang的勝宴 cdrom]# cd ..
[root@wang的勝宴 media]# cd -
/media/cdrom
[root@wang的勝宴 cdrom]# cd ~
[root@wang的勝宴 ~]# 

14. mkdir

mkdir命令用于創建空目錄。
-p:遞歸創建層疊目錄。

[root@wang的勝宴 Desktop]# mkdir wang的勝宴
[root@wang的勝宴 Desktop]# mkdir -p a/b/c
[root@wang的勝宴 Desktop]# ls
a  chkhost.sh  chkscore.sh  example1.sh  example.sh  genuser.sh  mkcdrom.sh  users.txt  wang的勝宴
[root@wang的勝宴 Desktop]# cd a
[root@wang的勝宴 a]# cd b
[root@wang的勝宴 b]# cd c
[root@wang的勝宴 c]# 

15. cat -n

查看較少的文本文件。
-n: 顯示行號。

[root@wang的勝宴 Desktop]# cat -n example.sh
     1  #!/bin/bash
     2  #For Example BY wang的勝宴.com
     3  pwd
     4  ls -al

16. more

可翻頁查看文字較多的文本。

[root@wang的勝宴 Desktop]# more /etc/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
----------- 省略部分信息 ------------
chrony:x:994:993::/var/lib/chrony:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin
--More--(77%)

17. head -n20 [文件名稱]

查看文本的前20行。

[root@wang的勝宴 ~]# head -n20 anaconda-ks.cfg
#version=RHEL7
# System authorization information
auth --enableshadow --passalgo=sha512

# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=eno16777728 --onboot=off --ipv6=auto
network  --hostname=wang的勝宴.com
# Root password
rootpw --iscrypted $6$/BICADenrxneXgcq$jqSud/wsmjaYjyeHTKQ8QcP2.RJGbPS7.ZH9ICkG5GvikzJWkABG5m2Vd2V7H9mMdYW1/dVre70Eeynwtyrjm1
# System timezone

18. tail -n20 [文件名稱]

查看文本的后20行。

[root@wang的勝宴 ~]# tail -n20 anaconda-ks.cfg
# Partition clearing information
clearpart --none --initlabel 

%packages
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@multimedia
@print-client
@x11

%end

19. tail -f [文件名稱]

實時刷新查看文件,例如日志。

20. cp [參數] 源文件 目標文件

cp命令用于復制文件或目錄。

大家對文件復制操作應該不陌生,在Linux系統中,復制操作具體分為3種情況:
如果目標文件是目錄,則會把源文件復制到該目錄中;
如果目標文件也是普通文件,則會詢問是否要覆蓋它;
如果目標文件不存在,則執行正常的復制操作。

表1-6:cp命令的參數及其作用

參數 作用
-p 保留原始文件的屬性
-d 若對象為“鏈接文件”,則保留該“鏈接文件”的屬性
-r 遞歸持續復制(用于目錄)
-i 若目標文件存在則詢問是否覆蓋
-a 相當于-pdr(p、d、r為上述參數)
[root@wang的勝宴 ~]# cp -a Desktop/example.sh /etc

上面的命令是將桌面上的example.sh復制到etc目錄下。

21. tar czvf 文件對象 要壓縮的目錄

tar命令用于壓縮和解壓文件或目錄。
表1-7:tar命令的參數及其作用

參數 作用
-c 創建壓縮文件
-x 解開壓縮文件
-t 查看壓縮包內有哪些文件
-z 用Gzip壓縮或解壓
-j 用bzip2壓縮或解壓
-v 顯示壓縮或解壓的過程
-f 目標文件名
-p 保留原始的權限與屬性
-P 使用絕對路徑來壓縮
-C 指定解壓到的目錄
[root@wang的勝宴 ~]# tar czvf example.tar.gz /etc
tar: Removing leading `/' from member names
/etc/
/etc/fstab
/etc/crypttab
/etc/mtab
----------- 省略部分信息 ------------
/etc/httpd/modules
/etc/httpd/run
/etc/example.sh

22. tar xzvf 要解壓的目錄 -C 指定解壓到的目錄

oot@wang的勝宴 ~]# tar xzvf example.tar.gz -C ~
etc/
etc/fstab
tar: etc/fstab: time stamp 2019-02-12 15:22:40 is 23004119.465139425 s in the future
----------- 省略部分信息 ------------
tar: etc/X11/xinit: time stamp 2019-02-12 19:49:10 is 23020107.551471209 s in the future
tar: etc/X11/fontpath.d: time stamp 2019-02-12 19:50:35 is 23020192.551458642 s in the future
tar: etc/X11: time stamp 2019-02-12 19:48:19 is 23020056.551446702 s in the future
tar: etc/fonts/conf.d: time stamp 2019-02-12 19:50:48 is 23020205.551434998 s in the future
tar: etc/fonts: time stamp 2019-02-12 19:47:00 is 23019977.551409038 s in the future

23. grep [參數] 關鍵詞 文本文件

grep命令用于在文本中執行關鍵詞搜索,并顯示匹配的結果。
表1-8:grep命令的參數及其作用

參數 作用
-b 將可執行文件(binary)當作文本文件(text)來搜索
-c 僅顯示找到的行數
-i 忽略大小寫
-n 顯示行號
-v 反向選擇——僅列出沒有“關鍵詞”的行。
[root@wang的勝宴 ~]# grep /sbin/nologin /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
----------- 省略部分信息 ------------
tcpdump:x:72:72::/:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@wang的勝宴 ~]# grep -v /sbin/nologin /etc/passwd
root:x:0:0:root:/root:/bin/bash
----------- 省略部分信息 ------------
eric:x:1005:1005::/home/eric:/bin/bash
george:x:1006:1006::/home/george:/bin/bash

24. find [查找路徑] [尋找條件] [操作]

find命令用于按照指定條件來查找文件。

表1-9:find命令中的參數以及作用

參數 作用
-name 匹配名稱
-perm 匹配權限(mode為完全匹配,-mode為包含即可)
-user 匹配所有者
-group 匹配所有組
-mtime -n +n 匹配修改內容的時間(-n指n天以內,+n指n天以前)
-atime -n +n 匹配訪問文件的時間(-n指n天以內,+n指n天以前)
-ctime -n +n 匹配修改文件權限的時間(-n指n天以內,+n指n天以前)
-nouser 匹配無所有者的文件
-nogroup 匹配無所有組的文件
-newer f1 !f2 匹配比文件f1新但比f2舊的文件
--type b/d/c/p/l/f 匹配文件類型(后面的字幕字母依次表示塊設備、目錄、字符設備、管道、鏈接文件、文本文件)
-size 匹配文件的大小(+50KB為查找超過50KB的文件,而-50KB為查找小于50KB的文件)
-prune 忽略某個目錄
-exec …… {}; 后面可跟用于進一步處理搜索結果的命令(下文會有演示)
[root@wang的勝宴 ~]# find / -user wang的勝宴 -exec cp -a {} /root/findresults \;
find: ‘/proc/3745/task/3745/fd/6’: No such file or directory
find: ‘/proc/3745/task/3745/fdinfo/6’: No such file or directory
find: ‘/proc/3745/fd/6’: No such file or directory
find: ‘/proc/3745/fdinfo/6’: No such file or directory
cp: cannot copy a directory, ‘/root/findresults’, into itself, ‘/root/findresults/findresults’
cp: ‘/root/findresults/.mozilla’ and ‘/root/findresults/.mozilla’ are the same file
----------- 省略部分信息 ------------
cp: ‘/root/findresults/webkit’ and ‘/root/findresults/webkit’ are the same file
cp: ‘/root/findresults/icondatabase’ and ‘/root/findresults/icondatabase’ are the same file
cp: ‘/root/findresults/WebpageIcons.db’ and ‘/root/findresults/WebpageIcons.db’ are the same file

[root@wang的勝宴 ~]# ls /root/findresults
2075                                                          first-index.txt                photos
91fd3dc4769d4584b378532f02ffb133-card-database.tdb            folks                          Pictures
----------- 省略部分信息 ------------
calendar                                                      input-sources-converted        
findresults                                                   ontologies.gvdb

find /* -user wang的勝宴 -exec cp -a {} /root/findresults \;:查找系統中的所有文件中所有者為wang的勝宴的文件,并將這些文件復制到/root/finresults目錄下。

25. history

history命令用于查看用戶輸入命令的記錄。

[root@wang的勝宴 ~]# history
    1  ifconfig
    2  cat /etc/hostname
    3  cd /etc/sysconfig/network-scripts
    4  vim ifcfg-eno1677778
    5  rm -f ifcfg-eno1677778
----------- 省略部分信息 ------------
  163  grep -v /sbin/nologin /etc/passwd
  164  find / -user wang的勝宴 -exec cp -a {} /root/findresults \;
  165  cat /etc/findresualts
  166  cat /etc/findresults
  167  cat /root/findresults
  168  ls /root
  169  ls /root/findresults
  170  history

26. wc [參數] 文本

wc命令用于統計指定文本的行數、字數、字節數。
表1-10:wc的參數以及作用

參數 作用
-l 只顯示行數
-w 只顯示單詞數
-c 只顯示字節數
[root@wang的勝宴 Desktop]# wc example.sh
 4  8 54 example.sh

27. tr [原始字符] [目標字符]

tr命令用于替換文本中的字符。

[root@wang的勝宴 Desktop]# cat users.txt
andy
barry
carl
duke
eric
george
[root@wang的勝宴 Desktop]#  cat users.txt | tr 'a-z' 'A-Z'
ANDY
BARRY
CARL
DUKE
ERIC
GEORGE

' | ':管道符,用于把該符前面命令的輸出內容作為后面命令的輸入。
'a-z' 'A-Z':通配符(和正則表達式差不多),表示a到z的26個小寫字母,后者同理。

28. stat [文件名稱]

stat命令用于查看文件的具體存儲信息和時間等信息。

[root@wang的勝宴 Desktop]# stat example.sh
  File: ‘example.sh’
  Size: 54          Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d    Inode: 71432578    Links: 1
Access: (0744/-rwxr--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2019-02-14 20:52:41.398015290 +0800
Modify: 2019-02-13 16:50:34.579017291 +0800
Change: 2019-02-13 16:56:30.486020308 +0800
 Birth: -

29. touch [選項] [文件]

touch命令用于創建空目錄或設置文件的時間。
表1-11:touch命令的參數及其作用

參數 作用
-a 僅修改“讀取時間”(atime)
-m 僅修改“修改時間”(mtime)
-d 同時修改atime與mtime
[root@wang的勝宴 Desktop]# touch wang的勝宴
[root@wang的勝宴 Desktop]# cd wang的勝宴
[root@wang的勝宴 wang的勝宴]# cd -
/root/Desktop
[root@wang的勝宴 Desktop]# ls -l example.sh
-rwxr--r--. 1 root root 54 Feb 13 16:50 example.sh
[root@wang的勝宴 Desktop]# touch -d "20190210 05:20" example.sh
[root@wang的勝宴 Desktop]# ls -l example.sh
-rwxr--r--. 1 root root 54 Feb 10 05:20 example.sh

30. dd

dd命令用于按照指定大小和個數的數據塊來復制文件或轉換文件。

dd命令是一個比較重要而且比較有特色的一個命令,它能夠讓用戶按照指定大小和個數的數據塊來復制文件的內容。
Linux系統中有一個名為/dev/zero的設備文件,充滿著哲學理論色彩,因為這個文件不會占用系統存儲空間,但卻可以提供無窮無盡的數據,因此可以使用它作為dd命令的輸入文件,來生成一個指定大小的文件。

表2-13:dd命令的參數及其作用如表2-13所示。

參數 作用
if 輸入的文件名稱
of 輸出的文件名稱
bs 設置每個“塊”的大小
count 設置要復制“塊”的個數
[root@wang的勝宴 Desktop]# dd if=/dev/zero of=800M_file count=1 bs=800M
1+0 records in
1+0 records out
838860800 bytes (839 MB) copied, 34.7179 s, 24.2 MB/s

31. diff [參數] 文件1 文件2 ...

diff命令用于比較多個文本文件的差異。
--brief:顯示比較后的結果,判斷文件是否相同,相同則無顯示。

[root@wang的勝宴 Desktop]# diff --brief example.sh example1.sh
Files example.sh and example1.sh differ
[root@wang的勝宴 Desktop]# diff -c example.sh example1.sh
*** example.sh  2019-02-10 05:20:00.000000000 +0800
--- example1.sh 2019-02-13 17:06:50.050025560 +0800
***************
*** 1,4 ****
  #!/bin/bash
! #For Example BY wang的勝宴.com
! pwd
! ls -al
--- 1,5 ----
  #!/bin/bash
! echo "當前腳本名稱為$0"
! echo "總共有$#個參數,分別是$*"
! echo "第1個參數為$1,第五個為$5"
! 

32. cut

cut命令用于按“列”提取文本字符。
-d:用于指定每列的間隔符。
-f:用于指定輸出第幾列的內容。

[root@wang的勝宴 Desktop]# cut -d: -f1 /etc/passwd
root
wang的勝宴
----------- 省略部分信息 ------------
duke
eric
george

33. mv [選項] 源文件 [目標路徑|目標文件名]

mv命令用于剪切文件或將文件重命名。

剪切操作不同于復制操作,因為它會默認把源文件刪除掉,只保留剪切后的文件。如果在同一個目錄中對一個文件進行剪切操作,其實也就是對其進行重命名。

[root@wang的勝宴 Desktop]# ls
800M_file  a  chkhost.sh  chkscore.sh  example1.sh  example.sh  genuser.sh  mkcdrom.sh  users.txt  wang的勝宴
[root@wang的勝宴 Desktop]# mv /etc/passwd ~/Desktop
[root@wang的勝宴 Desktop]# ls
800M_file  a  chkhost.sh  chkscore.sh  example1.sh  example.sh  genuser.sh  mkcdrom.sh  passwd  users.txt  wang的勝宴

34. rm

rm命令用于刪除文件或目錄。
-f:刪除免提示,直接刪除。
-r:刪除目錄,需帶此參數。

[root@wang的勝宴 Desktop]# rm -fr wang的勝宴
[root@wang的勝宴 Desktop]# ls
800M_file  a  chkhost.sh  chkscore.sh  example1.sh  example.sh  genuser.sh  mkcdrom.sh  users.txt

35. file

file命令用于查看文件所屬的具體類型。

[root@wang的勝宴 Desktop]# file example.sh
example.sh: Bourne-Again shell script, ASCII text executable

36. type

type命令用于查看命令所屬的具體類型。

[root@wang的勝宴 Desktop]# type rm
rm is aliased to `rm -i'

這里顯示rm命令實際為rm -i的別名,可用alias rm查看。

公眾號:勝言
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,362評論 6 544
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,577評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,486評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,852評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,600評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,944評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,944評論 3 447
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,108評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,652評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,385評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,616評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,111評論 5 364
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,798評論 3 350
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,205評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,537評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,334評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,570評論 2 379

推薦閱讀更多精彩內容