這篇文章主要為大家分享Linux常用命令的介紹和使用。文中還介紹了linux使用命令對(duì)目錄和文件的基本操作,希望大家通過(guò)這篇文章能有所收獲。
目前成都創(chuàng)新互聯(lián)已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、尖山網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
命令字 [選項(xiàng)] [參數(shù)]
命令字:命令字是唯一的,嚴(yán)格區(qū)分大小寫;
選項(xiàng):用于調(diào)節(jié)命令的具體功能,可以有一個(gè)或者多個(gè)選項(xiàng),選項(xiàng)分為短格式和長(zhǎng)格式,“-”表示短格式,例如“l(fā)s -a”;“--”表示長(zhǎng)格式,例如“l(fā)s --help”;
- 參數(shù):參數(shù)是命令處理的對(duì)象,例如文件、目錄名等;
用于實(shí)現(xiàn)某一類功能的指令或程序,命令的執(zhí)行依賴于解釋器程序(例如:/bin/bash)。
集成在bash中,安裝Linux系統(tǒng)自帶,不需要對(duì)應(yīng)文件,執(zhí)行速度快,屬于shell解釋器的一部分。
獨(dú)立于shell解釋器之外的程序,安裝程序或者服務(wù)生成命令,需要對(duì)應(yīng)到系統(tǒng)文件中,執(zhí)行速度慢。
自動(dòng)補(bǔ)全命令
[root@centos01 ~]# whi <!--輸入前三個(gè)字符按Tab鍵自動(dòng)補(bǔ)全-->
which while whiptail
強(qiáng)制換行
[root@centos01 ~]# user\
> add bob <!--強(qiáng)制換行創(chuàng)建bob用戶-->
[root@centos01 ~]# tail -2 /etc/passwd <!--驗(yàn)證是否創(chuàng)建成功-->
test:x:1000:1000:test:/home/test:/bin/bash
bob:x:1001:1001::/home/bob:/bin/bash
清空至行首
[root@centos01 ~]# useradd
[root@centos01 ~]# eradd <!--將光標(biāo)移至e字符執(zhí)行Ctrl+u清空至行首-->
清空至行尾
[root@centos01 ~]# useradd
[root@centos01 ~]# use <!--將光標(biāo)移至e字符執(zhí)行Ctrl+k清空至行尾-->
清空屏幕內(nèi)容
取消本次命令編輯
[root@centos01 ~]# tail -2 /etc/passwd^C
[root@centos01 ~]#
查看Bash內(nèi)部命令的幫助信息
[root@centos01 ~]# help pwd
pwd: pwd [-LP]
打印當(dāng)前工作目錄的名字。
選項(xiàng):
-L 打印 $PWD 變量的值,如果它命名了當(dāng)前的
工作目錄
-P 打印當(dāng)前的物理路徑,不帶有任何的符號(hào)鏈接
默認(rèn)情況下,`pwd' 的行為和帶 `-L' 選項(xiàng)一致
退出狀態(tài):
除非使用了無(wú)效選項(xiàng)或者當(dāng)前目錄不可讀,否則
返回狀態(tài)為0
適用于大多數(shù)外部命令。
[root@centos01 ~]# vim --help
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 2 2017 00:45:39)
用法: vim [參數(shù)] [文件 ..] 編輯指定的文件
或: vim [參數(shù)] - 從標(biāo)準(zhǔn)輸入(stdin)讀取文本
或: vim [參數(shù)] -t tag 編輯 tag 定義處的文件
或: vim [參數(shù)] -q [errorfile] 編輯第一個(gè)出錯(cuò)處的文件
參數(shù):
-- 在這以后只有文件名
-v Vi 模式 (同 "vi")
-e Ex 模式 (同 "ex")
-E Improved Ex mode
-s 安靜(批處理)模式 (只能與 "ex" 一起使用)
-d Diff 模式 (同 "vimdiff")
-y 容易模式 (同 "evim",無(wú)模式)
-R 只讀模式 (同 "view")
-Z 限制模式 (同 "rvim")
-m 不可修改(寫入文件)
-M 文本不可修改
-b 二進(jìn)制模式
-l Lisp 模式
-C 兼容傳統(tǒng)的 Vi: 'compatible'
-N 不完全兼容傳統(tǒng)的 Vi: 'nocompatible'
-V[N][fname] Be verbose [level N] [log messages to fname]
-D 調(diào)試模式
-n 不使用交換文件,只使用內(nèi)存
-r 列出交換文件并退出
-r (跟文件名) 恢復(fù)崩潰的會(huì)話
-L 同 -r
-A 以 Arabic 模式啟動(dòng)
-H 以 Hebrew 模式啟動(dòng)
-F 以 Farsi 模式啟動(dòng)
-T <terminal> 設(shè)定終端類型為 <terminal>
-u <vimrc> 使用 <vimrc> 替代任何 .vimrc
--noplugin 不加載 plugin 腳本
-P[N] 打開 N 個(gè)標(biāo)簽頁(yè) (默認(rèn)值: 每個(gè)文件一個(gè))
-o[N] 打開 N 個(gè)窗口 (默認(rèn)值: 每個(gè)文件一個(gè))
-O[N] 同 -o 但垂直分割
+ 啟動(dòng)后跳到文件末尾
+<lnum> 啟動(dòng)后跳到第 <lnum> 行
--cmd <command> 加載任何 vimrc 文件前執(zhí)行 <command>
-c <command> 加載第一個(gè)文件后執(zhí)行 <command>
-S <session> 加載第一個(gè)文件后執(zhí)行文件 <session>
-s <scriptin> 從文件 <scriptin> 讀入正常模式的命令
-w <scriptout> 將所有輸入的命令追加到文件 <scriptout>
-W <scriptout> 將所有輸入的命令寫入到文件 <scriptout>
-x 編輯加密的文件
--startuptime <file> Write startup timing messages to <file>
-i <viminfo> 使用 <viminfo> 取代 .viminfo
-h 或 --help 打印幫助(本信息)并退出
--version 打印版本信息并退出
使用“?”、“?”方向鍵滾動(dòng)文本,使用page Up和page Down鍵翻頁(yè),按Q或q鍵退出閱讀環(huán)境、按“/”鍵查找內(nèi)容。
[root@centos01 ~]# man pwd
PWD(1) FSF PWD(1)
NAME
pwd - 顯示出當(dāng)前/活動(dòng)目錄的名稱
總覽 (SYNOPSIS)
pwd [OPTION]
描述 (DESCRIPTION)
顯示出 完整的 當(dāng)前 活動(dòng)目錄 名稱.
--help 顯示 幫助 信息, 然后 退出
--version
顯示 版本 信息, 然后 退出
報(bào)告 BUGS
發(fā)現(xiàn)的 bug 寄往 <bug-sh-utils@gnu.org>.
另見 (SEE ALSO)
Pwd 的 完整文檔 以 Texinfo 手冊(cè) 的 形式 維護(hù). 如果 正確 安裝了 info 和 pwd 文件, 用 命令
info pwd
可以 訪問(wèn) 完整 的 手冊(cè).
版權(quán) (COPYRIGHT)
Copyright ? 1999 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FIT‐
NESS FOR A PARTICULAR PURPOSE.
[中文版維護(hù)人]
徐明 <xuming@users.sourceforge.net>
[中文版最新更新]
2003/05/13
《中國(guó)Linux論壇man手冊(cè)頁(yè)翻譯計(jì)劃》
http://cmpp.linuxforum.net
ls命令選項(xiàng)
-l:以長(zhǎng)格式顯示文件和目錄的列表;
-a:顯示所有子目錄和文件的信息;
-A:與-a選項(xiàng)的作用基本類似,但有兩個(gè)特殊隱藏目錄不會(huì)顯示,“.”和“..”;
-d:顯示目錄本身的屬性,而不是顯示目錄中的內(nèi)容;
-h:以更人性化的方式顯示出目錄或文件的大小,此選項(xiàng)需要結(jié)合-l選項(xiàng)一起使用;
-R:以遞歸的方式顯示指定目錄及其子目錄中的所有內(nèi)容;
- --color:顯示顏色;
應(yīng)用舉例:
[root@centos01 ~]# ls -l /
總用量 102428
-rw-r--r-- 1 root root 104857600 1月 9 21:42 1.iso
drwxr-xr-x 3 root root 18 1月 9 21:22 benet
lrwxrwxrwx. 1 root root 7 10月 23 22:29 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 10月 23 22:37 boot
drwxr-xr-x 18 root root 3140 1月 9 21:00 dev
[root@centos01 ~]# ls -ld / <!--長(zhǎng)格式查看根的屬性-->
dr-xr-xr-x. 19 root root 269 1月 9 21:31 /
[root@centos01 ~]# ls -ld /test/yun/benet/1.txt <!--長(zhǎng)格式查看文件屬性-->
-rw-r--r-- 1 root root 0 1月 9 21:40 /test/yun/benet/1.txt
[root@centos01 benet]# dd if=/dev/zero of=./1.iso bs=10M count=10 <!--創(chuàng)建測(cè)試數(shù)據(jù)-->
記錄了10+0 的讀入
記錄了10+0 的寫出
104857600字節(jié)(105 MB)已復(fù)制,1.13446 秒,92.4 MB/秒
[root@centos01 benet]# ls -lh ./1.iso
<!--長(zhǎng)格式顯示文件屬性;以KB或者M(jìn)顯示文件大小-->
-rw-r--r-- 1 root root 100M 1月 9 21:43 ./1.iso
[root@centos01 ~]# ls -lhR /test/ <!--遞歸顯示目錄中包含的子文件大小-->
/test/:
總用量 0
drwxr-xr-x 3 root root 19 1月 9 21:31 yun
/test/yun:
總用量 0
drwxr-xr-x 2 root root 84 1月 9 21:43 benet
/test/yun/benet:
總用量 100M
-rw-r--r-- 1 root root 100M 1月 9 21:43 1.iso
-rw-r--r-- 1 root root 0 1月 9 21:40 1.txt
-rw-r--r-- 1 root root 0 1月 9 21:40 2.txt
-rw-r--r-- 1 root root 0 1月 9 21:40 3.txt
-rw-r--r-- 1 root root 0 1月 9 21:40 4.txt
-rw-r--r-- 1 root root 0 1月 9 21:40 5.txt
用于統(tǒng)計(jì)指定目錄(或)文件所占磁盤空間的大小,du命令常用的幾個(gè)選項(xiàng)如下:
-a:統(tǒng)計(jì)磁盤空間占用時(shí)包括所有的文件,而不僅僅只統(tǒng)計(jì)目錄;
-h:以更人性化的方式(默認(rèn)以KB計(jì)數(shù),但不顯示單位)顯示出統(tǒng)計(jì)結(jié)果;
- -s:只統(tǒng)計(jì)所占用空間總的(Summary)大小,而不是統(tǒng)計(jì)每個(gè)子目錄,文件的大?。?/li>
應(yīng)用舉例:
[root@centos01 ~]# df -Th <!--統(tǒng)計(jì)磁盤大小-->
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點(diǎn)
/dev/sda3 xfs 76G 3.8G 72G 5% /
devtmpfs devtmpfs 474M 0 474M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 7.0M 482M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 136M 61M 70% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
[root@centos01 ~]# du -sh /var/log/
<!--統(tǒng)計(jì)所有文件總共占用的空間大小-->
4.9M /var/log/
[root@centos01 ~]# du -sh /test/ <!--統(tǒng)計(jì)目錄大小-->
100M /test/
[root@centos01 ~]# du -ah /test/yun/benet/1.iso<!--統(tǒng)計(jì)文件大小-->
100M /test/yun/benet/1.iso
touch命令用于創(chuàng)建空文件,用于測(cè)試,當(dāng)目標(biāo)文件已存在時(shí),將更新該文件的時(shí)間標(biāo)記。
應(yīng)用舉例:
[root@centos01 ~]# touch /test/1.iso <!--創(chuàng)建單個(gè)文件-->
[root@centos01 ~]# cd /test/
[root@centos01 test]# ls <!--驗(yàn)證-->
1.iso
[root@centos01 ~]# touch /test/{1..10}.txt <!--連續(xù)創(chuàng)建多個(gè)文件-->
[root@centos01 ~]#
[root@centos01 ~]# cd /test/
[root@centos01 test]# ls <!--驗(yàn)證創(chuàng)建的文件-->
10.txt 1.iso 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
mkdir命令用于創(chuàng)建新目錄,語(yǔ)法格式如下:
mkdir [選項(xiàng)] 目錄位置及名稱...
應(yīng)用舉例:
[root@centos01 ~]# mkdir www <!--創(chuàng)建目錄-->
[root@centos01 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg www
[root@centos01 ~]# mkdir -p /test/yun/benet <!--循環(huán)創(chuàng)建目錄-->
[root@centos01 ~]# cd /test/yun/benet/
[root@centos01 benet]# pwd
/test/yun/benet
復(fù)制文件或目錄,需要復(fù)制多個(gè)文件或目錄時(shí),目標(biāo)位置必須是目錄,而且目標(biāo)目錄必須以及存在。語(yǔ)法格式如下:
cp [選項(xiàng)]... 源文件或目錄... 目標(biāo)文件或目錄...
cp常用的選項(xiàng)如下:
-f:覆蓋目錄同名文件或目錄時(shí)不進(jìn)行提醒,直接強(qiáng)制復(fù)制;
-i:覆蓋目錄同名文件或目錄時(shí)提醒用戶確認(rèn);
-p:復(fù)制時(shí)保持源文件的權(quán)限,屬主及時(shí)間標(biāo)記等屬性不變;
- -r:復(fù)制目錄時(shí)必須使用此選項(xiàng),表示遞歸復(fù)制所有文件及子目錄;
應(yīng)用舉例:
[root@centos01 ~]# cp -r benet/ www/ <!--復(fù)制目錄到benet目錄中-->
[root@centos01 ~]# cp -rpf /test/ ./yun/
<!--循環(huán)復(fù)制/test目錄中的數(shù)據(jù)到當(dāng)前目錄yun中,
test目錄中的數(shù)據(jù)保持權(quán)限不變-->
rm命令用于刪除指定的文件或目錄,語(yǔ)法格式如下:
rm [選項(xiàng)] 要?jiǎng)h除的文件或目錄...
rm命令常用的選項(xiàng)如下:
-f:不提醒,直接強(qiáng)制刪除;
-i:提醒用戶確認(rèn);
- -r:遞歸刪除整個(gè)目錄樹;
應(yīng)用舉例:
[root@centos01 test]# ls
10.txt 1.iso 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt yun
[root@centos01 test]# rm -rf yun <!--不提醒遞歸刪除yun目錄-->
[root@centos01 test]# rm -rf ./*.iso
<!--不提醒遞歸刪除所有以*.iso結(jié)尾的文件-->
[root@centos01 test]# ls
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
[root@centos01 test]# rm -ri ./* <!--提醒用戶確認(rèn)刪除當(dāng)前目錄所有文件和目錄-->
rm:是否刪除普通空文件 "./10.txt"?y <!--輸入y確認(rèn)即可-->
rm:是否刪除普通空文件 "./1.txt"?y
............ <!--此處省略部分內(nèi)容-->
rm -rf命令極度危險(xiǎn),慎重操作?。?!
mv命令用于將指定的文件或目錄轉(zhuǎn)移位置,如果目標(biāo)位置與源位置相同,則相當(dāng)于執(zhí)行重命名操作。mv命令語(yǔ)法格式如下:
mv [選項(xiàng)]... 源文件或目錄... 目標(biāo)文件或目錄
應(yīng)用舉例:
[root@centos01 ~]# mv 1.mp3 /benet/bdqn/accp/xsh/
<!--將當(dāng)前目錄的1.mp3數(shù)據(jù)剪切到/benet/bdqn/accp/xsh/目錄-->
[root@centos01 xsh]# ls
1.mp3
[root@centos01 xsh]# mv 1.mp3 2.mp3 <!--將1.mp3重命名為2.mp3-->
[root@centos01 xsh]# ls
2.mp3
which命令用來(lái)查找Linux命令程序所在的位置,注意:默認(rèn)當(dāng)找到第一個(gè)目標(biāo)后不再繼續(xù)查找;若在所有搜素路徑中查找,加“-a”選項(xiàng);無(wú)法查找內(nèi)部命令所對(duì)應(yīng)的程序文件,例如:which cd。語(yǔ)法格式如下:
which 命令|程序名
應(yīng)用舉例:
[root@centos01 ~]# which passwd <!--查看passwd命令的位置-->
/usr/bin/passwd
[root@centos01 ~]# which -a groupadd <!--查看groupadd命令的位置-->
/usr/sbin/groupadd
find命令用來(lái)精細(xì)查找文件或目錄。基本語(yǔ)法格式如下:
find [查找范圍] [查找條件表達(dá)式]
find常用的查找條件如下:
-name:按名稱查找;根據(jù)目標(biāo)文件的名稱進(jìn)行查找,允許使用“*”及“?”通配符;
-size:按文件大小查找;一般使用“+”、“-”號(hào)設(shè)置超過(guò)或小于指定的大小作為查找條件。常用的容量單位包括kB(注意k是小寫)、MB、GB;
-user:按文件屬主查找;
- -type:按文件類型查找;類型指的是普通文件(f)、目錄(d)、塊設(shè)備文件(b)、字符設(shè)備文件(c)等。
同時(shí)使用多個(gè)查找條件時(shí),各表達(dá)式之間可以使用邏輯運(yùn)算符“-a”、“-o”,分別表示而且(and)、或者(or)。
應(yīng)用舉例:
[root@centos01 ~]# find /test/yun/benet/ -name *.txt
<!--查看/test/yun/benet/目錄下所有*.txt的文件-->
/test/yun/benet/1.txt
/test/yun/benet/2.txt
/test/yun/benet/3.txt
/test/yun/benet/4.txt
/test/yun/benet/5.txt
[root@centos01 ~]# find /test/yun/benet/ -type d
<!--查看/test/yun/benet/目錄中所有目錄-->
/test/yun/benet/
[root@centos01 ~]# find /test/yun/benet/ -type f
<!--查看/test/yun/benet/目錄中所有文件-->
/test/yun/benet/1.txt
/test/yun/benet/2.txt
/test/yun/benet/3.txt
/test/yun/benet/4.txt
/test/yun/benet/5.txt
/test/yun/benet/1.iso
[root@centos01 ~]# find /test/yun/benet/ -size +100M
<!--查看/test/yun/benet/目錄中大于100M的文件-->
/test/yun/benet/2.iso
[root@centos01 ~]# find /test/yun/benet/ -size -100M
<!--查看/test/yun/benet/目錄中小于100M的文件-->
/test/yun/benet/
/test/yun/benet/1.txt
/test/yun/benet/2.txt
/test/yun/benet/3.txt
/test/yun/benet/4.txt
/test/yun/benet/5.txt
[root@centos01 ~]# find /test/yun/benet/ -size +100M -a -name *.iso
<!--查看/test/yun/benet/目錄中大于100M和名字為*.iso的顯示出來(lái)-->
/test/yun/benet/2.iso
[root@centos01 ~]# find /test/yun/benet/ -size +100M -o -name *.iso
<!--查看/test/yun/benet/目錄中大于100M或者名字為*.iso的顯示出來(lái)-->
/test/yun/benet/1.iso
/test/yun/benet/2.iso
顯示日期的命令:
[root@centos01 ~]# date
2020年 01月 10日 星期五 22:05:54 CST
[root@centos01 ~]# date +%F
2020-01-10
[root@centos01 ~]# date +%Y/%m/%d
2020/01/10
[root@centos01 ~]# date +%H:%M
22:07
顯示日歷的命令:
[root@centos01 ~]# cal
一月 2020
日 一 二 三 四 五 六
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
[root@centos01 ~]# cal 22 11 1999
十一月 1999
日 一 二 三 四 五 六
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
關(guān)于Linux的常用命令就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
名稱欄目:Linux常用命令的介紹和使用
文章起源:http://www.rwnh.cn/article4/jgjioe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、、搜索引擎優(yōu)化、手機(jī)網(wǎng)站建設(shè)、服務(wù)器托管、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)