Linux中國

十個鮮為人知的 Linux 命令 – Part 3

我們繼續「10個鮮為人知Linux命令系列」的第三部分。或許你已經知道了這些命令,那你無疑是一個有經驗而喜歡探索的Linux用戶。

22. ^foo^bar 命令

在一個實例中運行修改後的最後一個命令。假設我需要運行一個命令『ls -l『來詳細列出『Desktop』目錄下的內容。意外地,你打了『lls -l『。所以你需要重新打整個命令或者使用導航鍵編輯前面的命令。當你的命令很長時這個很痛苦。

avi@localhost:~/Desktop$ lls -l 
bash: lls: command not found

avi@localhost:~/Desktop$ ^lls^ls 

ls -l 
total 7489440 

drwxr-xr-x 2 avi  avi       36864 Nov 13  2012 101MSDCF 
-rw-r--r-- 1 avi  avi      206833 Nov  5 15:27 1.jpg 
-rw-r--r-- 1 avi  avi      158951 Nov  5 15:27 2.jpg 
-rw-r--r-- 1 avi  avi       90624 Nov  5 12:59 Untitled 1.doc

注意:在上面的替換中我們使用「 typo(被替換的) original_command(原始命令) 」。警告!這個命令可能會非常危險!如果你有意或者無意地打錯了系統命令或者任何像rm -rf那樣的風險命令的話!

23. > file.txt 命令

這個命令會刷新文件的內容而不需刪除然後創建相同的文件。當我們需要反覆輸出,或者在相同的文件上記錄日誌時,這個命令就非常有用。

我有一個有很多文字的『test.txt』文件在我的『Desktop『上。

avi@localhost:~/Desktop$ cat test.txt 

Linux 
GNU 
Debian 
Fedora 
kali 
ubuntu 
git 
Linus 
Torvalds

avi@localhost:~/Desktop$ > test.txt 
avi@localhost:~/Desktop$ cat test.txt

注意:再說一次,這個命令可能很危險!永遠不要嘗試刷新系統文件或者某篇日誌文件的內容。如果你這麼做了,你可能會遭遇嚴重的問題!

24. at 命令

at『命令與cron 命令相似也可用於安排一個任務或者在某個特定時刻執行命令。

avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" | at 14:012

avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" | at 2:12 PM

示例輸出

-rw-r--r-- 1 avi  avi      220492 Nov  1 13:49 Screenshot-1.png 
-rw-r--r-- 1 root root        358 Oct 17 10:11 sources.list 
-rw-r--r-- 1 avi  avi  4695982080 Oct 10 20:29 squeeze.iso 
..
..
-rw-r--r-- 1 avi  avi       90624 Nov  5 12:59 Untitled 1.doc 
-rw-r--r-- 1 avi  avi       96206 Nov  5 12:56 Untitled 1.odt 
-rw-r--r-- 1 avi  avi        9405 Nov 12 23:22 Untitled.png

注意:echo 「ls -l」的意思是,將這串命令(這裡是 ls -l)輸出在標準終端上。你可以用你需要或者選擇的命令替代『ls -l『。

:重定向輸出

/dev/pts/0: 這是輸出設備和/或文件,輸出到指定的地方,這裡輸出在終端(/dev/pts/0)。

就我而言,此時我的tty/dev/pts/0。你可以用tty命令檢查你的tty

avi@localhost:~/Desktop$ tty 

/dev/pts/0

注意: 『at『會在系統時間匹配到特定時間時會儘快執行。

25. du -h –max-depth=1 命令

下面的命令以人類可讀的形式輸出當前目錄的子目錄的大小。

avi@localhost:/home/avi/Desktop# du -h --max-depth=1 

38M     ./test 
1.1G    ./shivji 
42M     ./drupal 
6.9G    ./101MSDCF 
16G .

注意:上面的命令在檢查系統使用率是非常有用。

26. expr 命令

expr『不是那麼鮮為人知的命令。這個命令在終端中計算簡單的算數時非常有用。

avi@localhost:/home/avi/Desktop# expr 2 + 3 
5

avi@localhost:/home/avi/Desktop# expr 6 – 3 
3

avi@localhost:/home/avi/Desktop# expr 12 / 3 
4

avi@localhost:/home/avi/Desktop# expr 2 * 9 
18

27. look 命令

在終端上從英文字典上查單詞以防混淆。比如說,我記不清了是該拼成carrier還是carieer。

avi@localhost:/home/avi/Documents# look car

Cara 
Cara's 
…
... 
carps 
carpus 
carpus's 
carrel 
carrel's 
carrels 
carriage 
carriage's 
carriages 
carriageway 
carriageway's 
carried 
carrier 
carrier's 
carriers 
carries 
…
... 
caryatids

