11個常用的Linux命令

來源:互聯網
上載者:User

 

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 !!

 

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顯示檔案夾結構樹的簡單網頁,可以通過瀏覽器在連接埠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
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直接的網路連接。
代碼如下: www.jbxue.com
# mtr google.com

這個命令對於管理員和開發人員非常有用。為了使每天的任務自動化,管理員需要通過輸入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 Input)

Music 
Documents 
Templates 
Pictures 
Public 
Desktop 
Downloads 
Videos
#  ls | shuf -n1 (pick on random selection)

Public www.jbxue.com
# 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}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.