歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> 11 個很有用但鮮有人知的 linux 命令

11 個很有用但鮮有人知的 linux 命令

日期:2017/3/2 16:29:29   编辑:Linux服務器

  Linux命令行吸引了大多數Linux愛好者。一個正常的Linux用戶一般掌握大約50-60個命令來處理每日的任務。Linux命令和它們的 轉換對於Linux用戶、Shell腳本程序員和管理員來說是最有價值的寶藏。有些Linux命令很少人知道,但不管你是新手還是高級用戶,它們都非常方 便有用。

11 個很有用但鮮有人知的 linux 命令 三聯

  少有人知道的Linux命令

  這篇文章的目的是介紹一些少有人知的Linux命令,它們一定會高效地幫你管理你的桌面/服務器。

  1. sudo !!命令

  沒有特定輸入sudo命令而運行,將給出沒有權限的錯誤。那麼,你不需要重寫整個命令,僅僅輸入'!!'就可以抓取最後的命令。

  $ apt-get update

  E: Could not open lock file /var/lib/apt/lists/lock - open(13: Permission denied)

  E: Unable to lock directory /var/lib/apt/lists/

  E: Could not open lock file /var/lib/dpkg/lock - open(13: Permission denied)

  E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

  $ sudo !!

  sudoapt-get update

  [sudo] password forserver:

  …

  ..

  Fetched 474 kB in16s (28.0 kB/s)

  Reading package lists... Done

  server@localhost:~$

  2. python命令

  下面的命令生產一個通過HTTP顯示文件夾結構樹的簡單網頁,可以通過浏覽器在端口8000訪問,直到發出中斷信號。

  # python -m SimpleHTTPServer

11 個很有用但鮮有人知的 linux 命令

  3. mtr命令

  我們大多數都熟悉ping和traceroute。那對於把兩個命令的功能合二為一的mtr命令呢。如果mtr沒在你的機子上安裝,apt或者yum需要的包。

  $ sudo apt-get install mtr (On Debian based Systems)

  # yum install mtr (On Red Hat based Systems)

  現在運行mtr命令,開始查看mtr運行的主機和google.com直接的網絡連接。

  # mtr google.com

11 個很有用但鮮有人知的 linux 命令

  mtr命令

  4. Ctrl+x+e命令

  這個命令對於管理員和開發者非常有用。為了使每天的任務自動化,管理員需要通過輸入vi、vim、nano等打開編輯器。

  僅僅從命令行快速的敲擊“Ctrl-x-e”,就可以在編輯器中開始工作了。

  5. nl命令

  “nl命令”添加文件的行數。一個叫做'one.txt'的文件,其每行的內容是(Fedora、Debian、Arch、Slack和Suse),給每行添加行號。首先使用cat命令顯示“one.txt”的文件內容。

  # cat one.txt

  fedora

  debian

  arch

  slack

  suse

  現在運行“nl命令”,以添加行號的方式來顯示。

  # nl one.txt

  1 fedora

  2 debian

  3 arch

  4 slack

  5 suse

  6. shuf命令

  “Shut”命令隨機從一個文件或文件夾中選擇行/文件/文件夾。首先使用ls命令來顯示文件夾的內容。

  # ls

  Desktop Documents Downloads Music Pictures Public Templates Videos

  # ls | shuf (shuffle in put)

  Music

  Documents

  Templates

  Pictures

  Public

  Desktop

  Downloads

  Videos

  # ls | shuf -n1 (pick on random selection)

  Public

  # ls | shuf -n1

  Videos

  # ls | shuf -n1

  Templates

  # ls | shuf -n1

  Downloads

  注意:你可以把‘ n1’替換成‘ n2’來輸出兩個隨機選擇或者使用 n3、 n4等數字輸出其他任意的隨機選擇。

  7. ss命令

  “ss”表示socket統計。這個命令調查socket,顯示類似netstat命令的信息。它可以比其他工具顯示更多的TCP和狀態信息。

  # ss

  State Recv-Q Send-Q Local Address:Port Peer Address:Port

  ESTAB 0 0 192.168.1.198:41250 *.*.*.*:http

  CLOSE-WAIT 1 0 127.0.0.1:8000 127.0.0.1:41393

  ESTAB 0 0 192.168.1.198:36239 *.*.*.*:http

  ESTAB 310 0 127.0.0.1:8000 127.0.0.1:41384

  ESTAB 0 0 192.168.1.198:41002 *.*.*.*:http

  ESTAB 0 0 127.0.0.1:41384 127.0.0.1:8000

  8. last命令

  “last”命令顯示的是上次登錄用戶的歷史信息。這個命令通過搜索文件“/var/log/wtmp”,顯示logged-in和logged-out及其tty‘s的用戶列表。

  # last

  server pts/0 :0 Tue Oct 22 12:03 still logged in

  server tty8 :0 Tue Oct 22 12:02 still logged in

  …

  ...

  (unknown tty8 :0 Tue Oct 22 12:02 - 12:02 (00:00)

  server pts/0 :0 Tue Oct 22 10:33 - 12:02 (01:29)

  server tty7 :0 Tue Oct 22 10:05 - 12:02 (01:56)

  (unknown tty7 :0 Tue Oct 22 10:04 - 10:05 (00:00)

  reboot system boot 3.2.0-4-686-pae Tue Oct 22 10:04 - 12:44 (02:39)

  wtmp begins Fri Oct 4 14:43:17 2007

  9. curl ifconfig.me

  那麼如何得到你的外部IP地址呢?使用google?那麼這個命令就在你的終端輸出你的外部IP地址。

  # curl ifconfig.me

  注意:你可能沒有按照curl包,你需要 apt/yum來按照包。

  10. tree命令

  以樹式的格式得到當前文件夾的結構。

11 個很有用但鮮有人知的 linux 命令

  11. pstree

  這個命令顯示當前運行的所有進程及其相關的子進程,輸出的是類似‘tree’命令的樹狀格式

11 個很有用但鮮有人知的 linux 命令

Copyright © Linux教程網 All Rights Reserved