上面的命令會顯示字典上所有以'car'開頭的單詞。我得到了我想找的。

28. yes 命令

另外一個命令在通常基礎上並不會經常使用,但是在腳本語言和系統管理時非常有用。

這個命令會持續地輸出給定的字元串,直到由你的中斷命令打斷。

avi@localhost:~/Desktop$ yes "Tecmint is one of the best site dedicated to Linux, how to" 

Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
…
…
...
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to

29. factor 命令

factor實際是一個源於數學的命令。這個命令會輸出所有給定數字的因數。

avi@localhost:~/Desktop$ factor 22 
22: 2 11

avi@localhost:~/Desktop$ factor 21 
21: 3 7

avi@localhost:~/Desktop$ factor 11 
11: 11

30. ping -i 60 -a IP_address

我們都用ping命令檢測伺服器是否連通。我通常ping google,來檢測我是否連接到了網際網路。

當你等待或者持續盯著你的終端等待命令的回應或者等待伺服器的連接時,有時是很氣人的。

一旦伺服器連通就有一個聲音如何(譯註:下面命令是等60秒PING一次)?

avi@localhost:~/Desktop$ ping -i 60 -a www.google.com 

PING www.google.com (74.125.200.103) 56(84) bytes of data. 
64 bytes from www.google.com (74.125.200.103): icmp_req=1 ttl=44 time=105 ms 
64 bytes from 74.125.200.103: icmp_req=2 ttl=44 time=281 ms

注意,當你發現命令不會返回聲音時。請確保你的系統不是靜音的,聲音已經在『sound preferences(聲音選項)『 中啟用並確保勾選了『Enable window and window sound『。

31. tac 命令

這個命令很有趣,他會以倒序輸出文本文件的內容。也就是從最後一行到第一行。

在home目錄下,我的Documents目錄下有一個35.txt文件。用cat 命令檢查內容。

avi@localhost:~/Documents$ cat 35.txt

示例輸出

  1. Linux is built with certain powerful tools, which are unavailable in windows.
  2. One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it's Linux Counterpart.
  3. Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages.

現在用tac命令反轉文件內容(譯註:當然,我們知道cat反轉過來就是tac)。

avi@localhost:~/Documents$ tac 35.txt 

示例輸出

  1. Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages.
  2. One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it's Linux Counterpart.
  3. Linux is built with certain powerful tools, which are unavailable in windows.

現在結束了。如果你還知道其他一些Linux鮮為人知的命令,你可以在下面評論,那麼我們你可以在以後的文章中包含進來。

不要忘了給我們有價值的評論。我很快會發另外有趣的文章。別走開繼續關注 Tecmint

via: http://www.tecmint.com/10-lesser-known-commands-for-linux-part-3/

譯者:geekpi 校對:wxy

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


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

對這篇文章感覺如何?

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

    You may also like

    Leave a reply

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

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

    More in:Linux中國

    Linux中國

    捐贈 Let's Encrypt,共建安全的互聯網

    隨著 Mozilla、蘋果和谷歌對沃通和 StartCom 這兩家 CA 公司處罰落定,很多使用這兩家 CA 所簽發證書的網站紛紛尋求新的證書籤發商。有一個非盈利組織可以為大家提供了免費、可靠和安全的 SSL 證書服務,這就是 Let's Encrypt 項目。現在,它需要您的幫助
    Linux中國

    關於Linux防火牆iptables的面試問答

    Nishita Agarwal是Tecmint的用戶,她將分享關於她剛剛經歷的一家公司(印度的一家私人公司Pune)的面試經驗。在面試中她被問及許多不同的問題,但她是iptables方面的專家,因此她想分享這些關於iptables的問題和相應的答案給那些以後可能會進行相關面試的人。 所有的問題和相應的答案都基於Nishita Agarwal的記憶並經過了重寫。 嗨,朋友!我叫Nishita Agarwal。我已經取得了理學學士學位,我的專業集中在UNIX和它的變種(BSD,Linux)。它們一直深深的吸引著我。我在存儲方面有1年多的經驗。我正在尋求職業上的變化,並將供職於印度的P
    Linux中國

    Lets Encrypt 已被所有主流瀏覽器所信任

    旨在讓每個網站都能使用 HTTPS 加密的非贏利組織 Lets Encrypt 已經得了 IdenTrust的交叉簽名,這意味著其證書現在已經可以被所有主流的瀏覽器所信任。從這個裡程碑事件開始,訪問者訪問使用了Lets Encrypt 證書的網站不再需要特別配置就可以得到 HTTPS 安全保護了。 Lets Encrypt 的兩個中級證書 ...