我们继续“10个鲜为人知Linux命令系列”的第三部分。或许你已经知道了这些命令,那你无疑是一个有经验而喜欢探索的Linux用户。
22.^foo^bar命令在一个实例中运行修改后的最后一个命令。假设我需要运行一个命令‘ls-l‘来详细列出‘Desktop’目录下的内容。意外地,你打了‘lls-l‘。所以你需要重新打整个命令或者使用导航键编辑前面的命令。当你的命令很长时这个很痛苦。
avi@localhost:~/Desktop$lls-lbash:lls:commandnotfoundavi@localhost:~/Desktop$^lls^lsls-ltotal7489440drwxr-xr-x2aviavi36864Nov132012101MSDCF-rw-r--r--1aviavi206833Nov515:271.jpg-rw-r--r--1aviavi158951Nov515:272.jpg-rw-r--r--1aviavi90624Nov512:59Untitled1.doc注意:在上面的替换中我们使用“typo(被替换的)original_command(原始命令)”。警告!这个命令可能会非常危险!如果你有意或者无意地打错了系统命令或者任何像rm-rf那样的风险命令的话!
23.>file.txt命令这个命令会刷新文件的内容而不需删除然后创建相同的文件。当我们需要反复输出,或者在相同的文件上记录日志时,这个命令就非常有用。
我有一个有很多文字的‘test.txt’文件在我的‘Desktop‘上。
avi@localhost:~/Desktop$cattest.txtLinuxGNUDebianFedorakaliubuntugitLinusTorvaldsavi@localhost:~/Desktop$>test.txtavi@localhost:~/Desktop$cattest.txt注意:再说一次,这个命令可能很危险!永远不要尝试刷新系统文件或者某篇日志文件的内容。如果你这么做了,你可能会遭遇严重的问题!
24.at命令‘at‘命令与cron命令相似也可用于安排一个任务或者在某个特定时刻执行命令。
avi@localhost:~/Desktop$echo"ls-l>/dev/pts/0"|at14:012或
avi@localhost:~/Desktop$echo"ls-l>/dev/pts/0"|at2:12PM示例输出
-rw-r--r--1aviavi220492Nov113:49Screenshot-1.png-rw-r--r--1rootroot358Oct1710:11sources.list-rw-r--r--1aviavi4695982080Oct1020:29squeeze.iso....-rw-r--r--1aviavi90624Nov512:59Untitled1.doc-rw-r--r--1aviavi96206Nov512:56Untitled1.odt-rw-r--r--1aviavi9405Nov1223:22Untitled.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-depth1命令下面的命令以人类可读的形式输出当前目录的子目录的大小。
avi@localhost:/home/avi/Desktop#du-h--max-depth138M./test1.1G./shivji42M./drupal6.9G./101MSDCF16G.注意:上面的命令在检查系统使用率是非常有用。
26.expr命令‘expr‘不是那么鲜为人知的命令。这个命令在终端中计算简单的算数时非常有用。
avi@localhost:/home/avi/Desktop#expr2+35avi@localhost:/home/avi/Desktop#expr6–33avi@localhost:/home/avi/Desktop#expr12/34avi@localhost:/home/avi/Desktop#expr2\*91827.look命令在终端上从英文字典上查单词以防混淆。比如说,我记不清了是该拼成carrier还是carieer。
avi@localhost:/home/avi/Documents#lookca
CaraCara's…...carpscarpuscarpus'scarrelcarrel'scarrelscarriagecarriage'scarriagescarriagewaycarriageway'scarriedcarriercarrier'scarrierscarries…...caryatids上面的命令会显示字典上所有以'car'开头的单词。我得到了我想找的。
28.yes命令另外一个命令在通常基础上并不会经常使用,但是在脚本语言和系统管理时非常有用。
这个命令会持续地输出给定的字符串,直到由你的中断命令打断。
avi@localhost:~/Desktop$yes"TecmintisoneofthebestsitededicatedtoLinux,howto"TecmintisoneofthebestsitededicatedtoLinux,howtoTecmintisoneofthebestsitededicatedtoLinux,howtoTecmintisoneofthebestsitededicatedtoLinux,howtoTecmintisoneofthebestsitededicatedtoLinux,howto……...TecmintisoneofthebestsitededicatedtoLinux,howtoTecmintisoneofthebestsitededicatedtoLinux,howtoTecmintisoneofthebestsitededicatedtoLinux,howto29.factor命令factor实际是一个源于数学的命令。这个命令会输出所有给定数字的因数。
avi@localhost:~/Desktop$factor2222:211avi@localhost:~/Desktop$factor2121:37avi@localhost:~/Desktop$factor1111:1130.ping-i60-aIP_address我们都用ping命令检测服务器是否连通。我通常pinggoogle,来检测我是否连接到了因特网。
当你等待或者持续盯着你的终端等待命令的回应或者等待服务器的连接时,有时是很气人的。
一旦服务器连通就有一个声音如何(译注:下面命令是等60秒PING一次)?
avi@localhost:~/Desktop$ping-i60-awww.google.comPINGwww.google.com(74.125.200.103)56(84)bytesofdata.64bytesfromwww.google.com(74.125.200.103):icmp_req1ttl44time105ms64bytesfrom74.125.200.103:icmp_req2ttl44time281ms注意,当你发现命令不会返回声音时。请确保你的系统不是静音的,声音已经在‘soundpreferences(声音选项)‘中启用并确保勾选了‘Enablewindowandwindowsound‘。
31.tac命令这个命令很有趣,他会以倒序输出文本文件的内容。也就是从最后一行到第一行。
在home目录下,我的Documents目录下有一个35.txt文件。用cat命令检查内容。
avi@localhost:~/Documents$cat35.txt示例输出
Linuxisbuiltwithcertainpowerfultools,whichareunavailableinwindows.OneofsuchimportanttoolisShellScripting.Windowshowevercomeswithsuchatoolbutasusualitismuchweakascomparedtoit'sLinuxCounterpart.Shellscripting/programmingmakesitpossibletoexecutecommand(s),pipedtogetdesiredoutputinordertoautomateday-to-dayusages.现在用tac命令反转文件内容(译注:当然,我们知道cat反转过来就是tac)。
avi@localhost:~/Documents$tac35.txt示例输出
Shellscripting/programmingmakesitpossibletoexecutecommand(s),pipedtogetdesiredoutputinordertoautomateday-to-dayusages.OneofsuchimportanttoolisShellScripting.Windowshowevercomeswithsuchatoolbutasusualitismuchweakascomparedtoit'sLinuxCounterpart.Linuxisbuiltwithcertainpowerfultools,whichareunavailableinwindows.现在结束了。如果你还知道其他一些Linux鲜为人知的命令,你可以在下面评论,那么我们你可以在以后的文章中包含进来。
不要忘了给我们有价值的评论。我很快会发另外有趣的文章。别走开继续关注Tecmint。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。