<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tech blog of  WEN Yang : GNU Linux</title><link>http://blogs.mit.edu/CS/blogs/wenyang/archive/category/278.aspx</link><description>GNU Linux</description><dc:language>en-US</dc:language><generator>CommunityServer 1.1 (Build: 1.1.0.50615)</generator><item><title>An incomplete list of not-that-frequently-used but handy tools in Linux</title><link>http://blogs.mit.edu/CS/blogs/wenyang/archive/2007/09/12/65611.aspx</link><pubDate>Thu, 13 Sep 2007 02:16:00 GMT</pubDate><guid isPermaLink="false">dea6705e-d99c-4a22-9533-aabb455eb28d:65611</guid><dc:creator>wenyang</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.mit.edu/CS/blogs/wenyang/comments/65611.aspx</comments><wfw:commentRss>http://blogs.mit.edu/CS/blogs/wenyang/commentrss.aspx?PostID=65611</wfw:commentRss><description>Lots of programs in the Unix/Linux tend to follow the philosophy of "do
one thing, do it well", and they are often designed to work together to
do complicated jobs. Therefore, if we know what tools are available out
there, we can break down the tasks into a few steps and use the most
suitable tool for each of them. Usually, finding a right tool for the
work in hand might well worth the time, if (that's a big if) you can
easily find one and learn to use it quickly.&lt;br&gt;&lt;br&gt;Some tools we use
almost everyday: ls, cd, cp, mv, rm, pwd, find, grep, alias, locate, history, ... I am familiar with
their common usage, at least for the basic ones. For those advanced
cases, I know where to look for help quickly. &lt;br&gt;&lt;br&gt;Of course there are also powerful tools in my arsenal, such as Sed, Awk, and Emacs. I can do a lot of things with them. But there is still times when some of the following (small) tools come in handy. Unfortunately, since they are not used as often, I tend to forget their usage and need to dig into the details of manual pages, which is less desirable. So I'll try to give some typical examples of how
they can be used.&lt;br&gt;&lt;br&gt;cut - remove sections from each line of files&lt;br&gt;paste - merge lines of files&lt;br&gt;sort - sort lines of text files&lt;br&gt;tr - translate or delete characters&lt;br&gt;tac - concatenate and print files in reverse&lt;br&gt;wc - display a count of lines, words&amp;nbsp; and&amp;nbsp; characters&amp;nbsp; in&amp;nbsp; a file&lt;br&gt;uniq - report or filter out repeated lines in a file&lt;br&gt;......&lt;br&gt;&lt;br&gt;I'll put the details in my &lt;a href="http://web.mit.edu/wenyang/www/tiddlywiki_yw.htm"&gt;wiki&lt;/a&gt;. The directly link is &lt;a href="http://web.mit.edu/wenyang/www/tiddlywiki_yw.htm#%5B%5BAn%20incomplete%20list%20of%20not-that-frequently-used%20but%20handy%20tools%20in%20Linux%5D%5D"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;&lt;img src="http://blogs.mit.edu/CS/aggbug.aspx?PostID=65611" width="1" height="1"&gt;</description></item><item><title>Man (Manual) -&amp;gt; PDF</title><link>http://blogs.mit.edu/CS/blogs/wenyang/archive/2006/10/24/62019.aspx</link><pubDate>Tue, 24 Oct 2006 04:44:00 GMT</pubDate><guid isPermaLink="false">dea6705e-d99c-4a22-9533-aabb455eb28d:62019</guid><dc:creator>wenyang</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.mit.edu/CS/blogs/wenyang/comments/62019.aspx</comments><wfw:commentRss>http://blogs.mit.edu/CS/blogs/wenyang/commentrss.aspx?PostID=62019</wfw:commentRss><description>&lt;font face="Courier New"&gt;groff -Tps -m man filename.n | ps2pdf - output.pdf&lt;/font&gt;&lt;br&gt;&lt;br&gt;or &lt;br&gt;&lt;br&gt;&lt;font face="Courier New"&gt;groff -Tps -m man filename.n &amp;gt; output.ps&lt;br&gt;ps2pdf output.ps&lt;/font&gt;&lt;br&gt;&lt;img src="http://blogs.mit.edu/CS/aggbug.aspx?PostID=62019" width="1" height="1"&gt;</description></item><item><title>Using SED and AWK to find total demand from an origin for a certain time interval</title><link>http://blogs.mit.edu/CS/blogs/wenyang/archive/2005/09/22/18717.aspx</link><pubDate>Fri, 23 Sep 2005 03:55:00 GMT</pubDate><guid isPermaLink="false">dea6705e-d99c-4a22-9533-aabb455eb28d:18717</guid><dc:creator>wenyang</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.mit.edu/CS/blogs/wenyang/comments/18717.aspx</comments><wfw:commentRss>http://blogs.mit.edu/CS/blogs/wenyang/commentrss.aspx?PostID=18717</wfw:commentRss><description>&lt;p&gt;Example1:&lt;/p&gt;
&lt;p&gt;# sed -n '/&lt;strong&gt;&lt;em&gt;21600 1 4&lt;/em&gt;&lt;/strong&gt;/, /^}/ {/^{/p;}' demand.dat &amp;gt; test1&lt;/p&gt;
&lt;p&gt;# awk '$2 == "11220" { x += $4 } END { print "total flow per interval: " x "\ntotal flow per hour: " x*4}' test1&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Note:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In the first line, &lt;em&gt;21600&lt;/em&gt; is the time stamp, &lt;em&gt;1&lt;/em&gt; is the type, &lt;em&gt;4&lt;/em&gt; is the scale. 
&lt;/li&gt;&lt;li&gt;In the second line, &lt;em&gt;11220&lt;/em&gt; is the Node ID.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Example2:&lt;/p&gt;
&lt;p&gt;# awk -f count_orig.awk orig=11220 Demand/demand_newpath_Xhat_0600.dat&lt;/p&gt;
&lt;p&gt;Use script count_orig.awk, whose contain is the following:&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;&lt;br /&gt;$2 == orig { x += $4; print $2 "\t" $3 "\t" $4 }&lt;/p&gt;
&lt;p&gt;END { print "total flow per interval: " x "\ntotal flow per hour: " x*4}&lt;br /&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p dir="ltr" style="MARGIN-RIGHT: 0px"&gt;Note: "Demand/demand_newpath_Xhat_0600.dat" is the demand file for 6am.&lt;/p&gt;&lt;img src="http://blogs.mit.edu/CS/aggbug.aspx?PostID=18717" width="1" height="1"&gt;</description></item><item><title>Run matlab in batch mode</title><link>http://blogs.mit.edu/CS/blogs/wenyang/archive/2005/05/17/12701.aspx</link><pubDate>Tue, 17 May 2005 23:56:00 GMT</pubDate><guid isPermaLink="false">dea6705e-d99c-4a22-9533-aabb455eb28d:12701</guid><dc:creator>wenyang</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.mit.edu/CS/blogs/wenyang/comments/12701.aspx</comments><wfw:commentRss>http://blogs.mit.edu/CS/blogs/wenyang/commentrss.aspx?PostID=12701</wfw:commentRss><description>&lt;p&gt;Use option "-r MATLAB_command" to run matlab in batch mode. &lt;/p&gt;
&lt;p&gt;Automatically run the specified MATLAB M-file, either commands supplied with MATLAB or your own M-files, immediately after MATLAB starts. This is also referred to as calling MATLAB in batch mode. Separate multiple commands with commas or semicolons (;). M-files must be on the MATLAB path or in the MATLAB startup directory. Do not include the pathname or a file extension. &lt;/p&gt;
&lt;p&gt;Example: matlab -nojvm -nosplash -r MyCommand &lt;/p&gt;
&lt;p&gt;Reference: &lt;a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/start_q4.html"&gt;MATLAB Documentation - Desktop Tools and Development Environment - Startup Options&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;We can now use "system" (need to include &amp;lt; cstdlib &amp;gt;) to call a shell-script, which in turn calls matlab to do something. &lt;/p&gt;&lt;img src="http://blogs.mit.edu/CS/aggbug.aspx?PostID=12701" width="1" height="1"&gt;</description></item><item><title>eject, screen, lftp ...</title><link>http://blogs.mit.edu/CS/blogs/wenyang/archive/2005/05/07/11959.aspx</link><pubDate>Sat, 07 May 2005 05:55:00 GMT</pubDate><guid isPermaLink="false">dea6705e-d99c-4a22-9533-aabb455eb28d:11959</guid><dc:creator>wenyang</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.mit.edu/CS/blogs/wenyang/comments/11959.aspx</comments><wfw:commentRss>http://blogs.mit.edu/CS/blogs/wenyang/commentrss.aspx?PostID=11959</wfw:commentRss><description>&lt;p&gt;&lt;strong&gt;eject&lt;/strong&gt; - eject removable media&lt;/p&gt;
&lt;p&gt;When you &lt;em&gt;umount /mnt/usb&lt;/em&gt;, sometimes the LED is still on, then you can try this&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;&lt;em&gt;eject /mnt/usb&lt;/em&gt; &lt;/p&gt;&lt;/blockquote&gt;
&lt;p dir="ltr"&gt;&lt;strong&gt;screen&lt;/strong&gt; - screen manager with VT100/ANSI terminal emulation&lt;/p&gt;
&lt;p dir="ltr"&gt;SYNOPSIS&lt;br /&gt;       &lt;em&gt;screen &lt;/em&gt;[ -options ] [ cmd [ args ] ]&lt;br /&gt;       &lt;em&gt;screen&lt;/em&gt; -r [[pid.]tty[.host]]&lt;br /&gt;       &lt;em&gt;screen&lt;/em&gt; -r sessionowner/[[pid.]tty[.host]]&lt;/p&gt;
&lt;p dir="ltr"&gt;lftp - &lt;br /&gt;&lt;br /&gt;To be continued ...&lt;/p&gt;&lt;img src="http://blogs.mit.edu/CS/aggbug.aspx?PostID=11959" width="1" height="1"&gt;</description></item><item><title>[Script] run DynaMIT, check runtime</title><link>http://blogs.mit.edu/CS/blogs/wenyang/archive/2005/05/01/11550.aspx</link><pubDate>Sun, 01 May 2005 23:11:00 GMT</pubDate><guid isPermaLink="false">dea6705e-d99c-4a22-9533-aabb455eb28d:11550</guid><dc:creator>wenyang</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.mit.edu/CS/blogs/wenyang/comments/11550.aspx</comments><wfw:commentRss>http://blogs.mit.edu/CS/blogs/wenyang/commentrss.aspx?PostID=11550</wfw:commentRss><description>&lt;blockquote&gt;&lt;pre&gt;&lt;span class="comment"&gt;#!/bin/&lt;/span&gt;&lt;span class="keyword"&gt;bash&lt;/span&gt;&lt;span class="comment"&gt;
&lt;/span&gt;&lt;span class="builtin"&gt;echo&lt;/span&gt; &lt;span class="string"&gt;'=== Running CorbaFreeDynaMIT from current directory ==='&lt;/span&gt;
&lt;span class="variable-name"&gt;STARTTime&lt;/span&gt;=&lt;span class="string"&gt;`date`&lt;/span&gt;
&lt;span class="builtin"&gt;echo&lt;/span&gt; &lt;span class="string"&gt;'Preparing to delete __* files in current directory and all sub directory'&lt;/span&gt;
ls __e*
&lt;span class="keyword"&gt;if&lt;/span&gt; [ $&lt;span class="variable-name"&gt;?&lt;/span&gt; = 0 ]
&lt;span class="keyword"&gt;then&lt;/span&gt; 
    &lt;span class="builtin"&gt;echo&lt;/span&gt; -n &lt;span class="string"&gt;"Really want to remove these files? (y/n):"&lt;/span&gt;
    &lt;span class="builtin"&gt;read&lt;/span&gt; yesORno
    &lt;span class="keyword"&gt;if&lt;/span&gt; [ $&lt;span class="variable-name"&gt;yesORno&lt;/span&gt; = y -o $&lt;span class="variable-name"&gt;yesORno&lt;/span&gt; = Y ]
        &lt;span class="keyword"&gt;then&lt;/span&gt;
        &lt;span class="builtin"&gt;echo&lt;/span&gt; &lt;span class="string"&gt;'find . -maxdepth 1 -name "__*" -exec rm -v {} \;'&lt;/span&gt;
        find . -maxdepth 1 -name &lt;span class="string"&gt;"__e*"&lt;/span&gt; -exec rm -v {} &lt;span class="string"&gt;\;&lt;/span&gt; &amp;amp;&amp;amp; &lt;span class="builtin"&gt;echo&lt;/span&gt; &lt;span class="string"&gt;"Files removed."&lt;/span&gt;
    &lt;span class="keyword"&gt;else&lt;/span&gt;
        &lt;span class="builtin"&gt;echo&lt;/span&gt; &lt;span class="string"&gt;"You did not choose 'y'. Continue without deleting"&lt;/span&gt;
    &lt;span class="keyword"&gt;fi&lt;/span&gt;
&lt;span class="keyword"&gt;fi&lt;/span&gt;
time ~/CorbaFreeDynaMIT/DynaMIT/DynaMIT dtaparam.dat
&lt;span class="builtin"&gt;echo&lt;/span&gt; &lt;span class="string"&gt;'Script'&lt;/span&gt; $&lt;span class="variable-name"&gt;0&lt;/span&gt; &lt;span class="string"&gt;'started at: '&lt;/span&gt; $&lt;span class="variable-name"&gt;STARTTime&lt;/span&gt;
&lt;span class="builtin"&gt;echo&lt;/span&gt; -n &lt;span class="string"&gt;'Script'&lt;/span&gt; $&lt;span class="variable-name"&gt;0&lt;/span&gt; &lt;span class="string"&gt;'finished at: '&lt;/span&gt;&amp;amp;&amp;amp; date
&lt;span class="builtin"&gt;echo&lt;/span&gt; &lt;span class="string"&gt;'Done.'&lt;/span&gt;

&lt;/pre&gt;&lt;/blockquote&gt;&lt;img src="http://blogs.mit.edu/CS/aggbug.aspx?PostID=11550" width="1" height="1"&gt;</description></item><item><title>nohup - run a command immune to hangups, with output to a non-tty</title><link>http://blogs.mit.edu/CS/blogs/wenyang/archive/2005/05/01/11549.aspx</link><pubDate>Sun, 01 May 2005 23:03:00 GMT</pubDate><guid isPermaLink="false">dea6705e-d99c-4a22-9533-aabb455eb28d:11549</guid><dc:creator>wenyang</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.mit.edu/CS/blogs/wenyang/comments/11549.aspx</comments><wfw:commentRss>http://blogs.mit.edu/CS/blogs/wenyang/commentrss.aspx?PostID=11549</wfw:commentRss><description>&lt;p&gt;In bash, use &lt;/p&gt;
&lt;p align="center"&gt;&lt;em&gt;&lt;strong&gt;nohup&lt;/strong&gt; ~/CorbaFreeDynaMIT/DynaMIT/DynaMIT dtaparam.dat 1&amp;gt;log_stdout 2&amp;gt;log_stderr &amp;amp;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://blogs.mit.edu/CS/aggbug.aspx?PostID=11549" width="1" height="1"&gt;</description></item></channel></rss>