Total Pageviews

Tuesday 31 July 2012

Linux的一些命令行神器

下面是Kristóf Kovács收集的28个Unix/Linux下的28个命令行下的工具(原文链接),有一些是大家熟悉的,有一些是非常有用的,有一些是不为人知的。这些工具都非常不错,希望每个人都知道。本篇文章还在Hacker News上被讨论,你可以过去看看。我以作者的原文中加入了官网链接和一些说明。

dstat & sar

iostat, vmstat, ifstat 三合一的工具,用来查看系统性能(我在《性能调优攻略》中提到过那三个xxstat工具)。
官方网站:http://dag.wieers.com/rpm/packages/dstat/
你可以这样使用:
1
alias dstat='dstat -cdlmnpsy'

slurm

查看网络流量的一个工具
官方网站:  Simple Linux Utility for Resource Management



screen, dtach, tmux, byobu

你是不是经常需要 SSH 或者 telent 远程登录到 Linux 服务器?你是不是经常为一些长时间运行的任务而头疼,比如系统备份、ftp 传输等等。通常情况下我们都是为每一个这样的任务开一个远程终端窗口,因为他们执行的时间太长了。必须等待它执行完毕,在此期间可不能关掉窗口或者断开连 接,否则这个任务就会被杀掉,一切半途而废了。
Screen是 一个可以在多个进程之间多路复用一个物理终端的窗口管理器。Screen中有会话的概念,用户可以在一个screen会话中创建多个screen窗口,在 每一个screen窗口中就像操作一个真实的telnet/SSH连接窗口那样。请参看IBM DeveloperWorks的这篇文章《使用 screen 管理你的远程会话

dtach 是用来模拟screen的detach的功能的小工具,其可以让你随意地attach到各种会话上 。下图为dtach+dvtm的样子。

tmux是一个优秀的终端复用软件,类似GNU Screen, 但来自于OpenBSD,采用BSD授权。使用它最直观的好处就是,通过一个终端登录远程主机并运行tmux后,在其中可以开启多个控制台而无需再“浪 费”多余的终端来连接这台远程主机;当然其功能远不止于此。与screen相比的优点:可以横向和纵向分割窗口,且窗格可以自由移动和调整大小。可在多个 缓冲区进行复制和粘贴,支持跨窗口搜索;非正常断线后不需重新detach;……  有人说——与tmux相比,screen简直弱爆了

byobu是Ubuntu开发的,在Screen的基础上进行包装,使其更加易用的一个工具。最新的Byobu,已经是基于Tmux作为后端了。可通过“byobu-tmux”这个命令行前端来接受各种与tmux一模一样的参数来控制它。Byobu的细节做的非常好,效果图如下:

multitail

MultiTail是个用来实现同时监控多个文档、类似tail命令的功能的软件。他和tail的区别就是他会在控制台中打开多个窗口,这样使同时监控多个日志文档成为可能。他还可以看log文件的统计,合并log文件,过滤log文件,分屏,……。
官网:http://www.vanheusden.com/multitail/


tpp

终端下的PPT,要是在某某大会上用这个演示PPT,就太TMD的Geek了。
官网:http://www.ngolde.de/tpp.html


xargs & parallel

Executes tasks from input (even multithread).
xargs 是一个比较古老的命令,有简单的并行功能,这个不说了。对于GNU parallel ( online manpage )来说,它不仅能够处理本机上多执行绪,还能分散至远端电脑协助处理。而使用GNU parallel前,要先确定本机有安装GNU parallel / ssh / rsync,远端电脑也要安装ssh。


duplicity & rsyncrypto

Duplicity是使用rsync算法加密的高效率备份软件,Duplicity支持目录加密生产和格式上传到远程或本地文件服务器。
rsyncrypto 就是 rsync + encryption。对于rsync的算法可参看酷壳的rsync核心算法
Encrypting backup tools.


nethack & slash’em

NetHackWiki),20年历史的古老电脑游戏。没有声音,没有漂亮的界面,不过这个游戏真的很有意思。网上有个家伙说:如果你一生只做一件事情,那么玩NetHack。 这句话很惹眼,但也让人觉得这个游戏很复杂不容易上手。其实,这个游戏很虽然很复杂,却容易上手。虽然玩通关很难,但上手很容易。NetHack上有许多 复杂的规则,”the DevTeam thinks of everything”(开发团队想到了所有的事情)。各种各样的怪物,各种各样的武器….,有许多spoilers文件来说明其规则。除了每次开始随机 生成的地图,每次玩游戏,你也都会碰到奇怪的事情: 因为喝了一种药水,变成了机器人;因为踢坏了商店的门被要求高价赔偿;你的狗为你偷来了商店的东西….. 这有点象人生,你不能完全了解这个世界,但你仍然可以选择自己的面对方式。
网上有许多文章所这是最好的电脑游戏或最好的电脑游戏之一。也许是因为它开放的源代码让人赞赏,古老的历史让人宽容,复杂的规则让人敬畏。虽然它不是当前流行的游戏,但它比任何一个当前流行的游戏都更有可能再经受20年的考验。
Slash’EM 也是一个基于NetHack的经典游戏。


