乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      理解 Linux 下 Shell 命令的不同分類及它們的用法

       孤獨(dú)一兵 2016-09-26

      當(dāng)你打算真正操縱好你的 Linux 系統(tǒng),沒有什么能比命令行界面更讓你做到這一點(diǎn)。為了成為一個(gè) Linux 高手,你必須能夠理解 Shell 命令的不同類型[1],并且會(huì)在終端下正確的使用它們。

      在 Linux 下,命令有幾種類型,對(duì)于一個(gè) Linux 新手來(lái)說(shuō),知道不同命令的意思才能夠高效和準(zhǔn)確的使用它們。因此,在這篇文章里,我們將會(huì)遍及各種不同分類的 Linux Shell 命令。

      需要注意一件非常重要的事:命令行界面和 Shell 是不同的,命令行界面只是為你提供一個(gè)訪問(wèn) Shell 的方式。而 Shell ,它是可編程的,這使得它可以通過(guò)命令與內(nèi)核進(jìn)行交流。

      理解 Linux 下 Shell 命令的不同分類及它們的用法

      下面列出了 Linux 下命令的不同種類:

      1. 程序可執(zhí)行文件(文件系統(tǒng) 中的命令)

      當(dāng)你執(zhí)行一條命令的時(shí)候,Linux 通過(guò)從左到右搜索存儲(chǔ)在 $PATH環(huán)境變量中的目錄來(lái)找到這條命令的可執(zhí)行文件。

      你可以像下面這樣查看存儲(chǔ)在 $PATH中的目錄:

      1. $ echo $PATH

      2. /home/aaronkilik/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

      在上面的命令中,目錄 /home/aaronkilik/bin將會(huì)被首先搜索,緊跟著是/usr/local/sbin,然后一直接著下去。在搜索過(guò)程中,搜索順序是至關(guān)重要的。

      比如在 /usr/bin目錄里的文件系統(tǒng)中的命令:

      1. $ ll /bin/

      示例輸出:

      1. total 16284

      2. drwxr-xr-x 2 root root 4096 Jul 31 16:30 ./

      3. drwxr-xr-x 23 root root 4096 Jul 31 16:29 ../

      4. -rwxr-xr-x 1 root root 6456 Apr 14 18:53 archdetect*

      5. -rwxr-xr-x 1 root root 1037440 May 17 16:15 bash*

      6. -rwxr-xr-x 1 root root 520992 Jan 20 2016 btrfs*

      7. -rwxr-xr-x 1 root root 249464 Jan 20 2016 btrfs-calc-size*

      8. lrwxrwxrwx 1 root root 5 Jul 31 16:19 btrfsck -> btrfs*

      9. -rwxr-xr-x 1 root root 278376 Jan 20 2016 btrfs-convert*

      10. -rwxr-xr-x 1 root root 249464 Jan 20 2016 btrfs-debug-tree*

      11. -rwxr-xr-x 1 root root 245368 Jan 20 2016 btrfs-find-root*

      12. -rwxr-xr-x 1 root root 270136 Jan 20 2016 btrfs-image*

      13. -rwxr-xr-x 1 root root 249464 Jan 20 2016 btrfs-map-logical*

      14. -rwxr-xr-x 1 root root 245368 Jan 20 2016 btrfs-select-super*

      15. -rwxr-xr-x 1 root root 253816 Jan 20 2016 btrfs-show-super*

      16. -rwxr-xr-x 1 root root 249464 Jan 20 2016 btrfstune*

      17. -rwxr-xr-x 1 root root 245368 Jan 20 2016 btrfs-zero-log*

      18. -rwxr-xr-x 1 root root 31288 May 20 2015 bunzip2*

      19. -rwxr-xr-x 1 root root 1964536 Aug 19 2015 busybox*

      20. -rwxr-xr-x 1 root root 31288 May 20 2015 bzcat*

      21. lrwxrwxrwx 1 root root 6 Jul 31 16:19 bzcmp -> bzdiff*

      22. -rwxr-xr-x 1 root root 2140 May 20 2015 bzdiff*

      23. lrwxrwxrwx 1 root root 6 Jul 31 16:19 bzegrep -> bzgrep*

      24. -rwxr-xr-x 1 root root 4877 May 20 2015 bzexe*

      25. lrwxrwxrwx 1 root root 6 Jul 31 16:19 bzfgrep -> bzgrep*

      26. -rwxr-xr-x 1 root root 3642 May 20 2015 bzgrep*

      2. Linux 別名

      這些是用戶定義的命令,它們是通過(guò) shell 內(nèi)置命令 alias創(chuàng)建的,其中包含其它一些帶有選項(xiàng)和參數(shù)的 shell 命令。這個(gè)意圖主要是使用新穎、簡(jiǎn)短的名字來(lái)替代冗長(zhǎng)的命令。

      創(chuàng)建一個(gè)別名的語(yǔ)法像下面這樣:

      1. $ alias newcommand='command -options'

      通過(guò)下面的命令,可以列舉系統(tǒng)中的所有別名:

      1. $ alias -p

      2. alias alert='notify-send --urgency=low -i '$([ $? = 0 ] && echo terminal || echo error)' '$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')''

      3. alias egrep='egrep --color=auto'

      4. alias fgrep='fgrep --color=auto'

      5. alias grep='grep --color=auto'

      6. alias l='ls -CF'

      7. alias la='ls -A'

      8. alias ll='ls -alF'

      9. alias ls='ls --color=auto'

      要在 Linux 中創(chuàng)建一個(gè)新的別名,仔細(xì)閱讀下面的例子。

      1. $ alias update='sudo apt update'

      2. $ alias upgrade='sudo apt dist-upgrade'

      3. $ alias -p | grep 'up'

      理解 Linux 下 Shell 命令的不同分類及它們的用法

      然而,上面這些我們創(chuàng)建的別名只能暫時(shí)的工作,當(dāng)經(jīng)過(guò)下一次系統(tǒng)啟動(dòng)后它們不再工作。你可以像下面展示的這樣在 '.bashrc' 文件中設(shè)置永久別名。

      理解 Linux 下 Shell 命令的不同分類及它們的用法

      添加以后,運(yùn)行下面的命令來(lái)激活:

      1. $ source ~/.bashrc

      3. Linux Shell 保留字

      在 shell 程序設(shè)計(jì)中,if、then、fi、for、whilecase、esac、elseuntil以及其他更多的字都是 shell 保留字。正如描述所暗示的,它們?cè)?shell 中有特殊的含義。

      你可以通過(guò)使用下面展示的 type命令來(lái)列出所有的 shell 關(guān)鍵字:

      1. $ type if then fi for while case esac else until

      2. if is a shell keyword

      3. then is a shell keyword

      4. fi is a shell keyword

      5. for is a shell keyword

      6. while is a shell keyword

      7. case is a shell keyword

      8. esac is a shell keyword

      9. else is a shell keyword

      10. until is a shell keyword

      4. Linux shell 函數(shù)

      一個(gè) shell 函數(shù)是一組在當(dāng)前 shell 內(nèi)一起執(zhí)行的命令。函數(shù)有利于在 shell 腳本中實(shí)現(xiàn)特殊任務(wù)。在 shell 腳本中寫 shell 函數(shù)的傳統(tǒng)形式是下面這樣:

      1. function_name {

      2. command1

      3. command2

      4. ......

      5. }

      或者像這樣:

      1. function function_name {

      2. command1

      3. command2

      4. ......

      5. }

      讓我們看一看如何在一個(gè)名為 shell_functions.sh 的腳本中寫 shell 函數(shù)。

      1. #!/bin/bash

      2. #write a shell function to update and upgrade installed packages

      3. upgrade_system{

      4. sudo apt update;

      5. sudo apt dist-upgrade;

      6. }

      7. #execute function

      8. upgrade_system

      取代通過(guò)命令行執(zhí)行兩條命令:sudo apt updatesudo apt dist-upgrade,我們?cè)谀_本內(nèi)寫了一個(gè)像執(zhí)行一條單一命令一樣來(lái)執(zhí)行兩條命令的 shell 函數(shù) upgrade_system。

      保存文件,然后使腳本可執(zhí)行。最后像下面這樣運(yùn)行 shell 函數(shù):

      1. $ chmod +x shell_functions.sh

      2. $ ./shell_functions.sh

      理解 Linux 下 Shell 命令的不同分類及它們的用法

      5. Linux Shell 內(nèi)置命令

      這些是在 shell 中內(nèi)置的 Linux 命令,所以你無(wú)法在文件系統(tǒng)中找到它們。這些命令包括pwdcd、bg、aliashistory、type、source、readexit等。

      你可以通過(guò)下面展示的 type命令來(lái)列出或檢查 Linux 內(nèi)置命令:

      1. $ type pwd

      2. pwd is a shell builtin

      3. $ type cd

      4. cd is a shell builtin

      5. $ type bg

      6. bg is a shell builtin

      7. $ type alias

      8. alias is a shell builtin

      9. $ type history

      10. history is a shell builtin

      學(xué)習(xí)一些 Linux 內(nèi)置命令用法:

      結(jié)論

      作為一個(gè) Linux 用戶,知道你所運(yùn)行的命令類型是很重要的。我相信,通過(guò)上面明確、簡(jiǎn)單并且易于理解的解釋,包括一些相關(guān)的說(shuō)明,你可能對(duì) “Linux 命令的不同種類[5]”有了很好的理解。

      你也可以在下面的評(píng)論區(qū)提任何問(wèn)題或補(bǔ)充意見,從而和我們?nèi)〉寐?lián)系。

      作者:Aaron Kili [6] 譯者:ucasFL校對(duì):wxy

      本文由 LCTT[7] 原創(chuàng)編譯,Linux中國(guó)榮譽(yù)推出

      [1]: http://www./different-types-of-linux-shells/

      [2]: http://www./pwd-command-examples/

      [3]: http://www./cd-command-in-linux/

      [4]: http://www./history-command-examples/

      [5]: http://www./different-types-of-linux-shells/

      [6]: http://www./author/aaronkili/

      [7]: https://github.com/LCTT/TranslateProject

      推薦文章

      將文章分享給朋友是對(duì)我們最好的贊賞!

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多