Linux就該這麼學-新手必須掌握的 Linux 命令
阿新 • • 發佈:2022-12-05
執行檢視幫助命令
命令名稱 [命令引數] [命令物件] man --help man -h
echo 命令
echo Linuxprobe.Com
date 命令
[root@linuxprobe ~]# date Mon Aug 24 16:11:23 CST 2017 [root@linuxprobe ~]# date "+%Y-%m-%d %H:%M:%S" 2017-08-24 16:29:12
reboot 命令
[root@linuxprobe ~]# reboot
.poweroff 命令
[root@linuxprobe ~]# poweroff
wget 命令
wget 命令用於在終端中下載網路檔案,格式為“wget [引數] 下載地址”。 -b 後臺下載模式 -P 下載到指定目錄 -t 最大嘗試次數 -c 斷點續傳 -p 下載頁面內所有資源,包括圖片、視訊等 -r 遞迴下載 [root@linuxprobe ~]# wget http://www.linuxprobe.com/docs/LinuxProbe.pdf
ps 命令
ps 命令用於檢視系統中的程序狀態,格式為“ps [引數]” -a 顯示所有程序(包括其他使用者的程序) -u 使用者以及其他詳細資訊 -x 顯示沒有控制終端的程序
top 命令
top 命令用於動態地監視程序活動與系統負載等資訊,其格式為 top。 ¾ 第 1 行:系統時間、執行時間、登入終端數、系統負載(三個數值分別為 1 分鐘、5 分鐘、15 分鐘內的平均值,數值越小意味著負載越低)。 ¾ 第 2 行:程序總數、執行中的程序數、睡眠中的程序數、停止的程序數、僵死的程序 數。 ¾ 第 3 行:使用者佔用資源百分比、系統核心佔用資源百分比、改變過優先順序的程序資源 百分比、空閒的資源百分比等。 ¾ 第 4 行:實體記憶體總量、記憶體使用量、記憶體空閒量、作為核心快取的記憶體量。 ¾ 第 5 行:虛擬記憶體總量、虛擬記憶體使用量、虛擬記憶體空閒量、已被提前載入的記憶體量
pidof 命令
pidof 命令用於查詢某個指定服務程序的 PID 值,格式為“pidof [引數] [服務名稱]” [root@linuxprobe ~]# pidof sshd 2156
kill 命令
kill 命令用於終止某個指定 PID 的服務程序,格式為“kill [引數] [程序 PID]”。 [root@linuxprobe ~]# kill 2156
killall 命令
格式為:“killall [引數] [程序名稱]”。 [root@linuxprobe ~]# pidof httpd 13581 13580 13579 13578 13577 13576 [root@linuxprobe ~]# killall httpd [root@linuxprobe ~]# pidof httpd [root@linuxprobe ~]#
ifconfig 命令《=》 ip address 命令
[root@linuxprobe ~]# ifconfig [root@linuxprobe ~]# ip address
uname 命令
uname 命令用於檢視系統核心與系統版本等資訊,格式為“uname [-a]” [root@linuxprobe ~]# uname -a Linux linuxprobe.com 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
uptime 命令
uptime 用於檢視系統的負載資訊,格式為 uptime。 [root@linuxprobe ~]# uptime 22:49:55 up 10 min, 2 users, load average: 0.01, 0.19, 0.18
free 命令
free 用於顯示當前系統中記憶體的使用量資訊,格式為“free [-h]”。 [root@linuxprobe ~]# free -h
who 命令
who 用於檢視當前登入主機的使用者終端資訊,格式為“who [引數]”。 [root@linuxprobe ~]# who
last 命令
last 命令用於檢視所有系統的登入記錄,格式為“last [引數]”。 [root@linuxprobe ~]# last
history 命令
history 命令用於顯示歷史執行過的命令,格式為“history [-c]”。
pwd 命令
pwd 命令用於顯示使用者當前所處的工作目錄,格式為“pwd [選項]” [root@linuxprobe etc]# pwd /etc
cd 命令
cd 命令用於切換工作路徑,格式為“cd [目錄名稱]”
ls 命令
ls 命令用於顯示目錄中的檔案資訊,格式為“ls [選項] [檔案] ” 使用 ls 命令的“-a”引數看 到全部檔案(包括隱藏檔案),使用“-l”引數可以檢視檔案的屬性、大小等詳細資訊。 [root@linuxprobe ~]# ls -al [root@linuxprobe ~]# ls -ld /etc drwxr-xr-x. 132 root root 8192 Jul 10 10:48 /etc
cat 命令
cat 命令用於檢視純文字檔案(內容較少的),格式為“cat [選項] [檔案]”。 [root@linuxprobe ~]# cat -n initial-setup-ks.cfg
more 命令
more 命令用於檢視純文字檔案(內容較多的),格式為“more [選項]檔案”。
head 命令
head 命令用於檢視純文字文件的前 N 行,格式為“head [選項] [檔案]”。
tail 命令
tail 命令用於檢視純文字文件的後 N 行或持續重新整理內容,格式為“tail [選項] [檔案]”。
tr 命令
tr 命令用於替換文字檔案中的字元,格式為“tr [原始字元] [目標字元]”。 [root@linuxprobe ~]# cat anaconda-ks.cfg | tr [a-z] [A-Z]
wc 命令
wc 命令用於統計指定文字的行數、字數、位元組數,格式為“wc [引數] 文字” -l 只顯示行數 -w 只顯示單詞數 -c 只顯示位元組數 [root@linuxprobe ~]# wc -l /etc/passwd 38 /etc/passwd
stat 命令
stat 命令用於檢視檔案的具體儲存資訊和時間等資訊,格式為“stat 檔名稱” [root@linuxprobe ~]# stat anaconda-ks.cfg
cut 命令
cut 命令用於按“列”提取文字字元,格式為“cut [引數] 文字”。 [root@linuxprobe ~]# head -n 2 /etc/passwd
diff 命令
diff 命令用於比較多個文字檔案的差異,格式為“diff [引數] 檔案”。 [root@linuxprobe ~]# cat diff_A.txt Welcome to linuxprobe.com Red Hat certified Free Linux Lessons Professional guidance Linux Course [root@linuxprobe ~]# cat diff_B.txt Welcome tooo linuxprobe.com Red Hat certified Free Linux LeSSonS ////////.....//////// Professional guidance Linux Course 接下來使用 diff --brief 命令顯示比較後的結果,判斷檔案是否相同: [root@linuxprobe ~]# diff --brief diff_A.txt diff_B.txt Files diff_A.txt and diff_B.txt differ 最後使用帶有-c 引數的 diff 命令來描述檔案內容具體的不同: [root@linuxprobe ~]# diff -c diff_A.txt diff_B.txt *** diff_A.txt 2017-08-30 18:07:45.230864626 +0800 --- diff_B.txt 2017-08-30 18:08:52.203860389 +0800 *************** *** 1,5 **** ! Welcome to linuxprobe.com Red Hat certified ! Free Linux Lessons Professional guidance Linux Course --- 1,7 ---- ! Welcome tooo linuxprobe.com ! Red Hat certified ! Free Linux LeSSonS ! ////////.....//////// Professional guidance Linux Course
touch 命令
touch 命令用於建立空白檔案或設定檔案的時間,格式為“touch [選項] [檔案]” -a 僅修改“讀取時間”(atime) -m 僅修改“修改時間”(mtime) -d 同時修改 atime 與 mtime [root@linuxprobe ~]# ls -l anaconda-ks.cfg -rw-------. 1 root root 1213 May 4 15:44 anaconda-ks.cfg [root@linuxprobe ~]# echo "Visit the LinuxProbe.com to learn linux skills" >> anaconda-ks.cfg [root@linuxprobe ~]# ls -l anaconda-ks.cfg -rw-------. 1 root root 1260 Aug 2 01:26 anaconda-ks.cfg [root@linuxprobe ~]# touch -d "2017-05-04 15:44" anaconda-ks.cfg [root@linuxprobe ~]# ls -l anaconda-ks.cfg -rw-------. 1 root root 1260 May 4 15:44 anaconda-ks.cfg
mkdir 命令
mkdir 命令用於建立空白的目錄,格式為“mkdir [選項] 目錄”。 [root@linuxprobe ~]# mkdir linuxprobe [root@linuxprobe ~]# cd linuxprobe [root@linuxprobe linuxprobe]# mkdir -p a/b/c/d/e [root@linuxprobe linuxprobe]# cd a [root@linuxprobe a]# cd b [root@linuxprobe b]#
cp 命令
cp 命令用於複製檔案或目錄,格式為“cp [選項] 原始檔 目標檔案”。 -p 保留原始檔案的屬性 -d 若物件為“連結檔案”,則保留該“連結檔案”的屬性 -r 遞迴持續複製(用於目錄) -i 若目標檔案存在則詢問是否覆蓋 -a 相當於-pdr(p、d、r 為上述引數) [root@linuxprobe ~]# touch install.log [root@linuxprobe ~]# cp install.log x.log [root@linuxprobe ~]# ls install.log x.log
mv 命令
mv 命令用於剪下檔案或將檔案重新命名,格式為“mv [選項] 原始檔 [目標路徑|目標檔名]” [root@linuxprobe ~]# mv x.log linux.log [root@linuxprobe ~]# ls install.log linux.log
rm 命令
rm 命令用於刪除檔案或目錄,格式為“rm [選項] 檔案”。 [root@linuxprobe ~]# rm install.log rm: remove regular empty file ‘install.log’? y [root@linuxprobe ~]# rm -f linux.log [root@linuxprobe ~]# ls [root@linuxprobe ~]#
dd 命令
dd 命令用於按照指定大小和個數的資料塊來複制檔案或轉換檔案,格式為“dd [引數]”。 if 輸入的檔名稱 of 輸出的檔名稱 bs 設定每個“塊”的大小 count 設定要複製“塊”的個數 [root@linuxprobe ~]# dd if=/dev/zero of=560_file count=1 bs=560M 1+0 records in 1+0 records out 587202560 bytes (587 MB) copied, 27.1755 s, 21.6 MB/s [root@linuxprobe ~]# dd if=/dev/cdrom of=RHEL-server-7.0-x86_64-LinuxProbe.Com.iso 7311360+0 records in 7311360+0 records out 3743416320 bytes (3.7 GB) copied, 370.758 s, 10.1 MB/s
file 命令
file 命令用於檢視檔案的型別,格式為“file 檔名” [root@linuxprobe ~]# file anaconda-ks.cfg anaconda-ks.cfg: ASCII text [root@linuxprobe ~]# file /dev/sda /dev/sda: block special
tar 命令
-c 建立壓縮檔案 -x 解開壓縮檔案 -t 檢視壓縮包內有哪些檔案 -z 用 Gzip 壓縮或解壓 -j 用 bzip2 壓縮或解壓 -v 顯示壓縮或解壓的過程 -f 目標檔名 -p 保留原始的許可權與屬性 -P 使用絕對路徑來壓縮 -C 指定解壓到的目錄 [root@linuxprobe ~]# tar -czvf etc.tar.gz /etc [root@linuxprobe ~]# tar xzvf etc.tar.gz -C /root/etc
grep 命令
grep 命令用於在文字中執行關鍵詞搜尋,並顯示匹配的結果,格式為“grep [選項] [檔案]”。 -b 將可執行檔案(binary)當作文字檔案(text)來搜尋 -c 僅顯示找到的行數 -i 忽略大小寫 -n 顯示行號 -v 反向選擇—僅列出沒有“關鍵詞”的行 [root@linuxprobe ~]# grep /sbin/nologin /etc/passwd
find 命令
find 命令用於按照指定條件來查詢檔案,格式為“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@linuxprobe ~]# find /etc -name "host*" -print [root@linuxprobe ~]# find / -perm -4000 -print