lftp

利用lftp命令行ftp工具进行网站数据的增量备份,镜像,就像使用rsync一样。


ack

ack是一个perl脚本,是grep的一个可选替换品。其可以对匹配字符有高亮显示。是为程序员专门设计的,默认递归搜索,省提供多种文件类型供选。


calcurse & remind + wyrd

calcurse是一个命令行下的日历和日程软件。remind + wyrd也很类似。关于日历,我不得不提一个Linux的Cycle日历,也是一个神器,呵呵。


newsbeuter & rsstail

newsbeuter 和 rsstail 是命令行下RSS的阅读工具。


powertop

做个环保的程序员,看看自己的电脑里哪些程序费电。PowerTOP 是一个让 Intel 平台的笔记本电脑节省电源的 Linux 工具。此工具由 Intel 公司发布。它可以帮助用户找出那些耗电量大的程序,通过修复或者关闭那些应用程序或进程,从而为用户节省电源。


htop & iotop

htop 和 iotop  用来查看进程,内存和IO负载。

ttyrec & ipbt

ttyrec 是一个 tty 控制台录制程序,其所录制的数据文件可以使用与之配套的 ttyplay 播放。不管是你在 tty 中的各种操作,还是在 tty 中耳熟能详的软件,都可进行录制。
ipbt 是一个用来回放 ttyrec 所录制的控制台输入过程的工具。
与此类似的还有Shelr 和 termrec 


rsync

