Linux命令行吸引了大多數Linux愛好者。一個正常的Linux用戶通常掌握大約
50-60個命令來處理每日的任務。Linux命令和它們的轉換對於Linux用戶、Shell腳本程序員和管理員來講是最有價值的寶藏。有些Linux命令不多人知道,但無論你是新手仍是高級用戶,它們都很是方便有用。
![](http://static.javashuo.com/static/loading.gif)
少有人知道的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 !!
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
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
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 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保持收看。喜歡和分享將有助於咱們傳播。 原文地址:
http://www.tecmint.com/11-lesser-known-useful-linux-commands/