Linux中國

Linux 命令行簡介

如果你是 Linux 新手,或者從來沒有花時間研究過命令行,你可能不會理解為什麼這麼多 Linux 愛好者坐在舒適的桌面前興奮地輸入命令來使用大量工具和應用。在這篇文章中,我們將快速瀏覽一下命令行的奇妙之處,看看能否讓你著迷。

首先,要使用命令行,你必須打開一個命令工具(也稱為「命令提示符」)。如何做到這一點將取決於你運行的 Linux 版本。例如,在 RedHat 上,你可能會在屏幕頂部看到一個 「Activities」 選項卡,它將打開一個選項列表和一個用於輸入命令的小窗口(類似 「cmd」 為你打開的窗口)。在 Ubuntu 和其他一些版本中,你可能會在屏幕左側看到一個小的終端圖標。在許多系統上,你可以同時按 Ctrl+Alt+t 鍵打開命令窗口。

如果你使用 PuTTY 之類的工具登錄 Linux 系統,你會發現自己已經處於命令行界面。

一旦你得到你的命令行窗口,你會發現自己坐在一個提示符面前。它可能只是一個 $ 或者像 user@system:~$ 這樣的東西,但它意味著系統已經準備好為你運行命令了。

一旦你走到這一步,就應該開始輸入命令了。下面是一些要首先嘗試的命令,以及這裡是一些特別有用的命令的 PDF 和適合列印和做成卡片的雙面命令手冊。

命令 用途
pwd 顯示我在文件系統中的位置(在最初進入系統時運行將顯示主目錄)
ls 列出我的文件
ls -a 列出我更多的文件(包括隱藏文件)
ls -al 列出我的文件,並且包含很多詳細信息(包括日期、文件大小和許可權)
who 告訴我誰登錄了(如果只有你,不要失望)
date 日期提醒我今天是星期幾(也顯示時間)
ps 列出我正在運行的進程(可能只是你的 shell 和 ps 命令)

一旦你從命令行角度習慣了 Linux 主目錄之後,就可以開始探索了。也許你會準備好使用以下命令在文件系統中閑逛:

命令 用途
cd /tmp 移動到其他文件夾(本例中,打開 /tmp 文件夾)
ls 列出當前位置的文件
cd 回到主目錄(不帶參數的 cd 總是能將你帶回到主目錄)
cat .bashrc 顯示文件的內容(本例中顯示 .bashrc 文件的內容)
history 顯示最近執行的命令
echo hello 跟自己說 「hello」
cal 顯示當前月份的日曆

要了解為什麼高級 Linux 用戶如此喜歡命令行,你將需要嘗試其他一些功能,例如重定向和管道。「重定向」是當你獲取命令的輸出並將其放到文件中而不是在屏幕上顯示時。「管道」是指你將一個命令的輸出發送給另一條將以某種方式對其進行操作的命令。這是可以嘗試的命令:

命令 用途
echo "echo hello" > tryme 創建一個新的文件並將 「echo hello」 寫入該文件
chmod 700 tryme 使新建的文件可執行
tryme 運行新文件(它應當運行文件中包含的命令並且顯示 「hello」 )
ps aux 顯示所有運行中的程序
ps aux | grep $USER 顯示所有運行中的程序,但是限制輸出的內容包含你的用戶名
echo $USER 使用環境變數顯示你的用戶名
whoami 使用命令顯示你的用戶名
who | wc -l 計數所有當前登錄的用戶數目

總結

一旦你習慣了基本命令,就可以探索其他命令並嘗試編寫腳本。 你可能會發現 Linux 比你想像的要強大並且好用得多.

via: https://www.networkworld.com/article/3518440/intro-to-the-linux-command-line.html

作者:Sandra Henry-Stocker 選題:lujun9972 譯者:qianmingtian 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    5 Comments

    1. 350fairfax nordvpn coupon
      You can definitely see your skills within the article you write.
      The arena hopes for more passionate writers like
      you who are not afraid to say how they believe.
      At all times go after your heart.

    2. Hi, I think your website might be having browser compatibility issues.
      When I look at your website in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping.
      I just wanted to give you a quick heads up!
      Other then that, excellent blog!

      Look at my page: Nordvpn Coupons Inspiresensation

    3. It’s awesome to pay a visit this web site and reading the views of
      all friends regarding this article, while I am also zealous of
      getting know-how.

      Here is my web blog; nordvpn coupons inspiresensation (t.co)

    4. Its such as you read my mind! You seem to grasp a lot approximately this, like you wrote the guide in it or
      something. I feel that you could do with a few p.c.
      to drive the message house a little bit, but instead
      of that, that is great blog. A great read.
      I’ll certainly be back.

      my webpage: nordvpn coupons inspiresensation

    5. Superb blog! Do you have any tips and hints for aspiring writers?
      I’m hoping to start my own blog soon but I’m a little lost on everything.

      Would you propose starting with a free platform like WordPress or go
      for a paid option? There are so many options out there that I’m totally overwhelmed
      .. Any ideas? Thanks!

      Here is my web-site: nordvpn coupons inspiresensation (https://t.co/eVysfVwFqe)

    Leave a reply

    您的郵箱地址不會被公開。 必填項已用 * 標註

    這個站點使用 Akismet 來減少垃圾評論。了解你的評論數據如何被處理

    More in:Linux中國