网站搜索

10 个鲜为人知的 Linux 命令 – 第 3 部分


就是对“鲜为人知的 Linux 文章”系列的最后两篇文章的反响感到不知所措。

  1. 11 个鲜为人知的有用 Linux 命令 – 第一部分
  2. 10 个鲜为人知的 Linux 命令 – 第 2 部分
  3. 10 个鲜为人知的有效 Linux 命令 – 第四部分
  4. 10 个鲜为人知的有用 Linux 命令 - 第五部分

我们提出了本系列的第三篇文章,其中包括一些其他鲜为人知、值得了解的 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”的文件,其中包含大量文本。

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’命令类似于 cron 命令,可用于安排任务或命令在指定时间运行。

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

OR

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 ” :此字符串 echo 是命令(此处为 ls -l)标准终端。您可以将“ls -l”替换为您需要和选择的任何命令。

> : redirects the output

/dev/pts/0 :这是输出设备和/或文件,在其中寻求输出,此处输出位于终端。

就我而言,当时我的 tty 位于 /dev/pts/0。您可以通过运行命令tty来检查您的 tty

avi@localhost:~/Desktop$ tty 

/dev/pts/0

注意:“at”命令在系统时钟与指定时间匹配时立即执行任务。

25. du -h –max-深度=1 命令

以下命令以人类可读的格式输出当前目录中子文件夹的大小。

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

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

注意:上面的命令在检查系统磁盘使用情况时非常有用。

下载 Linux 命令行备忘单

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. 查找命令

从终端本身检查英语词典中的单词,以防混淆。也就是说,我有点困惑拼写是“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. 是命令

另一个不经常使用的命令,通常但在脚本语言和系统管理员中非常有用。

该命令继续打印给定的字符串,直到您给出中断指令。

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 命令实际上是一个源自数学的命令。该命令输出给定数字的所有因数。

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 地址

我们所有人都使用 ping 命令来检查服务器是否处于活动状态。我通常会 ping google,以检查我是否已连接到互联网。

当您等待并持续观察终端以获得 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

在您报告该命令没有返回任何声音之前,让我告诉您一件事。确保您的系统音频未静音,必须在“声音首选项”中启用声音主题,并确保选中“启用窗口和窗口声音”。

31. tac命令

这个命令非常有趣,它以相反的顺序打印文本文件的内容,即从最后一行到第一行。

我的文档目录中的主文件夹下有一个文本文件 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 命令反转文件的内容。

avi@localhost:~/Documents$ tac 35.txt
样本输出
3.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. 

1. Linux is built with certain powerful tools, which are unavailable in windows.

目前为止就这样了。如果您知道其他鲜为人知的 Linux 命令,可以发表评论,以便我们将它们包含在以后的文章中。

不要忘记向我们提供您有价值的评论。我很快就会带来另一篇有趣的文章。在此之前,请继续关注并连接到 Tecmint