十个鲜为人知的 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鲜为人知的命令,你可以在下面评论,那么我们你可以在以后的文章中包含进来。

 原文发布时间为:2013-11-22

本文来自云栖社区合作伙伴“Linux中国”

相关文章
|
23小时前
|
Linux Shell 程序员
【Linux操作系统】命令的运行原理
【Linux操作系统】命令的运行原理
|
1天前
|
Linux
linux命令【JavaPub版】
linux命令【JavaPub版】
6 0
|
1天前
|
Linux 开发工具
Linux下视频截取命令 使用【ffmpeg】使用
Linux下视频截取命令 使用【ffmpeg】使用
7 1
|
2天前
|
Linux 数据处理 数据安全/隐私保护
Linux中的groups命令:管理用户组信息的利器
`groups`命令在Linux中用于显示用户所属的用户组,帮助管理员进行权限管理。它读取`/etc/group`和`/etc/passwd`文件获取信息,特点是简单直观,支持多用户组。命令参数如`-a`显示主组,`-g`显示主组ID,`-n`以数字形式显示,`-r`显示实际组。在实际应用中,结合其他命令可进行权限分析和定制输出。注意权限问题及用户组可能随系统变化。
|
2天前
|
关系型数据库 Linux 数据处理
深入了解Linux命令gprof:数据处理和分析利器
gprof是Linux下的一款命令行工具,用于分析程序性能,找出代码瓶颈。它通过分析函数调用和执行时间,提供函数级别的性能报告和图形化展示。使用gprof需在编译时添加`-pg`选项,然后运行程序并用gprof生成报告。注意覆盖所有执行路径,并可与其他性能工具结合使用,以优化代码性能。
|
2天前
|
安全 算法 Linux
探索Linux命令gpgv2:安全通信与数据验证的利器
`gpgv2`是GPG的签名验证工具,用于确保文件完整性和来源真实性。基于公钥密码学,支持多种加密算法和OpenPGP标准。通过`--verify`等参数验证签名,例如`gpgv2 --verify signature_file file`。重要注意事项包括保护私钥、定期更新密钥、验证签名来源及使用强密码。在数据安全场景中,`gpgv2`是保障信息安全的利器。
|
2天前
|
安全 Linux 数据处理
深入探索Linux中的gpgsplit命令
`gpgsplit`是GPG套件的一部分,用于分割大型加密文件或合并加密的OpenPGP消息。它支持ASCII armored和二进制格式,提供按字节数、行数或消息数分割的灵活性,并可合并消息。在处理大型加密文件、安全管理及数据传输中发挥作用。使用时注意保护私钥、备份数据、正确指定格式,并遵循安全实践。示例:使用`--split 10M`将大文件按10MB分割,`cat`多个消息文件并用`gpgsplit --output`合并。
|
2天前
|
Linux 开发者
Linux基础:常用命令及其用途
这些命令只是Linux命令行的冰山一角,但它们构成了日常工作的基础。通过掌握这些基本命令,你可以更有效地利用Linux系统的强大功能。随着你对这些基础命令的熟练应用,你会发现自己能够更快地完成任务并解决问题。
10 2
|
3天前
|
消息中间件 Unix Linux
[高频]Linux中常见的命令及常见面试题
[高频]Linux中常见的命令及常见面试题
|
3天前
|
算法 数据挖掘 Linux
探索Linux中的awk命令:强大的文本分析工具
探索Linux中的`awk`命令,一个强大的文本分析工具,用于模式扫描、数据提取与报告生成。本文介绍`awk`的用途、工作原理、特点及应用示例。`awk`基于"模式-动作"框架,从输入数据中匹配模式并执行相应操作。其特点包括:强大的文本处理能力、灵活的I/O及简洁的语法。示例涵盖了打印特定行、处理字段、计算统计值等场景。使用`awk`时要注意理解输入数据、测试脚本、优化性能和添加注释。深入学习以提升数据处理技能。