通过SSH进行文件同步的经典工具(核心算法


mtr

MTR – traceroute 2.0,其是把 traceroute 和 ping 集成在一块的一个小工具 用于诊断网络。


socat & netpipes

socat是一个多功能的网络工具,名字来由是” Socket CAT”,可以看作是netcat的N倍加强版。
netpipes 和socat一样,主要是用来在命令行来进行socket操作的命令,这样你就可以在Shell脚本下行进socket网络通讯了。


iftop & iptraf

iftopiptraf可以用来查看当前网络链接的一些流量情况。



siege & tsung

Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。
Tsung 是 一个压力测试工具,可以测试包括HTTP, WebDAV, PostgreSQL, MySQL, LDAP, and XMPP/Jabber等服务器。针对 HTTP 测试,Tsung 支持 HTTP 1.0/1.1 ,包含一个代理模式的会话记录、支持 GET、POST 和 PUT 以及 DELETE 方法,支持 Cookie 和基本的 WWW 认证,同时还支持 SSL。
参看:十个免费的Web压力测试工具


ledger

ledger 一个命令行下记帐的小工具。

taskwarrior

TaskWarrior 是一个基于命令行的 TODO 列表管理工具。主要功能包括:标签、彩色表格输出、报表和图形、大量的命令、底层API、多用户文件锁等功能。


curl

cURL是 一个利用URL语法在命令行下工作的文件传输工具,1997年首次发行。它支持文件上传和下载,所以是综合传输工具,但按传统,习惯称cURL为下载工 具。cURL还包含了用于程序开发的libcurl。cURL支援的通訊協定有FTP、FTPS、HTTP、HTTPS、TFTP、SFTP、 Gopher、SCP、Telnet、DICT、FILE、LDAP、LDAPS、IMAP、POP3、SMTP和RTSP。


rtorrent & aria2

rTorrent 是 一个非常简洁、优秀、非常轻量的BT客户端. 它使用了 ncurses 库以 C++ 编写, 因此它完全基于文本并在终端中运行. 将 rTorrent 用在安装有 GNU Screen 和 Secure Shell 的低端系统上作为远程的 BT 客户端是非常理想的。
aria2 是 Linux 下一个不错的高速下载工具。由于它具有分段下载引擎,所以支持从多个地址或者从一个地址的多个连接来下载同一个文件。这样自然就大大加快了文件的下载速 度。aria2 也具有断点续传功能,这使你随时能够恢复已经中断的文件下载。除了支持一般的 http(s) 和 ftp 协议外,aria2 还支持 BitTorrent 协议。这意味着,你也可以使用 aria2 来下载 torrent 文件。

ttytter & earthquake

TTYtter 是一个Perl写的命令行上发Twitter的工具,可以进行所有其他平台客户端能进行的事情,当然,支持中文。脚本控、CLI控、终端控、Perl控的最愛。
Earthquake也是一个命令行上的Twitter客户端。



vifm & ranger

Vifm 基于ncurses的文件管理器,DOS风格,用键盘操作。

Ranger用 Python 完成,默认为使用 Vim 风格的按键绑定,比如 hjkl(上下左右),dd(剪切),yy(复制)等等。功能很全,扩展/可配置性也非常不错。类似MacOS X下Finder(文件管理器)的多列文件管理方式。支持多标签页。实时预览文本文件和目录。

cowsay & sl

cowsay  不说了,如下所示,哈哈哈。还有xcowsay,你可以自己搜一搜。

sl是什么?ls?,呵呵,你会经常把ls 打成sl吗?如果是的话,这个东西可以让你娱乐一下,你会看到一辆火车呼啸而过~~,相当拉风。你可以使用sudo apt-get install sl 安装.
-----------------------------------------------------------------------------------------

The Sysadmin's Toolbox: iftop


Who's using up all the bandwidth, and what are they doing? Use iftop to find out.
Longtime system administrators often take tools for granted that they've used for years and assume everyone else has heard of them. Of course, new sysadmins join the field every day, and even seasoned sysadmins don't all use the same tools. With that in mind, I decided to write a few columns where I highlight some common-but-easy-to-overlook tools that make life as a sysadmin (and really, any Linux user) easier. My last article covered sar, a tool you can use to collect and view system metrics over time. This time, I discuss a program that's handy for viewing real-time network performance data: iftop.
Anyone who's had to use a network at a conference has experienced what happens when there just isn't enough network bandwidth to go around. While you are trying to check your e-mail, other people are streaming movies and TV shows, downloading distribution install disks, using p2p networks, upgrading their distributions or watching cat videos on YouTube. Although it's certainly frustrating to try to use one of those networks, imagine how frustrating it would be to be the admin in charge of that network. Whether you run a conference network, a local office network or even a Web server at your house, it can be really nice to know what is using up all of your bandwidth.
iftop is a Linux command-line program designed to give you live statistics about what network connections use the most bandwidth in a nice graphical form. As you may realize from the name, iftop borrows a lot of ideas from the always-useful load troubleshooting tool top. Like top, iftop updates automatically every few seconds, and like top, by default, it sorts the output you see by what's using the most resources. Where top is concerned with processes and how much CPU and RAM they use, iftop is concerned with network connections and how much upload and download bandwidth they use.
Even though iftop is packaged for both Red Hat- and Debian-based distributions, it's probably not installed by default, so you will need to install the package of the same name. In the case of Red Hat-based distributions, you might have to pull it down from a third-party repository. Once it's installed, the simplest way to get started is just to run iftop as the root user. iftop will locate the first interface it can use and start listening in on the traffic and display output similar to what you see in Figure 1. To close the program, press q to quit just like with top.
Figure 1. iftop output—the IPs have been smudged to protect the innocent.
At the very top of the screen is a scale that goes along with the bar graph iftop might display with each connection. The next rows of output correspond to each network connection between a pair of hosts. In between the two hosts are arrows that let you know the direction the traffic is flowing. The final three columns provide average bandwidth for each connection during the last 2, 10 and 40 seconds, respectively. So for instance, the very top connection in Figure 1 has averaged around 2.83Mb during the last 2 seconds, 3.32Mb during the last 10 seconds and 3.11Mb during the last 40 seconds. Underneath all the transmit and receive columns at the bottom of the screen are a series of statistics for overall transmitted and received traffic (TX and RX, respectively) including 2-, 10- and 40-second averages for both those and, finally, the totals for the interface.
Note: if you have a server with multiple interfaces, you may want iftop to monitor a different interface from the default. Just add -i followed by the interface to monitor when you launch iftop. For instance, to monitor eth2, I would type iftop -i eth2.

Disable DNS Lookups

By default, when you run iftop, it will try to translate all of the IP addresses into hostnames. Sometimes this can be useful if you are diagnosing issues on a local network; however, like with a lot of other network diagnostics tools, resolving all of those IPs can slow down the program and also may contribute to the traffic you see in the output. The solution is to run iftop with the -n argument, so it just shows you IP addresses for everything (you always can run a DNS query against an IP you are interested in, in another window). Alternatively, if you already have iftop running, you can press n to disable DNS lookups.

Show Port Data

When you run iftop on a server that might serve multiple purposes, it can be handy to know whether all of that upstream traffic is accessing your Web server, your mail server or something else. Alternatively, if you are trying to figure out what's using up all of your download bandwidth, it can be handy to see whether the top connections are Web connections or some rsync job you have running. To figure all of this out, iftop allows you to toggle the port display on and off. Press the p key while iftop is running, and it will display the ports used for both the source and destination IP for all traffic.
The one big downside to showing both the source and destination ports used for a connection is that you'll find in many cases you are concerned only with one or the other. For instance, if you are running a Web server, you may notice that a lot of traffic is going to your Web port (labeled www in iftop), but all of the ports used by IPs accessing your Web server use all sorts of high ports. In that case, you can press either S or D to toggle the display of either source or destination ports, respectively. Figure 2 shows an example of iftop output where I've chosen to display only the source ports.
Figure 2. iftop with only the source ports displayed.
For me, the really great thing about iftop is that it's a relatively simple command-line tool. It's true that a number of other programs exist that can provide fancy Web-based graphs of your network traffic, and I think those are great for trending network data just like they are for trending system load and other metrics. What I like about iftop is the same thing I like about top—when there's a problem, you can get instant real-time data about your system that updates as the situation progresses.