11 個很少人知道但很有用的 Linux 命令

來源:互聯網
上載者:User

  Linux命令列吸引了大多數Linux愛好者。 一個正常的Linux使用者一般掌握大約50-60個命令來處理每日的任務。 Linux命令和它們的轉換對於Linux使用者、Shell腳本程式師和管理員來說是最有價值的寶藏。 有些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: Una ble to lock directory /var/lib/apt/lists/
  E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denie d)
  E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
  $ sudo !!
  sudo apt-get update
  [sudo] password for server:
  ...
  ..
  Fetched 474 kB in 16s (28.0 kB/s)
  Reading package lists... Done
  server@localhost:~$
  2. python命令
  下面的命令生產一個通過HTTP顯示資料夾結構樹的簡單網頁,可以通過瀏覽器在埠HTTP://www.aliyun.com/ zixun/aggregation/37392.html">8000訪問,直到發出中斷信號。
  # python -m SimpleHTTPServer


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




  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命令


「Shuf」命令隨機從一個檔或資料夾中選擇行/檔/資料夾。 首先使用ls命令來顯示資料夾的內容。


  # ls


  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos


  #  ls | shuf (shuffle Input)


  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命令


  以樹式的格式得到當前資料夾的結構。


  # tree


  .


  |-- Desktop


  |-- Documents


  |  `-- 37.odt


  |-- Downloads


  |  |-- attachments.zip


  |  |-- ttf-indic-fonts_0.5.11_all.deb


|  |-- ttf-indic-fonts_1.1_all.deb


  |  `-- wheezy-nv-install.sh


  |-- Music


  |-- Pictures


  |  |-- Screenshot from 2013-10-22 12:03:49.png


  |  `-- Screenshot from 2013-10-22 12:12:38.png


  |-- Public


  |-- Templates


  `-- Videos


  10 directories, 23 files


  11. pstree


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


  # pstree


  init─┬─NetworkManager───{NetworkManager}


  ├─accounts-daemon───{accounts-daemon}


  ├─acpi_fakekeyd


  ├─acpid


  ├─apache2───10*[apache2]


  ├─at-spi-bus-laun───2*[{at-spi-bus-laun}]


  ├─atd


  ├─avahi-daemon───avahi-daemon


  ├─bluetoothd


  ├─colord───{colord}


  ├─colord-sane───2*[{colord-sane}]


  ├─console-kit-dae───64*[{console-kit-dae}]


  ├─cron


  ├─cupsd


  ├─2*[dbus-daemon]


  ├─dbus-launch


  ├─dconf-service───2*[{dconf-service}]


  ├─dovecot─┬─anvil


  │        ├─config


  │        └─log


  ├─exim4


  ├─gconfd-2


  ├─gdm3─┬─gdm-simple-slav─┬─Xorg


  │      │                ├─gdm-session-wor─┬─x-session-manag─┬─evolution-a+


  │      │                │                │                ├─gdu-notific+


│      │                │                │                ├─gnome-scree+


  │      │                │                │                ├─gnome-setti+


  │      │                │                │                ├─gnome-shell+++


  │      │                │                │                ├─nm-applet──+++


│      │                │                │                ├─ssh-agent


  │      │                │                │                ├─tracker-min+


  │      │                │                │                ├─tracker-sto+


  │      │                │                │                └─3*[{x-sessi+


│      │                │                └─2*[{gdm-session-wor}]


  │      │                └─{gdm-simple-slav}


  │      └─{gdm3}


  ├─6*[getty]


  ├─gnome-keyring-d───9*[{gnome-keyring-d}]


  ├─gnome-shell-cal───2*[{gnome-shell-cal}]


  ├─goa-daemon───{goa-daemon}


  ├─gsd-printer───{gsd-printer}


  ├─gvfs-afc-volume───{gvfs-afc-volume}


  目前為止就這麼多。 在下篇文章中,我將涉及一些其他很少有人知道的有趣的Linux命令。 到那時連接 Tecmint保持收看。 喜歡和分享將有助於我們傳播。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.