<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9025803393047781590</id><updated>2025-09-15T09:57:19.661-07:00</updated><category term="Two many files Open Issue"/><category term="rmem"/><category term="rmem_default"/><category term="rmem_max"/><category term="wmem"/><title type='text'>Unix Training</title><subtitle type='html'>This blog is intended to give simplestic way of unix commands in well organized way.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-5375014337234613176</id><published>2011-11-01T00:39:00.000-07:00</published><updated>2011-11-01T00:39:15.056-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Two many files Open Issue"/><title type='text'>Too Many Files Open Issue</title><content type='html'>While running socket program, we do see &quot;Too Many Files Open Issue. To address this issue, &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;$ limit&lt;/h3&gt;&lt;br /&gt;
&lt;p&gt;Run &lt;tt&gt;limit&lt;/tt&gt; command with Administrator rights,  we will see following details&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
cputime      unlimited
filesize     unlimited
datasize     unlimited
stacksize    10240 kbytes
coredumpsize 0 kbytes
memoryuse    unlimited
vmemoryuse   unlimited
descriptors  8192 
memorylocked 32 kbytes
maxproc      47264 
openfiles    8192
&lt;/code&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;Open  this file  &lt;tt&gt;/etc/security/limits.conf &lt;/tt&gt; to change these values. You will get more details  from comments section of this file .&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;In this file, make the changes as below to address this issue.&lt;/p&gt;&lt;pre&gt;&lt;tt&gt;* soft nofile 65535
* hard nofile 65535&lt;/tt&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/5375014337234613176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/5375014337234613176' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/5375014337234613176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/5375014337234613176'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2011/11/too-many-files-open-issue.html' title='Too Many Files Open Issue'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-7090680990358829249</id><published>2009-05-22T00:35:00.000-07:00</published><updated>2009-05-22T00:42:37.819-07:00</updated><title type='text'>Kernel Parameters</title><content type='html'>&lt;TABLE&gt;&lt;THEAD&gt;&lt;TR&gt;&lt;TH   &gt;Name&lt;/TH&gt;&lt;TH&gt;Description&lt;/TH&gt;&lt;TH&gt;Reasonable Values&lt;/TH&gt;&lt;/TR&gt;&lt;/THEAD&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SHMMAX&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Maximum size of shared memory segment (bytes)&lt;/TD&gt;&lt;TD&gt;250kB + 8.2kB * &lt;TT&gt;shared_buffers&lt;/TT&gt; + 14.2kB * &lt;TT&gt;max_connections&lt;/TT&gt; or infinity&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SHMMIN&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Minimum size of shared memory segment (bytes)&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SHMALL&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Total amount of shared memory available (bytes or pages)&lt;/TD&gt;&lt;TD&gt;if bytes, same as &lt;TT&gt;SHMMAX&lt;/TT&gt;; if pages, &lt;TTCLASS=&quot;LITERAL&quot;&gt;ceil(SHMMAX/PAGE_SIZE)&lt;/TT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SHMSEG&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Maximum number of shared memory segments per process&lt;/TD&gt;&lt;TD&gt;only 1 segment is needed, but the default is much higher&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SHMMNI&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Maximum number of shared memory segments system-wide&lt;/TD&gt;&lt;TD&gt;like &lt;TT&gt;SHMSEG&lt;/TT&gt; plus room for other applications&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SEMMNI&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Maximum number of semaphore identifiers (that is, sets)&lt;/TD&gt;&lt;TD&gt;&amp;#62;= ceil(max_connections / 16)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SEMMNS&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Maximum number of semaphores system-wide&lt;/TD&gt;&lt;TD&gt;ceil(max_connections / 16) * 17 + room for other applications&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SEMMSL&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Maximum number of semaphores per set&lt;/TD&gt;&lt;TD&gt;&amp;#62;= 17&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SEMMAP&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Number of entries in semaphore map&lt;/TD&gt;&lt;TD&gt;see text&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;TT&gt;SEMVMX&lt;/TT&gt;&lt;/TD&gt;&lt;TD&gt;Maximum value of semaphore&lt;/TD&gt;&lt;TD&gt;&amp;#62;= 255  (The default is often 32767, do not change unless asked to.)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;We can update directly in this file using root permission /etc/sysctl.conf</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/7090680990358829249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/7090680990358829249' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/7090680990358829249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/7090680990358829249'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2009/05/kernel-parameters.html' title='Kernel Parameters'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-6306901662035291040</id><published>2009-05-21T23:00:00.000-07:00</published><updated>2009-05-21T23:08:52.301-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="rmem"/><category scheme="http://www.blogger.com/atom/ns#" term="rmem_default"/><category scheme="http://www.blogger.com/atom/ns#" term="rmem_max"/><category scheme="http://www.blogger.com/atom/ns#" term="wmem"/><title type='text'>TCP Tuning in Linux.</title><content type='html'>&lt;div&gt;&lt;br /&gt;&lt;table width=&quot;100%&quot; nowrap=&quot;true&quot;&gt;&lt;tr&gt;&lt;th&gt;Command &lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt; &lt;br /&gt;&lt;tr&gt;&lt;td&gt;echo &quot;1&quot; &amp;gt; /proc/sys/net/ipv4/tcp_window_scaling&lt;/td&gt;&lt;td&gt; Activate window scaling according to RFC 1323&lt;/td&gt;&lt;/tr&gt; &lt;br /&gt;&lt;tr&gt;&lt;td&gt;echo &quot;1&quot; &amp;gt; /proc/sys/net/ipv4/tcp_timestamps &lt;/td&gt;&lt;td&gt;Activate timestamps according to RFC 1323 &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;echo 4194304 &amp;gt; /proc/sys/net/core/rmem_max &lt;/td&gt;&lt;td&gt;Set maximum size of TCP receive window. &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;echo 4194304 &amp;gt; /proc/sys/net/core/wmem_max &lt;/td&gt;&lt;td&gt;Set maximum size of TCP transmit window. &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;echo 4194304 &amp;gt; /proc/sys/net/core/rmem_default &lt;/td&gt;&lt;td&gt;Set default size of TCP receive window.  &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;echo 4194304 &amp;gt; /proc/sys/net/core/wmem_default &lt;/td&gt;&lt;td&gt;Set default size of TCP transmit window.  &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;echo &quot;[wmin] [wstd] [wmax]&quot; &amp;gt; /proc/sys/net/ipv4/tcp_rmem &lt;/td&gt;&lt;td&gt;Set min, default, max receive window. Used by the autotuning function. &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;echo &quot;[wmin] [wstd] [wmax]&quot; &amp;gt; /proc/sys/net/ipv4/tcp_wmem &lt;/td&gt;&lt;td&gt;Set min, default, max transmit window. Used by the autotuning function. &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;echo &quot;bmin bdef bmax&quot; &amp;gt; /proc/sys/net/ipv4/tcp_mem &lt;/td&gt;&lt;td&gt;Set maximum total TCP buffer-space allocatable. Used by the autotuning function. &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;ifconfig eth? txqueuelen 1000 &lt;/td&gt;&lt;td&gt;Define length of transmit queue. Replace &quot;?&quot; with actual interface number. &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/6306901662035291040/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/6306901662035291040' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/6306901662035291040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/6306901662035291040'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2009/05/tcp-tuning-in-linux.html' title='TCP Tuning in Linux.'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-629509929607025831</id><published>2009-04-22T05:34:00.000-07:00</published><updated>2011-12-05T23:29:50.397-08:00</updated><title type='text'>Cron Job</title><content type='html'>Create a file with commands whatever you want.&lt;br /&gt;
Say for example, I want to move files from /tmp/sps/a*.txt to /home/kdh/abc/ folder, every three minutes once.&lt;br /&gt;
&lt;br /&gt;
Step 1: create a file&lt;br /&gt;
vi cr1.sh&lt;br /&gt;
mv /tmp/sps/a*.txt  /home/kdh/abc/&lt;br /&gt;
:wq&lt;br /&gt;
&lt;br /&gt;
Step 2: Create and post a crontab for this command to run for every three minutes&lt;br /&gt;
crontab -e&lt;br /&gt;
*/3 * * * * /home/kdh/cr1.sh&lt;br /&gt;
:wq&lt;br /&gt;
&lt;br /&gt;
Now Cronjob is running, every three minutes. &lt;br /&gt;
&lt;br /&gt;
To display the jobs list :&lt;br /&gt;
&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
More details check for man crontab&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;# Minute &amp;nbsp; Hour &amp;nbsp; Day of Month &amp;nbsp; &amp;nbsp; &amp;nbsp; Month &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Day of Week &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Command &amp;nbsp; 

# (0-59) &amp;nbsp;(0-23) &amp;nbsp; &amp;nbsp; (1-31) &amp;nbsp; &amp;nbsp;(1-12 or Jan-Dec) &amp;nbsp;(0-6 or Sun-Sat) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 

&amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; * &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ls&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/629509929607025831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/629509929607025831' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/629509929607025831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/629509929607025831'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2009/04/cron-job.html' title='Cron Job'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-1901450539167128190</id><published>2009-04-15T03:17:00.000-07:00</published><updated>2009-04-15T03:19:04.362-07:00</updated><title type='text'>Unix Editors - vi, vim</title><content type='html'>Editors&lt;br /&gt;-------&lt;br /&gt;&lt;blockquote&gt;Line editors - ed, ex, sed&lt;br /&gt;Screen editors - vi, vim, emacs&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;vi works with three mode - command, insert, colon / last line mode / esc mode / ex mode&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;Vi Commands&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;To open Vi, simply type &quot;vi&quot; at the command prompt in a Unix terminal.&lt;br /&gt;Once Vi editor is running, you can use the following commands.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Moving the Cursor &lt;br /&gt;h One space to the left &lt;br /&gt;j One space to up &lt;br /&gt;k One space down &lt;br /&gt;l One space to the right &lt;br /&gt;&lt;br /&gt;&lt;Return&gt; Beginning of new line &lt;br /&gt;- Beginning of previous line &lt;br /&gt;^ Beginning of current line &lt;br /&gt;$ End of current line &lt;br /&gt;&lt;Space&gt; Forward one space &lt;br /&gt;nG Beginning of line n &lt;br /&gt;b Beginning of current word &lt;br /&gt;w Beginning of next word &lt;br /&gt;e End of current word &lt;br /&gt;Control - e Scroll forward &lt;br /&gt;Control - b Scroll backward &lt;br /&gt;/pattern First occurence of pattern &lt;br /&gt;n Next occurence of pattern &lt;br /&gt;N Previous occurence of pattern &lt;br /&gt;/ Repeats last pattern search&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Text Insertion and Deletion &lt;br /&gt;a Appends text to the right of the cursor &lt;br /&gt;A Appends text at the end of the line &lt;br /&gt;i Inserts text to the left of the cursor &lt;br /&gt;I Inserts text at the beginning of the line &lt;br /&gt;o Opens a new line below the current line for text to be inserted &lt;br /&gt;O Opens a new line above the current line for text to be inserted &lt;br /&gt;x Deletes character at cursor position &lt;br /&gt;X Deletes character left of cursor position &lt;br /&gt;dd Deletes current line &lt;br /&gt;dw Deletes current word &lt;br /&gt;d) Deletes rest of sentence &lt;br /&gt;D or d$ Deletes from cursor to end of line &lt;br /&gt;P Puts back text from the previous delete &lt;br /&gt;rx Replaces selected character with x &lt;br /&gt;u Undoes last change &lt;br /&gt;U Restores current line &lt;br /&gt;:R myfile Appends file &quot;myfile&quot; to current file at current cursor position &lt;br /&gt;DEL Overwrites last character during text insertion &lt;br /&gt;ESC Stops text insertion, returns to command mode &lt;br /&gt; &lt;br /&gt;Screen Commands &lt;br /&gt;Control - I Reprints current screen &lt;br /&gt;Control - L Exposes one more line at top of screen &lt;br /&gt;Control - E Exposes one more line at bottom of screen &lt;br /&gt;Control - F Pages forward one screen &lt;br /&gt;Control - B Pages back one screen &lt;br /&gt;Control - D Pages down half a screen &lt;br /&gt;Control - U Pages up half a screen &lt;br /&gt;&lt;br /&gt;Change Commands &lt;br /&gt;cw Changes characters of current word until escape key is pressed &lt;br /&gt;c$ Changes text up to the end of the line &lt;br /&gt;C or cc Changes remaining text on the current line until escape key is pressed &lt;br /&gt;~ Changes case of the current character &lt;br /&gt;xp Transposes the current and following characters &lt;br /&gt;J Joins current line with the next line &lt;br /&gt;s Deletes current character and enters insertion mode &lt;br /&gt;rx Replaces current character with x &lt;br /&gt;R Replaces the following characters until escape key is pressed &lt;br /&gt;yy Puts current line in a buffer without deleting the line &lt;br /&gt;p Places the line stored in buffer after the current position of the cursor &lt;br /&gt;&lt;br /&gt;Other helpful Vi notes: &lt;br /&gt;To create or edit a vi file:&lt;br /&gt;&lt;br /&gt;Type &quot;vi myfile&quot; where myfile is the name of the file to be created or edited.&lt;br /&gt;&lt;br /&gt;To close a vi file:&lt;br /&gt;&lt;br /&gt;ZZ -- Exits vi and saves changes made to the file. &lt;br /&gt;:wq -- Writes changes to current file and quits edit session. &lt;br /&gt;:q! -- Quits edit session and does not save changes. &lt;br /&gt;For complete documentation on Vi, type &quot;man vi&quot; at the Unix command prompt.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;To set custom commands for Vi permanently, create a file in home directory .exrc file&lt;br /&gt;&lt;br /&gt;set nu -- set line number on/off&lt;br /&gt;abbr os Operating Systems - set abbreviation &lt;br /&gt;map ^W  :w^M - map the commands</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/1901450539167128190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/1901450539167128190' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/1901450539167128190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/1901450539167128190'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2009/04/unix-editors-vi-vim.html' title='Unix Editors - vi, vim'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-4071059595069278525</id><published>2009-04-07T02:41:00.000-07:00</published><updated>2009-04-07T02:43:08.516-07:00</updated><title type='text'>Disk Usage in Linux or Unix</title><content type='html'>To find out folder size &lt;br /&gt;&lt;br /&gt;du -s /foldername/&lt;br /&gt;&lt;br /&gt;To find out all the subfolder and files size &lt;br /&gt;&lt;br /&gt;$du -ah /foldername</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/4071059595069278525/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/4071059595069278525' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/4071059595069278525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/4071059595069278525'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2009/04/disk-usage-in-linux-or-unix.html' title='Disk Usage in Linux or Unix'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-6380717397749642002</id><published>2009-04-01T03:45:00.000-07:00</published><updated>2009-04-01T03:46:28.118-07:00</updated><title type='text'>CPU Utilization in Unix/Linux</title><content type='html'>&lt;strong&gt;Top command to find out Linux cpu usage&lt;/strong&gt;&lt;br /&gt;# top&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Display the utilization of each CPU individually using mpstat&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;# mpstat &lt;br /&gt;&lt;br /&gt;# mpstat -P ALL&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Comparison of CPU utilization&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;# sar -u 2 5&lt;br /&gt;&lt;br /&gt;To get multiple samples and multiple reports set an output file for the sar command. Run the sar command as a background process using.&lt;br /&gt;# sar -o output.file 12 8 &gt;/dev/null 2&gt;&amp;1 &amp;&lt;br /&gt;&lt;br /&gt;Better use nohup command so that you can logout and check back report later on:&lt;br /&gt;# nohup sar -o output.file 12 8 &gt;/dev/null 2&gt;&amp;1 &amp;&lt;br /&gt;&lt;br /&gt;All data is captured in binary form and saved to a file (data.file). The data can then be selectively displayed ith the sar command using the -f option.&lt;br /&gt;# sar -f data.file&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Task: Find out who is monopolizing or eating the CPUs&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10&lt;br /&gt;ps -eo pcpu,pid,user,args | sort -r -k1 | less &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;iostat command&lt;/strong&gt;&lt;br /&gt;You can also use iostat command which report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions&lt;br /&gt;&lt;br /&gt;iostat&lt;br /&gt;&lt;br /&gt;iostat -xtc 5 3&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;GUI tools for your laptops/desktops&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;gnome-system-monitor</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/6380717397749642002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/6380717397749642002' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/6380717397749642002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/6380717397749642002'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2009/04/cpu-utilization-in-unixlinux.html' title='CPU Utilization in Unix/Linux'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-3389172426792224266</id><published>2008-11-12T06:27:00.001-08:00</published><updated>2008-11-12T06:27:23.992-08:00</updated><title type='text'>Fourth Day</title><content type='html'>ed  Editor&lt;br /&gt;--&lt;br /&gt;a append &lt;br /&gt;w write&lt;br /&gt;q quit&lt;br /&gt;p print&lt;br /&gt;s search&lt;br /&gt;u undo&lt;br /&gt;d delete&lt;br /&gt;g all the occurence in a line&lt;br /&gt;c change/replace &lt;br /&gt;i insert&lt;br /&gt;&lt;br /&gt;a &amp; i works on line-addressing format, can able to spcify only one line number.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$ed&lt;br /&gt;a&lt;br /&gt;heloo this is the data&lt;br /&gt;entered to ed to append &lt;br /&gt;of text&lt;br /&gt;.&lt;br /&gt;w file3&lt;br /&gt;50&lt;br /&gt;q&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$ ls file3&lt;br /&gt;file3&lt;br /&gt;&lt;br /&gt;$ed file3&lt;br /&gt;50&lt;br /&gt;p&lt;br /&gt;of text&lt;br /&gt;1,$p&lt;br /&gt;hel this is the data&lt;br /&gt;entered to ed to append&lt;br /&gt;of text&lt;br /&gt;s/text/TEXT&lt;br /&gt;p&lt;br /&gt;of TEXT&lt;br /&gt;u&lt;br /&gt;p&lt;br /&gt;of text&lt;br /&gt;1,$s/a/A/g&lt;br /&gt;1,$p&lt;br /&gt;hel this is the dAtA&lt;br /&gt;entered to ed to Append&lt;br /&gt;of text&lt;br /&gt;1&lt;br /&gt;hel this is the data&lt;br /&gt;a&lt;br /&gt;*********&lt;br /&gt;.&lt;br /&gt;w&lt;br /&gt;68&lt;br /&gt;1,2p&lt;br /&gt;hel this is the data&lt;br /&gt;*********&lt;br /&gt;c&lt;br /&gt;+++++++&lt;br /&gt;.&lt;br /&gt;1,2p&lt;br /&gt;hel this is the data&lt;br /&gt;+++++++&lt;br /&gt;1,$c&lt;br /&gt;Whole content will be changed&lt;br /&gt;.&lt;br /&gt;1,$p&lt;br /&gt;Whole content will be changed&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;sed   Stream Editor&lt;br /&gt;----&lt;br /&gt;sed [options] &#39;address Action ... &#39; [file(s)]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;here, address could be line or context based.&lt;br /&gt;&lt;br /&gt;Applys the action implicity global to all the lines.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  instruction1&lt;br /&gt;  instruction2&lt;br /&gt;   |&lt;br /&gt;Line---&gt;process-----&gt; output&lt;br /&gt;   |&lt;br /&gt;  Dynamic Pattern&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$sed &#39;s/cow/dog/&#39;&lt;br /&gt;cow&lt;br /&gt;dog&lt;br /&gt;cow1 cow&lt;br /&gt;dog1 cow&lt;br /&gt;^D&lt;br /&gt;&lt;br /&gt;$sed &#39;s/cow/dog/g&#39;&lt;br /&gt;cow1 cow&lt;br /&gt;dog1 dog&lt;br /&gt;^D&lt;br /&gt;&lt;br /&gt;$sed &#39;s/cow/dog/2&#39;&lt;br /&gt;cow1 cow&lt;br /&gt;cow1 dog&lt;br /&gt;^D&lt;br /&gt;&lt;br /&gt;$sed &#39;s/cow/dog/2,3&#39;&lt;br /&gt;cow cow cow&lt;br /&gt;cow dog dog&lt;br /&gt;^D&lt;br /&gt;&lt;br /&gt;$sed &#39;s/dog/cow/&lt;br /&gt;&gt; s/cow/horses/&#39;&lt;br /&gt;dog&lt;br /&gt;horses&lt;br /&gt;cow&lt;br /&gt;horses&lt;br /&gt;&lt;br /&gt;$sed &#39;s/://g&#39; /etc/passwd removes the : from all the lines of the file&lt;br /&gt;$sed &#39;1,4s/://g&#39; /etc/passwd removes the : from first 4 lines of the file&lt;br /&gt;$sed &#39;s/://g&#39; /etc/passwd /etc/shadow removed : from two files&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$sed &#39;1s/cow/dog/&#39;  apply only for first line&lt;br /&gt;cow&lt;br /&gt;dog&lt;br /&gt;cow&lt;br /&gt;cow&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$sed -e &#39;s/dog/cow/&#39; -e &#39;s/cow/horse/&#39;  multiple actions using -e&lt;br /&gt;dog&lt;br /&gt;horse&lt;br /&gt;cow&lt;br /&gt;horse&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$sed &#39;s/dog/cow/;s/cow/horse/&#39;   multiple actions using ; option&lt;br /&gt;cow&lt;br /&gt;horse&lt;br /&gt;dog&lt;br /&gt;horse&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$vi actions&lt;br /&gt;s/dog/cow/&lt;br /&gt;s/cow/horse/&lt;br /&gt;:wq&lt;br /&gt;&lt;br /&gt;#multiple actions storing in a file &lt;br /&gt;$sed -f actions  &lt;br /&gt;cow&lt;br /&gt;horse&lt;br /&gt;dog&lt;br /&gt;horse&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#context based address; if and only if root exist the hello will be changed as bye&lt;br /&gt;$sed &#39;/root/s/hello/bye/&#39;  &lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;root hello&lt;br /&gt;root bye&lt;br /&gt;hello root&lt;br /&gt;bye root&lt;br /&gt;&lt;br /&gt;#hello will be replace from Line which has root to line which has halt.&lt;br /&gt;$sed &#39;/root/,/halt/s/hello/bye/g&#39;  &lt;br /&gt;hello hello&lt;br /&gt;hello hello&lt;br /&gt;this is root line&lt;br /&gt;this is root line&lt;br /&gt;hello hello&lt;br /&gt;bye bye&lt;br /&gt;hello&lt;br /&gt;bye&lt;br /&gt;halt hello&lt;br /&gt;halt bye&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#replace until the empty line occurs&lt;br /&gt;$sed &#39;1,/^$/s/hello/bye/g&#39;&lt;br /&gt;hello&lt;br /&gt;bye&lt;br /&gt;   &lt;blank line typed here&gt;&lt;br /&gt;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;#do not apply to first two line replace operation&lt;br /&gt;$sed &#39;1,2!s/hello/bye/g&#39;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;hello hello&lt;br /&gt;hello hello&lt;br /&gt;hello&lt;br /&gt;bye&lt;br /&gt;&lt;br /&gt;Grouping commands&lt;br /&gt;-----------------&lt;br /&gt;address&lt;br /&gt;{&lt;br /&gt;instructions&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# print only when pattern matches&lt;br /&gt;$sed &#39;s/cow/dog/gp&#39;&lt;br /&gt;cow&lt;br /&gt;dog&lt;br /&gt;dog&lt;br /&gt;&lt;br /&gt;# prints and stores to abc file when pattern matches&lt;br /&gt;$sed &#39;s/cow/dog/gpw abc&#39;&lt;br /&gt;cow&lt;br /&gt;dog&lt;br /&gt;dog&lt;br /&gt;&lt;br /&gt;$cat abc &lt;br /&gt;dog&lt;br /&gt;&lt;br /&gt;#Store actions result in two different file&lt;br /&gt;$sed &#39;s/hello/bye/w mm&lt;br /&gt;&gt; s/old/new/w mm1&#39;&lt;br /&gt;hello&lt;br /&gt;bye&lt;br /&gt;old&lt;br /&gt;new&lt;br /&gt;$cat mm&lt;br /&gt;bye&lt;br /&gt;$cat mm1&lt;br /&gt;new&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;#store multiple actions result in same file&lt;br /&gt;$sed &#39;s/hello/bye/w mm&lt;br /&gt;s/old/new/w mm&#39;&lt;br /&gt;hello&lt;br /&gt;bye&lt;br /&gt;old&lt;br /&gt;new&lt;br /&gt;$cat mm&lt;br /&gt;bye&lt;br /&gt;new&lt;br /&gt;&lt;br /&gt;#if both pattern found two lines will be created&lt;br /&gt;$sed &#39;s/hello/bye/w mm&lt;br /&gt;s/old/new/w mm&#39;&lt;br /&gt;hello old&lt;br /&gt;bye new&lt;br /&gt;&lt;br /&gt;$cat mm&lt;br /&gt;bye old&lt;br /&gt;bye new&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Replacement part&lt;br /&gt;----------------&lt;br /&gt;&amp;  print pattern&lt;br /&gt;\n stored pattern retrieve, here n is number&lt;br /&gt;()  stores pattern&lt;br /&gt;&lt;br /&gt;#patterns are got remembered and placed using &amp; symbol&lt;br /&gt;&lt;br /&gt;$sed &#39;s/director/executive director/&#39;&lt;br /&gt;director&lt;br /&gt;executive director&lt;br /&gt;&lt;br /&gt;$sed &#39;s/director/executive &amp;/&#39;&lt;br /&gt;director&lt;br /&gt;executive director&lt;br /&gt;&lt;br /&gt;$sed &#39;s/director/&amp; executive &amp;/&#39;&lt;br /&gt;director&lt;br /&gt;director executive director&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# operator using \(.*\)  to select all the characters and saved as pattern&lt;br /&gt;# open and close phrase stores pattern and can be retrieved using \n, here n is number&lt;br /&gt;$cat &gt; text&lt;br /&gt;first:second&lt;br /&gt;third:fourth&lt;br /&gt;$sed &#39;s/\(.*\):\(.*\)/\2\1/&#39; text&lt;br /&gt;secondfirst&lt;br /&gt;fourththird&lt;br /&gt;$sed &#39;s/\(.*\):\(.*\)/\2+\1/&#39; text&lt;br /&gt;second+first&lt;br /&gt;fourth+third&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;delete command&lt;br /&gt;--------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$sed &#39;/root/d&#39;&lt;br /&gt;line&lt;br /&gt;line&lt;br /&gt;root&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;#delete line which ends with bash&lt;br /&gt;$sed &#39;/bash$/d&#39;&lt;br /&gt;hello krishna&lt;br /&gt;hello krishna&lt;br /&gt;hello bash&lt;br /&gt;hello xyz&lt;br /&gt;hello xyz&lt;br /&gt;&lt;br /&gt;$sed &#39;/^bash/d&#39;  delete line which start with bash&lt;br /&gt;$sed &#39;/^$/d&#39;  delete empty lines&lt;br /&gt;$sed &#39;1,/^$/d&#39;  delete upto empty lines&lt;br /&gt;sed &#39;/hello/,/bye/d&#39; delete lines including hello and bye lines and found lines in between of this pattern&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#appending&lt;br /&gt;$sed &#39;a\&lt;br /&gt;&gt; ****&#39;&lt;br /&gt;this&lt;br /&gt;this&lt;br /&gt;****&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;****&lt;br /&gt;&lt;br /&gt;#append for second line&lt;br /&gt;$sed &#39;2a\&lt;br /&gt;****&#39;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;****&lt;br /&gt;&lt;br /&gt;#append at the end of the line&lt;br /&gt;$sed &#39;$a\&lt;br /&gt;****&#39;&lt;br /&gt;a&lt;br /&gt;d&lt;br /&gt;a&lt;br /&gt;g&lt;br /&gt;d&lt;br /&gt;g&lt;br /&gt;****&lt;br /&gt;&lt;br /&gt;# append new line for each line&lt;br /&gt;$sed &#39;a&lt;br /&gt;&gt; &#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#backwardslash creates new line&lt;br /&gt;$sed &#39;1a\&lt;br /&gt;&gt; ****\&lt;br /&gt;&gt; \&lt;br /&gt;&gt; &#39;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;****&lt;br /&gt;&lt;br /&gt;Replace&lt;br /&gt;-------&lt;br /&gt;#replace in first line&lt;br /&gt;$sed &#39;1c\&lt;br /&gt;&gt; ****&#39;&lt;br /&gt;hello&lt;br /&gt;****&lt;br /&gt;hj&lt;br /&gt;hj&lt;br /&gt;&lt;br /&gt;# replace in all the lines&lt;br /&gt;$sed &#39;c\&lt;br /&gt;****&#39;&lt;br /&gt;hello&lt;br /&gt;****&lt;br /&gt;h&lt;br /&gt;****&lt;br /&gt;&lt;br /&gt;$sed &#39;1c\***&#39;&lt;br /&gt;h&lt;br /&gt;***&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;NonPrintable characters&lt;br /&gt;-----------------------&lt;br /&gt;# To display non-printable commands&lt;br /&gt;$sed &#39;l&#39;&lt;br /&gt;^D&lt;br /&gt;^D$&lt;br /&gt;^D&lt;br /&gt;^A&lt;br /&gt;^A$&lt;br /&gt;^A&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Transformation&lt;br /&gt;--------------&lt;br /&gt;&lt;br /&gt;Character to character transform&lt;br /&gt;&lt;br /&gt;$sed &#39;y/abc/xyz/&#39;&lt;br /&gt;abc&lt;br /&gt;xyz&lt;br /&gt;xyz&lt;br /&gt;xyz&lt;br /&gt;ball&lt;br /&gt;yxll&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Printing&lt;br /&gt;--------&lt;br /&gt;sed -n  to suppress the printing &lt;br /&gt;&lt;br /&gt;$sed &#39;p&#39;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;$sed -n &#39;p&#39;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;#print only the word root containing lines&lt;br /&gt;$sed -n &#39;/root/p&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# print line numbers  use = character in action&lt;br /&gt;$sed &#39;=&#39;&lt;br /&gt;line1&lt;br /&gt;1&lt;br /&gt;line1&lt;br /&gt;&lt;br /&gt;#two input stream read and line number is not getting resetted for secondstream&lt;br /&gt;$sed &#39;=&#39; - -&lt;br /&gt;hello&lt;br /&gt;1&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;2&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;#print totalnumber of line&lt;br /&gt;sed -n &#39;$=&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;#print line containing root&lt;br /&gt;$sed -n &#39;/root/=&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;#print text with line number&lt;br /&gt;$sed -n &#39;/root/=;/root/p&#39; /etc/passwd&lt;br /&gt;1&lt;br /&gt;root:x:0:0:root:/root:/bin/bash&lt;br /&gt;12&lt;br /&gt;operator:x:11:0:operator:/root:/sbin/nologin&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Reading&lt;br /&gt;-------&lt;br /&gt;[lineaddress]r file&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$sed &#39;r simple&#39;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;welcome&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Writing&lt;br /&gt;--------&lt;br /&gt;&lt;br /&gt;$sed &#39;w simple&#39;&lt;br /&gt;hellotyped&lt;br /&gt;hellotyped&lt;br /&gt;$cat simple&lt;br /&gt;hellotyped&lt;br /&gt;&lt;br /&gt;sed -n &#39;w simple&#39; /etc/passwd&lt;br /&gt;$cat simple&lt;br /&gt;&lt;here goes with content of /etcpasswd&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#Splitting file - first five line stored into file1 and remaining moved to file2&lt;br /&gt;$sed -n &#39;1,5w file1&lt;br /&gt;&gt;6,$w file2&#39;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;quit&lt;br /&gt;----&lt;br /&gt;[line-address]q&lt;br /&gt;&lt;br /&gt;# first five lines will be displayed and quit&lt;br /&gt;$sed &#39;5q&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;#first line will be processed&lt;br /&gt;$sed &#39;q&#39; /etc/passwd &lt;br /&gt;$sed &#39;q&#39; /etc/passwd /etc/shadow&lt;br /&gt;$sed &#39;q;=&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;#print first lines of all the files in folder&lt;br /&gt;for i in * ; do sed &#39;q&#39; $i;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#remove empty lines which found in between of hello and bye.&lt;br /&gt;&lt;br /&gt;$cat &gt; blank&lt;br /&gt;this&lt;br /&gt;&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;bye&lt;br /&gt;&lt;br /&gt;end&lt;br /&gt;$cat &gt; sedscr&lt;br /&gt;/hello/,/bye/{&lt;br /&gt;/^$/d&lt;br /&gt;}&lt;br /&gt;$sed -f sedscr blank&lt;br /&gt;this&lt;br /&gt;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;end&lt;br /&gt;bye&lt;br /&gt;&lt;br /&gt;end&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Advanced sed commands&lt;br /&gt;----------------------&lt;br /&gt;working wiht a multiple pattern space (N, D, P)&lt;br /&gt;Using the holds space to preserve  the contents of the pattern space and make it available for subsequent comments (H,h,G,g,x).&lt;br /&gt;&lt;br /&gt;N creates multiline patternspace&lt;br /&gt;--------------------------------&lt;br /&gt;&lt;br /&gt;vi next2&lt;br /&gt;/owner/{&lt;br /&gt;N&lt;br /&gt;s/owner *\n*and *\n*operator *\n*guide/installation guide/&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;vi next3&lt;br /&gt;/owner/{&lt;br /&gt;N&lt;br /&gt;s/ *\n/ /&lt;br /&gt;s/owner and operator guide */installation guide\&lt;br /&gt;/&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;D deletes a portion of the pattern space&lt;br /&gt;&lt;br /&gt;vi d3&lt;br /&gt;/^$/{&lt;br /&gt;N&lt;br /&gt;/^\n$/d&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;vi delete.dat&lt;br /&gt;this is followed by one blank line&lt;br /&gt;&lt;br /&gt;this is followed by two blank lines&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;this is followed by three&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;this is followed by four&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;the end.&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$sed -f d3 delete.dat&lt;br /&gt;this is followed by one blank line&lt;br /&gt;&lt;br /&gt;this is followed by two blank lines&lt;br /&gt;this is followed by three&lt;br /&gt;&lt;br /&gt;this is followed by four&lt;br /&gt;the end.&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;vi d4&lt;br /&gt;/^$/{&lt;br /&gt;N&lt;br /&gt;/^\n$/d&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$sed -f d4 delete.dat&lt;br /&gt;this is followed by one blank line&lt;br /&gt;&lt;br /&gt;this is followed by two blank lines&lt;br /&gt;&lt;br /&gt;this is followed by three&lt;br /&gt;&lt;br /&gt;this is followed by four&lt;br /&gt;&lt;br /&gt;the end.&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;H hold - h or H   copy or append contents of PS to Hold Space&lt;br /&gt;G get - g or G  - copy or append contents of HS to Pattern Space&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$sed &#39;G&#39; /etc/passwd&lt;br /&gt;$sed &#39;g&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;$sed &#39;/root/G&#39;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;root&lt;br /&gt;root&lt;br /&gt;&lt;br /&gt;wow root welcome&lt;br /&gt;wow root welcome&lt;br /&gt;&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$sed &#39;/root/g&#39;&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;root&lt;br /&gt;&lt;br /&gt;$vi ad3&lt;br /&gt;/1/{&lt;br /&gt;h&lt;br /&gt;d&lt;br /&gt;}&lt;br /&gt;/2/{&lt;br /&gt;G&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$vi ad3.dat&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;$sed -f ad3 ad3.dat&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;awk&lt;br /&gt;---&lt;br /&gt;awk [-options] &#39;pattern action  ...&#39; [file(s)...]&lt;br /&gt;&lt;br /&gt;awk is filter.&lt;br /&gt;&lt;br /&gt;Used for Report generation, &lt;br /&gt;Some of feature carried from c and shell programming&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$awk &#39;/root/&#39; /etc/passwd&lt;br /&gt;root:x:0:0:root:/root:/bin/bash&lt;br /&gt;operator:x:11:0:operator:/root:/sbin/nologin&lt;br /&gt;$awk /root/&lt;br /&gt;hroot&lt;br /&gt;hroot&lt;br /&gt;root&lt;br /&gt;root&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$awk /^root/&lt;br /&gt;hroot&lt;br /&gt;root&lt;br /&gt;root&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$awk &#39;/^[0-9]+$/&#39;&lt;br /&gt;abcd&lt;br /&gt;12&lt;br /&gt;12&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$awk &#39;/root/{print }&#39;&lt;br /&gt;a&lt;br /&gt;root&lt;br /&gt;root&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;Field selection&lt;br /&gt;---------------&lt;br /&gt;$0 complete line&lt;br /&gt;$1 first field&lt;br /&gt;$10 tenth field&lt;br /&gt;&lt;br /&gt;$awk &#39;{print $1,$2}&#39;&lt;br /&gt;this is line one&lt;br /&gt;this is&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$awk &#39;{print $0}&#39;&lt;br /&gt;this is line one&lt;br /&gt;this is line one&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$awk &#39;/root/&lt;br /&gt;&gt; /halt/&#39;&lt;br /&gt;this root&lt;br /&gt;this root&lt;br /&gt;this roo&lt;br /&gt;halt&lt;br /&gt;halt&lt;br /&gt;root halt&lt;br /&gt;root halt&lt;br /&gt;root halt&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$awk &#39;/root/{print $0}&lt;br /&gt;&gt; /halt/{print}&#39;&lt;br /&gt;this root&lt;br /&gt;this root&lt;br /&gt;halt&lt;br /&gt;halt&lt;br /&gt;root halt&lt;br /&gt;root halt&lt;br /&gt;root halt&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;Default delimiter could be whitespaces like space, tab.&lt;br /&gt;&lt;br /&gt;$awk -F &quot;:&quot; &#39;{print $3}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;awk -F &quot;:&quot; &#39;/root/{print $3}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;$awk &#39;/[a-z]+/{print &quot;Alphabets&quot;}&lt;br /&gt;/[0-9]+/{print &quot;Numerals&quot;}&lt;br /&gt;/^$/{print &quot;Blank&quot;}&#39;&lt;br /&gt;fds23&lt;br /&gt;Alphabets&lt;br /&gt;Numerals&lt;br /&gt;232&lt;br /&gt;Numerals&lt;br /&gt;sds&lt;br /&gt;Alphabets&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;#multiple field separotor&lt;br /&gt;$awk -F &quot;[:,+]&quot; &#39;/root/{print $3}&#39;&lt;br /&gt;1:2,3:4&lt;br /&gt;root:2+4:5&lt;br /&gt;4&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$awk -F &quot;[:,+]+&quot; &#39;/root/{print $3}&#39;&lt;br /&gt;root::,2+4:5&lt;br /&gt;4&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;#prints fields with space&lt;br /&gt;awk -F : &#39;{print $1,$3}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;#string concatenated&lt;br /&gt;awk -F : &#39;{print $1$3}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;$awk -F : &#39;{print $1+$3}&#39; /etc/passwd&lt;br /&gt;$awk -F : &#39;{print $1&quot;+&quot;$3}&#39; /etc/passwd&lt;br /&gt;$awk -F : &#39;{print $1&quot;\t\t&quot;$3}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;printf&lt;br /&gt;------&lt;br /&gt;&lt;br /&gt;$awk -F : &#39;{printf(&quot;%15s%15s\n&quot;,$1,$7)}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;$awk -F : &#39;{printf(&quot;%-15s%-15s\n&quot;,$1,$7)}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;$awk -F : &#39;{printf(&quot;|%15s||%15s|\n&quot;,$1,$7)}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#Redirecting to file&lt;br /&gt;$ls -l | awk &#39;{print $5 &gt; &quot;out&quot;}&#39;&lt;br /&gt;&lt;br /&gt;#piping &lt;br /&gt;$ls -l | awk &#39;{print $5 | &quot;sort -n &quot;}&#39;&lt;br /&gt;$ls -l | awk &#39;{print $5}&#39; | sort -n&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;awk script from file&lt;br /&gt;---------------------&lt;br /&gt;$cat &gt; awkscr&lt;br /&gt;/root/{print $1}&lt;br /&gt;/halt/{print $0}&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$awk -f awkscr&lt;br /&gt;roor is root&lt;br /&gt;roor&lt;br /&gt;halt is fsdf&lt;br /&gt;halt is fsdf&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;Artihmatic operation:&lt;br /&gt;&lt;br /&gt;$awk &#39;{print $1 + 5}&#39;&lt;br /&gt;4&lt;br /&gt;9&lt;br /&gt;$awk &#39;{print $1 / 5}&#39;&lt;br /&gt;34&lt;br /&gt;6.8&lt;br /&gt;40&lt;br /&gt;8&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;#Delimiter &lt;br /&gt;$awk -F : &#39;{print $1,$2}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#if particular field satisfies the condition then print&lt;br /&gt;$awk &#39;$3 &gt;50&#39;&lt;br /&gt;this is 344&lt;br /&gt;this is 344&lt;br /&gt;this is 50&lt;br /&gt;this is 49&lt;br /&gt;&lt;br /&gt;#with logical operators&lt;br /&gt;$awk -F : &#39;$3 &gt;500 &amp;&amp; $3 &lt;=510{print $3}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;$awk -F : &#39;$1 == &quot;root&quot;&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#regular expressions applied using ~ sumbol&lt;br /&gt;$awk &#39;$3 ~ /^root/&#39;&lt;br /&gt;this is root&lt;br /&gt;this is root&lt;br /&gt;this is bash&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$awk &#39;$3 !~ /^root/&#39;&lt;br /&gt;this is root&lt;br /&gt;this is bash&lt;br /&gt;this is bash&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#++ operator usage&lt;br /&gt;$awk &#39;/^$/{print ++x}&#39;&lt;br /&gt;&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;3&lt;br /&gt;dff&lt;br /&gt;&lt;br /&gt;4&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;awk &#39;{print NR}&#39;&lt;br /&gt;line1&lt;br /&gt;1&lt;br /&gt;line2&lt;br /&gt;2&lt;br /&gt;$&lt;br /&gt;$awk &#39;{print NR}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;# prints the line with number - NR - Number of Record&lt;br /&gt;$awk &#39;{print NR, $0}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$awk &#39;{print NR}&#39; /etc/passwd /etc/shadow&lt;br /&gt;#FNR get resetted&lt;br /&gt;$awk &#39;{print FNR}&#39; /etc/passwd /etc/shadow&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#NF - number of Fields&lt;br /&gt;$awk &#39;{print NF}&#39; /etc/passwd &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#read fourth field using arithmatic calculations&lt;br /&gt;$awk &#39;{print $(2*2)}&#39;&lt;br /&gt;1 2 3 4 5&lt;br /&gt;4&lt;br /&gt;&lt;br /&gt;#last field of each record&lt;br /&gt;$awk &#39;{print $(NF)}&#39;&lt;br /&gt;1 2 3 4 5&lt;br /&gt;5&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Storing and running Awk script:&lt;br /&gt;-------------------------------&lt;br /&gt;$vi awk4&lt;br /&gt;#!/bin/awk -f&lt;br /&gt;{print $0}&lt;br /&gt;&lt;br /&gt;$&lt;br /&gt;$chmod +x awk4&lt;br /&gt;$./awk4&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;AWK programming model&lt;br /&gt;&lt;br /&gt;BEGIN&lt;br /&gt;MAIN&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;BEGIN  used to print the heading/Declaring variables&lt;br /&gt;END  used to print the summary/totals&lt;br /&gt;BEGIN and END sections are optional&lt;br /&gt;BEGIN (action)&lt;br /&gt;END (action)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$awk &#39;BEGIN{print &quot;Welcome to AWK programming&quot;}&#39;&lt;br /&gt;Welcome to AWK programming&lt;br /&gt;&lt;br /&gt;$awk &#39;BEGIN{print &quot;Welcome to AWK programming&quot;}{print}&#39;&lt;br /&gt;Welcome to AWK programming&lt;br /&gt;first&lt;br /&gt;first&lt;br /&gt;second&lt;br /&gt;second&lt;br /&gt;&lt;br /&gt;$awk &#39;BEGIN{print &quot;Welcome to AWK programming&quot;}{print}END{print &quot;Over&quot;}&#39;&lt;br /&gt;Welcome to AWK programming&lt;br /&gt;first&lt;br /&gt;first&lt;br /&gt;second&lt;br /&gt;^D&lt;br /&gt;Over&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$awk &#39;END{print &quot;Number of records processed&quot;, NR}&#39;&lt;br /&gt;Hello&lt;br /&gt;it is me&lt;br /&gt;look for total number of Records processed&lt;br /&gt;Number of records processed 3&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;#FS - Field Separator&lt;br /&gt;$awk &#39;BEGIN{FS=&quot;:&quot;}{print $3}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;#OFS - Output Field Separator&lt;br /&gt;$awk &#39;BEGIN{FS=&quot;:&quot;;OFS=&quot;+&quot;}{print $1,$3}&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;#check current directory holding file size&lt;br /&gt;ls -l | awk &#39;BEGIN{sum=0}{sum=sum+$5}END{print &quot;total&quot;,sum}&#39;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Passing Variables&lt;br /&gt;-----------------&lt;br /&gt;&lt;br /&gt;$awk -v var=1 &#39;{print $var}&#39;&lt;br /&gt;hello r u there&lt;br /&gt;hello&lt;br /&gt;wow&lt;br /&gt;wow&lt;br /&gt;$awk -v var=2 &#39;{print $var}&#39;&lt;br /&gt;hello r u there&lt;br /&gt;r&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Builtin functions in awk&lt;br /&gt;------------------------&lt;br /&gt;$awk &#39;{print int($1)}&#39;&lt;br /&gt;34&lt;br /&gt;34&lt;br /&gt;45&lt;br /&gt;45&lt;br /&gt;&lt;br /&gt;$awk &#39;{print sqrt($1)}&#39;&lt;br /&gt;34&lt;br /&gt;5.83095&lt;br /&gt;9&lt;br /&gt;3&lt;br /&gt;&lt;br /&gt;$awk &#39;{print length($1)}&#39;&lt;br /&gt;sdsdsd&lt;br /&gt;6&lt;br /&gt;hello&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;$awk &#39;{print length($0)}&#39;&lt;br /&gt;wow this&lt;br /&gt;8&lt;br /&gt;working&lt;br /&gt;7&lt;br /&gt;&lt;br /&gt;$awk &#39;{print toupper($0)}&#39;&lt;br /&gt;hello&lt;br /&gt;HELLO&lt;br /&gt;&lt;br /&gt;$awk &#39;{print tolower($0)}&#39;&lt;br /&gt;HELLO&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;$awk &#39;{print substr($1,1,2)}&#39;&lt;br /&gt;this&lt;br /&gt;th&lt;br /&gt;wonderful&lt;br /&gt;wo&lt;br /&gt;&lt;br /&gt;$awk &#39;{print substr($1,3,2)}&#39;&lt;br /&gt;1990&lt;br /&gt;90&lt;br /&gt;&lt;br /&gt;$awk &#39;{print substr($1,3)}&#39;&lt;br /&gt;1990&lt;br /&gt;90&lt;br /&gt;1990000&lt;br /&gt;90000&lt;br /&gt;&lt;br /&gt;#substring in regular expression&lt;br /&gt;$awk &#39;substr($1,3,2) &gt;45 &amp;&amp; substr($1,3,2) &lt; 90&#39;&lt;br /&gt;1940&lt;br /&gt;1946&lt;br /&gt;1946&lt;br /&gt;1980&lt;br /&gt;1980&lt;br /&gt;1990&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;#Split function&lt;br /&gt;$awk &#39;{split($0,arr,&quot;:&quot;);print arr[1]}&#39;&lt;br /&gt;this:is:find&lt;br /&gt;this&lt;br /&gt;$awk &#39;{split($0,arr,&quot;:&quot;);print arr[2]}&#39;&lt;br /&gt;19:23:45&lt;br /&gt;23&lt;br /&gt;$awk &#39;{split($0,arr,&quot;:&quot;);print &quot;hello&quot; arr[2]}&#39;&lt;br /&gt;ram:krishna:moorthy&lt;br /&gt;hellokrishna&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;#system function used to run unix command&lt;br /&gt;$awk &#39;BEGIN{system(&quot;date&quot;)}&#39;&lt;br /&gt;Fri Oct 24 16:07:02 IST 2008&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#displays the line which has more than 65 chracters&lt;br /&gt;$awk &#39;length &gt;65&#39; /etc/passwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;substituions functions&lt;br /&gt;----------------------&lt;br /&gt;sub() &lt;br /&gt;gsub()&lt;br /&gt;gensub()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$awk &#39;{print sub(&quot;root&quot;,&quot;hello&quot;)}&#39;&lt;br /&gt;root&lt;br /&gt;1&lt;br /&gt;this is root root&lt;br /&gt;1&lt;br /&gt;$awk &#39;{print gsub(&quot;root&quot;,&quot;hello&quot;)}&#39;&lt;br /&gt;root root&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;$awk &#39;{print gsub(&quot;root&quot;,&quot;hello&quot;,$1)}&#39;&lt;br /&gt;hello root&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$awk &#39;{print gsub(&quot;root&quot;,&quot;hello&quot;,$1);print}&#39;&lt;br /&gt;hello&lt;br /&gt;0&lt;br /&gt;hello&lt;br /&gt;root&lt;br /&gt;1&lt;br /&gt;hello&lt;br /&gt;$awk &#39;{gsub(&quot;root&quot;,&quot;hello&quot;,$1);print}&#39;&lt;br /&gt;root&lt;br /&gt;hello&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$awk &#39;{print gensub(&quot;root&quot;,&quot;hello&quot;,1)}&#39;&lt;br /&gt;root root&lt;br /&gt;hello root&lt;br /&gt;&lt;br /&gt;$awk &#39;{print gensub(&quot;root&quot;,&quot;hello&quot;,&quot;G&quot;)}&#39;&lt;br /&gt;root root&lt;br /&gt;hello hello&lt;br /&gt;$awk &#39;{print gensub(&quot;root&quot;,&quot;hello&quot;,&quot;g&quot;)}&#39;&lt;br /&gt;root root&lt;br /&gt;hello hello&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#getline method stores result of previous output&#39;s last line&lt;br /&gt;$ awk &#39;BEGIN{ &quot;date&quot; | getline name ; print name}&#39;&lt;br /&gt;Fri Oct 24 16:20:59 IST 2008&lt;br /&gt;$ awk &#39;BEGIN{ &quot;date&quot; | getline name ; print &quot;date is &quot;name}&#39;&lt;br /&gt;date is Fri Oct 24 16:21:27 IST 2008&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;#getline method holds input from std in &lt;br /&gt;$awk &#39;BEGIN{print &quot;Enter your name&quot;&lt;br /&gt;&gt; getline name &lt;&quot;-&quot;&lt;br /&gt;&gt; print name&lt;br /&gt;&gt; }&lt;br /&gt;&gt; &#39;&lt;br /&gt;Enter your name&lt;br /&gt;krishna&lt;br /&gt;krishna&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$awk &#39;BEGIN{getline record  &lt; &quot;/etc/passwd&quot;;print record}&#39;&lt;br /&gt;root:x:0:0:root:/root:/bin/bash&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#subdate method to do mail merge of operation&lt;br /&gt;$cat subdate.awk&lt;br /&gt;/@date/{&lt;br /&gt;        &quot;date +&#39;%a., %h %d, %y&#39;&quot; | getline today&lt;br /&gt;        gsub(/@date/, today)&lt;br /&gt;}&lt;br /&gt;{ print }&lt;br /&gt;$cat subdate.test&lt;br /&gt;I am writing mail on @date to my friend.&lt;br /&gt;this has to reach on @date.&lt;br /&gt;$awk -f subdate.awk subdate.test&lt;br /&gt;I am writing mail on Fri., Oct 24, 08 to my friend.&lt;br /&gt;this has to reach on Fri., Oct 24, 08.&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$cat awkfor1&lt;br /&gt;#!/bin/awk -f&lt;br /&gt;{&lt;br /&gt;s=0&lt;br /&gt;for (i=1; i&lt;= NF; i++ )&lt;br /&gt;s=s+$i&lt;br /&gt;print s&lt;br /&gt;}&lt;br /&gt;./awkfor1&lt;br /&gt;22&lt;br /&gt;22&lt;br /&gt;2 ee&lt;br /&gt;2&lt;br /&gt;3 44&lt;br /&gt;47&lt;br /&gt;5 6 7&lt;br /&gt;18&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;do while&lt;br /&gt;--------&lt;br /&gt;&lt;br /&gt;cat &gt;awkwhile1&lt;br /&gt;{&lt;br /&gt; total=i=0&lt;br /&gt; do {&lt;br /&gt;   ++i&lt;br /&gt;   total +=$i&lt;br /&gt;  }while( total &lt;=100 )&lt;br /&gt;  print i, &quot;:&quot;, total&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#after press enter, all the lines of /etc/passwd will be displayed&lt;br /&gt;$awk &#39;{while ((getline &lt; &quot;/etc/passwd&quot;) &gt; 0) print }&#39;&lt;br /&gt;&lt;br /&gt;#just displays all the lines&lt;br /&gt;$awk &#39;BEGIN{while ((getline &lt; &quot;/etc/passwd&quot;) &gt; 0) print }&#39;</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/3389172426792224266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/3389172426792224266' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/3389172426792224266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/3389172426792224266'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2008/11/fourth-day.html' title='Fourth Day'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-2197433214290625554</id><published>2008-11-12T06:26:00.002-08:00</published><updated>2008-11-12T06:27:01.251-08:00</updated><title type='text'>Third Day</title><content type='html'>Until&lt;br /&gt;-----&lt;br /&gt;&lt;br /&gt;until control command&lt;br /&gt;do&lt;br /&gt; commands&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#list the numbers reverse, if user enters more than ten&lt;br /&gt;echo Enter the number&lt;br /&gt;read num&lt;br /&gt;until [ $num -le 10 ]&lt;br /&gt;do&lt;br /&gt; echo $num&lt;br /&gt; num=`expr $num - 1`&lt;br /&gt;done&lt;br /&gt;echo &quot;Out of Until loop&quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#get ordinary filename from user until then continue&lt;br /&gt;echo enter the filename&lt;br /&gt;read fname&lt;br /&gt;until [ -f $fname ]&lt;br /&gt;do&lt;br /&gt;        echo $fname is  not an ordinary file&lt;br /&gt;        read fname&lt;br /&gt;done&lt;br /&gt;echo $fname is an ordinary file&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Write a script to generate the number sequence 20.0 , 19.9, 19.8, 19.7 ... 10.0&lt;br /&gt;&lt;br /&gt;num1=20.00&lt;br /&gt;until [ &quot;$num1&quot; = &quot;10.00&quot; ]&lt;br /&gt;do&lt;br /&gt;        echo $num1&lt;br /&gt;        num1=`echo  $num1 - 0.1 | bc`&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Write a script to check whether the particular user already logged in or not. If not logged in then wait until he logged in . Script has to run in background.&lt;br /&gt;&lt;br /&gt;echo Enter user name&lt;br /&gt;read user&lt;br /&gt;sec=0&lt;br /&gt;until [  `who | cut -f1 -d &quot; &quot; | grep $user` ]  &lt;br /&gt;# even we can use regular expression to get exactly matchinguser name&lt;br /&gt;do&lt;br /&gt;sec=`expr $sec + 10`&lt;br /&gt;sleep 10&lt;br /&gt;done&lt;br /&gt;echo &quot;waited for ${sec}s&quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Case&lt;br /&gt;-----&lt;br /&gt;case value in&lt;br /&gt;choice 1)&lt;br /&gt; commands;;&lt;br /&gt;choice 2)&lt;br /&gt; commands;;&lt;br /&gt;esac&lt;br /&gt;&lt;br /&gt;In shell script case statement, do not have dafault key word. *) used for the same and it can present anywhere in case but rest of the choices will not work.&lt;br /&gt;&lt;br /&gt;echo -e &quot;Enter the choice:\c&quot;&lt;br /&gt;read ch&lt;br /&gt;case $ch in&lt;br /&gt;1)&lt;br /&gt; ls ;;&lt;br /&gt;2)&lt;br /&gt; who ;;&lt;br /&gt;3)&lt;br /&gt; date;;&lt;br /&gt;*)&lt;br /&gt; echo Default&lt;br /&gt;;;&lt;br /&gt;esac&lt;br /&gt;&lt;br /&gt;# we can use regular expression also as choice&lt;br /&gt;echo -e &quot;Enter the choice:\c&quot;&lt;br /&gt;read ch&lt;br /&gt;case $ch in&lt;br /&gt;[lL]*)&lt;br /&gt; ls ;;&lt;br /&gt;[wW]*)&lt;br /&gt; who ;;&lt;br /&gt;3 | 4)&lt;br /&gt; date;;&lt;br /&gt;*)&lt;br /&gt; echo Default;;&lt;br /&gt;esac&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#we can use string also for choice&lt;br /&gt;echo -e &quot;Enter the choice:\c&quot;&lt;br /&gt;read ch&lt;br /&gt;case &quot;$ch&quot; in&lt;br /&gt;&quot;ls&quot;)&lt;br /&gt; ls ;;&lt;br /&gt;*)&lt;br /&gt; echo Default;;&lt;br /&gt;esac&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Control statements&lt;br /&gt;------------------&lt;br /&gt;&lt;br /&gt;tput clear&lt;br /&gt;while true&lt;br /&gt;do&lt;br /&gt;        echo -e &quot;Enter your choice:\c&quot;&lt;br /&gt;        read ch&lt;br /&gt;        case &quot;$ch&quot; in&lt;br /&gt;        1)&lt;br /&gt;  while true&lt;br /&gt;        do&lt;br /&gt;                echo -e &quot;Enter your number:\c&quot;&lt;br /&gt;                read num&lt;br /&gt;                if [ $num -le 10 ]&lt;br /&gt;                then&lt;br /&gt;                        echo $num is less than or equal to 10&lt;br /&gt;                        echo Do you want to continue&lt;br /&gt;                        read ans&lt;br /&gt;                        if [ &quot;$ans&quot; = &quot;Y&quot; -o &quot;$ans&quot; = &quot;y&quot; ]&lt;br /&gt;                        then&lt;br /&gt;                                continue&lt;br /&gt;                        else&lt;br /&gt;                                break&lt;br /&gt;                        fi&lt;br /&gt;                else&lt;br /&gt;                        echo number is greater than 10&lt;br /&gt;                fi&lt;br /&gt;        done&lt;br /&gt;        ;;&lt;br /&gt;        2)&lt;br /&gt;        echo &quot;default option entered and exiting&quot;&lt;br /&gt;        exit&lt;br /&gt;        esac&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;tput - screen interface command&lt;br /&gt;tput bold bold&lt;br /&gt;tput smso reverse background&lt;br /&gt;tput rmso normal background&lt;br /&gt;tput reset  &lt;br /&gt;tput cup 10 20  expect input from 10 row 20 position&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Write a script to display stars like below&lt;br /&gt;*&lt;br /&gt;**&lt;br /&gt;***&lt;br /&gt;****&lt;br /&gt;***&lt;br /&gt;**&lt;br /&gt;*&lt;br /&gt;&lt;br /&gt;echo enter number&lt;br /&gt;read num&lt;br /&gt;num1=1&lt;br /&gt;while [ $num1 -le $num ]&lt;br /&gt;do&lt;br /&gt;        star=`echo &quot;$star*&quot;`&lt;br /&gt;        echo &quot;$star&quot;&lt;br /&gt;        num1=`expr $num1 + 1`&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;num1=`expr $num1 - 1`&lt;br /&gt;&lt;br /&gt;until [ $num1 -lt 1 ]&lt;br /&gt;do&lt;br /&gt;num1=`expr $num1 - 1`&lt;br /&gt;if [ $num1 -eq 0 ]&lt;br /&gt;then&lt;br /&gt;break&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;star=`echo &quot;$star&quot; | cut -c1-$num1`&lt;br /&gt;echo &quot;$star&quot;&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#Multiplication Table upto 10 times for any of the number&lt;br /&gt;&lt;br /&gt;1 * 5 =5&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;10 * 5 = 50&lt;br /&gt;&lt;br /&gt;echo Enter number&lt;br /&gt;read num&lt;br /&gt;times=1&lt;br /&gt;until [ $times -eq 11 ]&lt;br /&gt;do&lt;br /&gt;&lt;br /&gt;echo &quot;$times * $num = `expr $times \* $num`&quot;&lt;br /&gt;times=`expr $times + 1`&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;trap&lt;br /&gt;----&lt;br /&gt;trap &#39;echo Interrupted&#39; 2   press CTRL c then &quot;Interrupted&quot; string will be printed&lt;br /&gt;&lt;br /&gt;trap - 2  to remove the trap&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#Until user say hello don&#39;t allow to do something and stop interrupting or quiting&lt;br /&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;trap &quot;echo you have pressed : Cannot escape&quot; 1 2&lt;br /&gt;echo &quot;Terminal Locked&quot;&lt;br /&gt;read key&lt;br /&gt;while true&lt;br /&gt;do&lt;br /&gt;        echo -e &quot;enter your password:\c&quot;&lt;br /&gt;        stty -echo&lt;br /&gt;        read pw&lt;br /&gt;        stty sane&lt;br /&gt;        if [ &quot;$pw&quot; = &quot;hello&quot; ]&lt;br /&gt;        then&lt;br /&gt;                break&lt;br /&gt;        else&lt;br /&gt;                echo &quot;Wrong! password Illegal user&quot;&lt;br /&gt;        fi&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;export&lt;br /&gt;------&lt;br /&gt;&lt;br /&gt;copies the variable for all shells which get created in this process&lt;br /&gt;If any change has happened in child shell for this variable will not impacted in parent process. It is quivelent to passing by Value argument.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#demo on export command&lt;br /&gt;#export.sh&lt;br /&gt;echo The value of x is $x&lt;br /&gt;x=100&lt;br /&gt;echo Now the value of x is $x&lt;br /&gt;sleep 1&lt;br /&gt;echo Process ID is $$&lt;br /&gt;echo Your are about to leave this process&lt;br /&gt;sleep 10&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$x=10&lt;br /&gt;$echo $$&lt;br /&gt;234&lt;br /&gt;&lt;br /&gt;$sh export.sh&lt;br /&gt;The value of x is&lt;br /&gt;Now the value of x is 100&lt;br /&gt;Process ID is 24633&lt;br /&gt;Your are about to leave this process&lt;br /&gt;&lt;br /&gt;$export x&lt;br /&gt;&lt;br /&gt;$sh export.sh&lt;br /&gt;The value of x is 10&lt;br /&gt;Now the value of x is 100&lt;br /&gt;Process ID is 24644&lt;br /&gt;Your are about to leave this process&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Shells and Sub-shells&lt;br /&gt;---------------------&lt;br /&gt;sh filename&lt;br /&gt;sh &lt; filename  here filename holds script file&lt;br /&gt;&lt;br /&gt;Interpreter Line&lt;br /&gt;----------------&lt;br /&gt;#!/bin/ksh  to create/switch temporarily a shell&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;() brackets used to group the commands in sub-shells&lt;br /&gt;&lt;br /&gt;$date ; who ; ls |&gt; out  only the output of ls will be stored in out file&lt;br /&gt;$( date ; who ; ls ) |&gt; out  the output of date, who and ls will be stored in out file&lt;br /&gt;&lt;br /&gt;{} - paranthesis used to group the command and run in same shell&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$pwd&lt;br /&gt;root&lt;br /&gt;$( cd /var ; ls )&lt;br /&gt;ls output goes here&lt;br /&gt;$pwd&lt;br /&gt;root&lt;br /&gt;&lt;br /&gt;${ cd /var ; ls }&lt;br /&gt;ls output goes here&lt;br /&gt;$pwd&lt;br /&gt;var&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Dot commands&lt;br /&gt;------------&lt;br /&gt;. scriptfile runs in current shell&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$vi demo1.sh&lt;br /&gt;echo Process id $$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$echo $$&lt;br /&gt;567&lt;br /&gt;$ sh demo1.sh&lt;br /&gt;Process id 8888&lt;br /&gt;$. demo1.sh&lt;br /&gt;Process is 567&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.bashrc file - &lt;br /&gt;------------&lt;br /&gt;&lt;br /&gt;this file get executed while making login&lt;br /&gt;&lt;br /&gt;.bash_profile - current login shells - means this will impact only for currently logged in shells&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;KORN/BASH&lt;br /&gt;---------&lt;br /&gt;&lt;br /&gt;let : computation (KORN/BASH)&lt;br /&gt;----&lt;br /&gt;$let  sum=&quot; 3 + 4&quot;&lt;br /&gt;$echo $sum&lt;br /&gt;7&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$echo $(date) in KORN/BASH, we can use this format to retrieve variable value&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Computation with (( ))  two brackets&lt;br /&gt;------------------------------------&lt;br /&gt;Here no need of giving $ for all the variables&lt;br /&gt;x=10 &lt;br /&gt;y=10 &lt;br /&gt;z=10&lt;br /&gt;&lt;br /&gt;sum=$((x+y+z));echo $sum&lt;br /&gt;z=$((z+1));echo $z&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Here Document (&lt;&lt;)&lt;br /&gt;-----------------------&lt;br /&gt;&lt;br /&gt;waits for END character to typed by user&lt;br /&gt;&lt;br /&gt;$cat &lt;&lt; END&lt;br /&gt;&gt;this is&lt;br /&gt;&gt;waiting &lt;br /&gt;&gt;for &lt;br /&gt;&gt;END&lt;br /&gt;this is&lt;br /&gt;waiting &lt;br /&gt;for&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$cat &lt;&lt; END&lt;br /&gt;&gt; this is input&lt;br /&gt;&gt; send on `date +%D`&lt;br /&gt;&gt; to `whoami` user&lt;br /&gt;&gt;END&lt;br /&gt;this is input&lt;br /&gt;send on 10/23/08&lt;br /&gt;to user3 user&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#Write a program to send the mail using here document&lt;br /&gt;&lt;br /&gt;$vi here1.sh&lt;br /&gt;#!/bin/sh&lt;br /&gt;echo this is to test the here document&lt;br /&gt;echo&lt;br /&gt;echo&lt;br /&gt;mail user3 &lt;&lt; MARK&lt;br /&gt;Your porgram for printing the invoices has been executed&lt;br /&gt;on `date`. Please check the print queue.&lt;br /&gt;MARK&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$sh here1.sh&lt;br /&gt;this is to test the here document&lt;br /&gt;&lt;br /&gt;Now mail send to user3&lt;br /&gt;&lt;br /&gt;$mail&lt;br /&gt;mail details displayed here&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;String Operations:&lt;br /&gt;------------------&lt;br /&gt;&lt;br /&gt;${#name} used to find the length of the string&lt;br /&gt;&lt;br /&gt;${variable%pattern}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$name=&quot;oracle&quot;&lt;br /&gt;$echo ${#oracle}&lt;br /&gt;6&lt;br /&gt;&lt;br /&gt;$fqdn=&quot;www.oracle.co.in&quot;  % used to cut from the end of the string , %% from the beginning&lt;br /&gt;$echo ${fqdn%in}&lt;br /&gt;www.oracle.co.&lt;br /&gt;$echo ${fqdn%co.in}&lt;br /&gt;www.oracle.&lt;br /&gt;$echo ${fqdn%.co.in}&lt;br /&gt;www.oracle&lt;br /&gt;$echo ${fqdn%.*}&lt;br /&gt;www.oracle.co&lt;br /&gt;$echo ${fqdn%%.*}&lt;br /&gt;www&lt;br /&gt;$echo ${fqdn%o*}&lt;br /&gt;www.oracle.c&lt;br /&gt;$echo ${fqdn%%o*}&lt;br /&gt;www.&lt;br /&gt;$echo ${fqdn#www}&lt;br /&gt;.oracle.co.in&lt;br /&gt;$echo ${fqdn#www.}&lt;br /&gt;oracle.co.in&lt;br /&gt;$echo ${fqdn#*.}&lt;br /&gt;oracle.co.in&lt;br /&gt;$echo ${fqdn##.}&lt;br /&gt;in&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$ip_address=&quot;192.168.0.1&quot;&lt;br /&gt;$echo ${ip_address%.*}&lt;br /&gt;192.168.0&lt;br /&gt;$echo ${ip_address##.*}&lt;br /&gt;192.168.0.1&lt;br /&gt;$echo ${ip_address#.*}&lt;br /&gt;192.168.0.1&lt;br /&gt;$echo ${ip_address%%.*}&lt;br /&gt;192&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$name=&quot;mmm&quot;&lt;br /&gt;$echo ${#name}&lt;br /&gt;3&lt;br /&gt;$expr $name : &#39;.*&#39;  using expr string operations&lt;br /&gt;3&lt;br /&gt;$expr length &quot;$name&quot;&lt;br /&gt;3&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Conditional Parameter substitution&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;:+ if value found then returns the attached string&lt;br /&gt;:- if value not found  then returns the attached string&lt;br /&gt;:= assign the value to the variable if value not found&lt;br /&gt;&lt;br /&gt;$found=`ls`&lt;br /&gt;$echo ${found:+&quot;found the values&quot;}&lt;br /&gt;found the values&lt;br /&gt;$found=&quot;&quot;&lt;br /&gt;$echo ${found:+&quot;found the values&quot;}&lt;br /&gt;&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$found=&quot;&quot;&lt;br /&gt;$echo ${found:-&quot;value not set&quot;}&lt;br /&gt;value not set&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$found=&quot;&quot;&lt;br /&gt;$echo ${found:=&quot;value&quot;}&lt;br /&gt;value&lt;br /&gt;$echo ${found}&lt;br /&gt;value&lt;br /&gt;$found=&quot;a&quot;&lt;br /&gt;$echo ${found:=&quot;value&quot;}&lt;br /&gt;a&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Merging Streams&lt;br /&gt;---------------&lt;br /&gt;1&gt;&amp;2 - send the standard output to the destination of the standard error.&gt;&amp;2&lt;br /&gt;2&gt;&amp;1 - send the standard error to the destination of the standard ouput.&gt;&amp;1&lt;br /&gt;&lt;br /&gt;ls -l abcd.tes nonexistingfile.txt 2&gt; errorfile 1&gt;&amp;2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Shell functions&lt;br /&gt;---------------&lt;br /&gt;function_name()&lt;br /&gt;{&lt;br /&gt;commands&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;function will exist for only the shell where it is defined, not visible for subshell.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$test(){&lt;br /&gt;&gt; echo &quot;function defined ...&quot;&lt;br /&gt;&gt; date&lt;br /&gt;&gt; echo Welcome&lt;br /&gt;&gt; }&lt;br /&gt;&lt;br /&gt;$test&lt;br /&gt;function defined ...&lt;br /&gt;Thu Oct 23 14:52:22 IST 2008&lt;br /&gt;Welcome&lt;br /&gt;&lt;br /&gt;$unset test&lt;br /&gt;$test&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To bring the functions which are stored in file, available for current shell, will be by running DOT command with filename&lt;br /&gt;&lt;br /&gt;. functionfile&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$name=&quot;marsd&quot;&lt;br /&gt;$expr $name : &#39;...\(..\)&#39;&lt;br /&gt;sd&lt;br /&gt;$expr $name : &#39;..\(..\).&#39;&lt;br /&gt;rs&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$vi datef&lt;br /&gt;date_fname() {&lt;br /&gt;set -- `date`&lt;br /&gt;year=`expr $6 : &#39;..\(..\)&#39;`&lt;br /&gt;echo &quot;$2$3_$year&quot;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$. datef&lt;br /&gt;$date_fname&lt;br /&gt;Oct23_08&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;eval command &lt;br /&gt;------------&lt;br /&gt;Evaluates more than once.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$echo $$&lt;br /&gt;8762&lt;br /&gt;$echo $$$&lt;br /&gt;8762$&lt;br /&gt;$echo $$$$&lt;br /&gt;87628762&lt;br /&gt;$eval echo \$$$   $8762 will be some number based what we set earlier&lt;br /&gt;762&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$y=x&lt;br /&gt;$z=y&lt;br /&gt;$echo $$z&lt;br /&gt;8762z&lt;br /&gt;$echo \$$z&lt;br /&gt;$y&lt;br /&gt;$eval echo \$$z&lt;br /&gt;x&lt;br /&gt;$&lt;br /&gt;&lt;br /&gt;$ set 1 2 3 4 5 6 7 8 9 10 11 16&lt;br /&gt;$eval echo \${$#}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The exec Statement&lt;br /&gt;------------------&lt;br /&gt;$exec date    runs date and logs out&lt;br /&gt;&lt;br /&gt;Instead of using std in,out,err,we can create new File descriptor using exec command.&lt;br /&gt;&lt;br /&gt;$exec 3&gt;invalidfile&lt;br /&gt;$echo &quot;this goes to invalid file &quot; 1&gt;&amp;3&lt;br /&gt;$cat invalidfile&lt;br /&gt;this goes to invalid file&lt;br /&gt;&lt;br /&gt;Redirect output to the file&lt;br /&gt;$exec 1&gt;| out&lt;br /&gt;$ls&lt;br /&gt;$cat out &gt; /dev/tty&lt;br /&gt;list the files&lt;br /&gt;&lt;br /&gt;$exec 1&gt; /dev/tty   to reset back to the normal&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Debuggers&lt;br /&gt;---------&lt;br /&gt;&lt;br /&gt;sh -n   used for checking errors&lt;br /&gt;&lt;br /&gt;set -n   set debug enable&lt;br /&gt;set -o noexec  remove deubg option&lt;br /&gt;&lt;br /&gt;sh -x  xtrace&lt;br /&gt;sh -u unbound variable error message at each attempt to use an undeclared variable&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;POSIX character class&lt;br /&gt;----------------------&lt;br /&gt;The ability of character classes to match characters not in the english alphabet&lt;br /&gt;&lt;br /&gt;grep -E  &quot;^[[:digit:]]+$&quot;&lt;br /&gt;grep -E  &quot;^[[:alpha:]]+$&quot;&lt;br /&gt;grep -E  &quot;^[[:cntrl:]]+$&quot;</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/2197433214290625554/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/2197433214290625554' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/2197433214290625554'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/2197433214290625554'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2008/11/third-day.html' title='Third Day'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-5782529339651995586</id><published>2008-11-12T06:26:00.001-08:00</published><updated>2008-11-12T06:26:33.014-08:00</updated><title type='text'>Second Day</title><content type='html'>find &lt;br /&gt;----&lt;br /&gt;&lt;br /&gt;find [path] [search criteria]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;find    displays all the files and displays in standard output&lt;br /&gt;find . -print displays all the files and displays in standard output&lt;br /&gt;find . -name &quot;in*&quot; -print displays the files which are starts with &quot;in&quot;&lt;br /&gt;find . -type f -name &quot;in*&quot;   display only files starting with in&lt;br /&gt;find . -type d -name &quot;in*&quot;  display only folders starting with in&lt;br /&gt;&lt;br /&gt;find /home -user &quot;user1&quot; display files from home folder created by user1&lt;br /&gt;find /home -group &quot;group&quot;&lt;br /&gt;find /home -uid 500  if user name already removed but to search that user created files&lt;br /&gt;&lt;br /&gt;find . -links 4  display files which  has 4 number of link&lt;br /&gt;find . -links +4 -ls  display files which has 4 or more links&lt;br /&gt;&lt;br /&gt;find . -perm 755   displays the files which has permission 755&lt;br /&gt;find . -perm 1755&lt;br /&gt;find . -perm 2755&lt;br /&gt;find . -perm 4755&lt;br /&gt;&lt;br /&gt;find . -atime -1 within one day accessed files&lt;br /&gt;find . -mtime -1 within one day modified files&lt;br /&gt;find . -c -1&lt;br /&gt;&lt;br /&gt;find . -mtime +365 365 day before modified files&lt;br /&gt;&lt;br /&gt;ls -lc   inode change time stamp - create time&lt;br /&gt;ls -lu   modified time&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;find . \( -name &quot;mm*&quot; -o -type l \)  files with mm as starting character or any link files&lt;br /&gt;find . !\( -name &quot;mm*&quot; -o -type l \)  files not with mm as starting character or any link files&lt;br /&gt;&lt;br /&gt;find -size 45 find files by size&lt;br /&gt;&lt;br /&gt;find . -name &quot;mm*&quot; -exec cat {} \; display found files in console&lt;br /&gt;find . -name &quot;mm*&quot; -ok cat {} \; remove found files (ok for interactively do the job)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;file&lt;br /&gt;----&lt;br /&gt;Displays the files type whether it is ASCII or other&lt;br /&gt;&lt;br /&gt;file *   to display current folder&#39;s files type&lt;br /&gt;file /bin/cp &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;shells&lt;br /&gt;------&lt;br /&gt;cat /etc/shells  displays the available shells type&lt;br /&gt;&lt;br /&gt;old shell - bourne shells&lt;br /&gt;bash - bourne again shells&lt;br /&gt;csh - C shells &lt;br /&gt;ksh- Korn shell&lt;br /&gt;tcsh - TC shell&lt;br /&gt;&lt;br /&gt;ps &lt;br /&gt;--&lt;br /&gt;displays the process list&lt;br /&gt;&lt;br /&gt;sleep 100 &amp;   &amp; symbol used to put particular process in background&lt;br /&gt;fg 1   bring the particular job foreground&lt;br /&gt;&lt;br /&gt;^Z to interrupt/suspend &lt;br /&gt;&lt;br /&gt;bg 1   to restart interrupted jobs&lt;br /&gt;&lt;br /&gt;jobs   to display currently available jobs&lt;br /&gt;&lt;br /&gt;ps -l    list the process &lt;br /&gt;&lt;br /&gt;nohup  command helps to run background jobs even after we logged out&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;nohup sort /etc/passwd &gt; out &amp; sort will be stored in out file&lt;br /&gt;&lt;br /&gt;ps -el | grep -e &quot;17280&quot; -e &quot;init&quot;   to display after reloggin to display running jobs&lt;br /&gt;&lt;br /&gt;nice -n 15 sleep 100 &amp;   sets 15 as nice value to set priority value&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Shells&lt;br /&gt;----------&lt;br /&gt;&lt;br /&gt;internal command&lt;br /&gt;external command&lt;br /&gt;executable files&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;type cd  to display what kind of command&lt;br /&gt;type echo &lt;br /&gt;&lt;br /&gt;more etc/passwd   holds the which shell alotted for user by default&lt;br /&gt;&lt;br /&gt;chsh permanently changes the shell type&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Shell Variables&lt;br /&gt;---------------&lt;br /&gt;Named parameters or user defined variables&lt;br /&gt;Positional parameters&lt;br /&gt;Special parameters&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Named Parameters&lt;br /&gt;----------------&lt;br /&gt;read name sets the value for name&lt;br /&gt;&lt;br /&gt;read name1 name2  sets value for multiple variables&lt;br /&gt;krishna moorthy&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;set  to display user defined variables&lt;br /&gt;unset name1  to unset variables&lt;br /&gt;&lt;br /&gt;name1=&quot;100&quot;  direct assign also possible &lt;br /&gt;&lt;br /&gt;echo $SHELL  to Know what kind of shell used by current user&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Executable order of the command will be check first the given command in builtin and then check current working directory and then check in $PATH.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;echo $PS1&lt;br /&gt;[\u@\h \W]\$&lt;br /&gt;PS1=&#39;[ \W]$&#39; single quote compulsory to set the PS1 path&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;echo $IFS&lt;br /&gt;echo &quot;$IFS&quot; | od -bcd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Positional Parameters - used in shell script to get input from command line&lt;br /&gt;---------------------&lt;br /&gt;&lt;br /&gt;Maximum 9 positional arguments possible to retrive using $1.. $9 ,to access 10th value ${10}&lt;br /&gt;&lt;br /&gt;vi u&lt;br /&gt;echo enter user name&lt;br /&gt;read user&lt;br /&gt;echo welcome $user&lt;br /&gt;&lt;br /&gt;sh u&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;vi u1&lt;br /&gt;echo Welcome $1&lt;br /&gt;&lt;br /&gt;sh u1 krishna&lt;br /&gt;&lt;br /&gt;To take all the arguments except with $0 (filename of the executed command)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Special Parameters&lt;br /&gt;------------------&lt;br /&gt;$$ pid of the current process&lt;br /&gt;$! pid of the last background process&lt;br /&gt;$#  total number of arguments passed in command line&lt;br /&gt;$@ To take all the arguments except with $0 (filename of the executed command)&lt;br /&gt;$* list of all the arguments as similar to $@&lt;br /&gt;$? exit status of the previous command&lt;br /&gt;$- displays the shell options &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;sh -x u1.sh  debug the shell script xtrace mode&lt;br /&gt;sh -v u1.sh  debug the shell script verbos mode&lt;br /&gt;sh -n u1.sh  debug undefined varibales -it won&#39;t run only checking varibales&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Test Command&lt;br /&gt;------------&lt;br /&gt;to compare the values or expressions&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$read num&lt;br /&gt;10&lt;br /&gt;$echo $num&lt;br /&gt;10&lt;br /&gt;$test $num -eq 10  check using test command&lt;br /&gt;$echo $?&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$read num&lt;br /&gt;10&lt;br /&gt;$[ $num -eq 20 ] check integer check with square brackets&lt;br /&gt;$echo $?&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;$str1=&quot;hello&quot;&lt;br /&gt;$[ &quot;$str1&quot; = &quot;Hello&quot; ] ; echo $? check string comparison&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;$[ -n &quot;$str1&quot;  ] ; echo $?  check not null&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;$[ -z &quot;$str1&quot;  ] ; echo $?  check null&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;File operators in Test Command&lt;br /&gt;------------------------------&lt;br /&gt;&lt;br /&gt;$test -f file1 ; echo $?  file exist and ordinary&lt;br /&gt;$test -d file1 ; echo $?  file exist and directory&lt;br /&gt;$test -e   file exist&lt;br /&gt;$test -s file2 ;echo $?  file exist with some content &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;relational operators&lt;br /&gt;-------------------&lt;br /&gt;-gt, -lt, -eq, -ge, -le, &lt;br /&gt;&lt;br /&gt;Logical operators&lt;br /&gt;-----------------&lt;br /&gt;-a&lt;br /&gt;-o&lt;br /&gt;!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Quotes usage in Unix&lt;br /&gt;--------------------&lt;br /&gt;single quote  prints special parameters also as it is&lt;br /&gt;single back quote treats as unix single command&lt;br /&gt;double quote  prints the string and special parameters will be replaced&lt;br /&gt;&lt;br /&gt;echo &#39;Today date is date&#39;&lt;br /&gt;echo &#39;Today date is `date`&#39;&lt;br /&gt;echo Today date is `date`&lt;br /&gt;echo &quot;Today date is `date`&quot;&lt;br /&gt;echo &quot;argument values are $*&quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;expr&lt;br /&gt;----&lt;br /&gt;makes arithmatic operation&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$expr 4 + 5&lt;br /&gt;9&lt;br /&gt;&lt;br /&gt;$expr 4 * 5&lt;br /&gt;expr: syntax error&lt;br /&gt;&lt;br /&gt;$expr 4 \* 5&lt;br /&gt;20&lt;br /&gt;&lt;br /&gt;$expr 5 + 4 \* 2&lt;br /&gt;13&lt;br /&gt;&lt;br /&gt;$expr \( 5 + 4 \) \* 2&lt;br /&gt;18&lt;br /&gt;&lt;br /&gt;$sum=`expr \( 5 + 4 \) \* 2` ; echo $sum&lt;br /&gt;18&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Setting positional variables value using set command&lt;br /&gt;----------------------------------------------------&lt;br /&gt;&lt;br /&gt;$set 10 20 30 40&lt;br /&gt;$echo $1&lt;br /&gt;10&lt;br /&gt;$echo $3&lt;br /&gt;30&lt;br /&gt;$echo $#&lt;br /&gt;4&lt;br /&gt;$echo $$&lt;br /&gt;17287&lt;br /&gt;$echo $*&lt;br /&gt;10 20 30 40&lt;br /&gt;&lt;br /&gt;$shift  shift command used to reposition the values one from the left&lt;br /&gt;$echo $1&lt;br /&gt;20&lt;br /&gt;$echo $#&lt;br /&gt;3&lt;br /&gt;&lt;br /&gt;$shift 2&lt;br /&gt;$echo $1&lt;br /&gt;40&lt;br /&gt;$echo $#&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;$set 4 + 5&lt;br /&gt;$echo $1&lt;br /&gt;4&lt;br /&gt;&lt;br /&gt;$set `expr 4 + 5`&lt;br /&gt;$echo $1&lt;br /&gt;9&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#sets &amp; displays the date to the variable&lt;br /&gt;set `date`&lt;br /&gt;$echo Today is $1&lt;br /&gt;Today is Wed&lt;br /&gt;$echo year is $6&lt;br /&gt;year is 2008&lt;br /&gt;$echo $#&lt;br /&gt;6&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;IFS &lt;br /&gt;----&lt;br /&gt;Holds the delimeter value&lt;br /&gt;&lt;br /&gt;$set `tail -1 /etc/passwd` ; echo $#&lt;br /&gt;1&lt;br /&gt;oldifs=&quot;$IFS&quot;&lt;br /&gt;$IFS=&quot;:&quot;&lt;br /&gt;$set `tail -1 /etc/passwd` ; echo $#&lt;br /&gt;7&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;bc - Base Calculations&lt;br /&gt;--&lt;br /&gt;$num1=10.5&lt;br /&gt;$num2=30&lt;br /&gt;$expr $num1 + $num2&lt;br /&gt;expr: non-numeric argument&lt;br /&gt;$echo $num1 + $num2 | bc&lt;br /&gt;40.5&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Write a script to accept four numbers(interactive) and calculate average of it.&lt;br /&gt;&lt;br /&gt;echo Enter four numbers one by one&lt;br /&gt;read num1&lt;br /&gt;read num2&lt;br /&gt;read num3&lt;br /&gt;read num4&lt;br /&gt;sum=`echo $num1 + $num2 + $num3 + $num4 | bc`&lt;br /&gt;avg=`expr $sum / 4 `&lt;br /&gt;echo $avg&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;read num1 num2 num3 num4 &lt;br /&gt;echo `echo \( $num1 + $num2 + $num3 + $num4 \) / 4 | bc`&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Display the largest ordinary filename and its size in the current dir.&lt;br /&gt;&lt;br /&gt;ls -lSr | grep &quot;^-&quot; |  tail -1 | tr -s &quot; &quot; | cut -f5 -d &quot; &quot; &lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;ls -lS | grep &quot;^-&quot; | head -1 | tr -s &quot; &quot; | cut -f5 -d &quot; &quot; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Conditional Execution&lt;br /&gt;---------------------&lt;br /&gt;&amp;&amp;&lt;br /&gt;||&lt;br /&gt;&lt;br /&gt;$grep &quot;root&quot; /etc/passwd &amp;&amp; echo &quot;Pattern Found&quot;&lt;br /&gt;root:x:0:0:root:/root:/bin/bash&lt;br /&gt;operator:x:11:0:operator:/root:/sbin/nologin&lt;br /&gt;Pattern Found&lt;br /&gt;$grep &quot;roottter&quot; /etc/passwd &amp;&amp; echo &quot;Pattern Found&quot;&lt;br /&gt;&lt;br /&gt;$grep &quot;root&quot; /etc/passwd &gt; /dev/null &amp;&amp; echo &quot;Pattern Found&quot;  Redirect output to null device&lt;br /&gt;Pattern Found&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Program Constructs&lt;br /&gt;------------------&lt;br /&gt;if&lt;br /&gt;for&lt;br /&gt;while&lt;br /&gt;until&lt;br /&gt;case&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if statement&lt;br /&gt;------------&lt;br /&gt;if control command&lt;br /&gt;then&lt;br /&gt;&lt;commands&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if control command&lt;br /&gt;then&lt;br /&gt;&lt;commands&gt;&lt;br /&gt;else&lt;br /&gt;&lt;commands&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if control command&lt;br /&gt;then&lt;br /&gt;&lt;commands&gt;&lt;br /&gt;elif control command&lt;br /&gt;then &lt;br /&gt;  &lt;comands&gt;&lt;br /&gt; else&lt;br /&gt;  &lt;commands&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;echo Enter the filename&lt;br /&gt;read fname&lt;br /&gt;if[ -e $fname ]&lt;br /&gt;then&lt;br /&gt; echo $fname exists&lt;br /&gt;else&lt;br /&gt; echo $fname not exists&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Write a script to accept two filenames and compare both the files are identical remove one of the file. Remove has to be interactively.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;cho Enter two file name&lt;br /&gt;read f1 f2&lt;br /&gt;if  `cmp $f1 $f2 &gt; /dev/null`&lt;br /&gt;then&lt;br /&gt;        echo both files are identical&lt;br /&gt;        rm -i $f1&lt;br /&gt;        echo first file got deleted&lt;br /&gt;else&lt;br /&gt;        echo files are different&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;cmp, comm and diff  also be used to make compare the files.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Write a script to check whether the user is logged on or not.&lt;br /&gt;&lt;br /&gt;echo read user name&lt;br /&gt;read user&lt;br /&gt;if   `who | cut -f1 -d &quot; &quot; | grep &quot;\&lt;$user\&gt;&quot; &gt; /dev/null `&lt;br /&gt;then&lt;br /&gt;        echo user found&lt;br /&gt;else&lt;br /&gt;        echo user not  found&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for loop&lt;br /&gt;---------&lt;br /&gt;&lt;br /&gt;for i in 1 2 3 4 5 &lt;br /&gt;do&lt;br /&gt;echo $i&lt;br /&gt;sleep 2&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for i in `seq 1 5`  useing sequence generate numbers&lt;br /&gt;do&lt;br /&gt;echo $i&lt;br /&gt;sleep 2&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for i in *; do echo $i; done  to display the files from the directory&lt;br /&gt;&lt;br /&gt;for i in `ls -l | tr -s &quot; &quot; | cut -f 5 -d &quot; &quot; `; do echo $i; done | sort -rn  displays size in reverse order&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Write a program to count occurence of uniquly the words&lt;br /&gt;&lt;br /&gt;vi data1&lt;br /&gt;this is data&lt;br /&gt;hello this is  data&lt;br /&gt;data&lt;br /&gt;hello&lt;br /&gt;hello&lt;br /&gt;&lt;br /&gt;echo `cat data1 | sort | uniq | wc -w`&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Rename all the doc files to txt files&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for i in `ls *.doc`&lt;br /&gt;do&lt;br /&gt;name=`basename $i doc`  #basename helps to cuts doc&lt;br /&gt;mv $i ${name}txt&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Remove all the empty files in the current directory only&lt;br /&gt;&lt;br /&gt;for i in *&lt;br /&gt;do&lt;br /&gt;if ! test -s $i&lt;br /&gt;then&lt;br /&gt;echo deleted file $i&lt;br /&gt;rm -ir $i&lt;br /&gt;else&lt;br /&gt;echo not deleted file - $i&lt;br /&gt;fi&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;while Loop&lt;br /&gt;----------&lt;br /&gt;&lt;br /&gt;#continue the loop until user inputs some character&lt;br /&gt;echo enter the answer&lt;br /&gt;read ans&lt;br /&gt;while [ -z &quot;$ans&quot; ]&lt;br /&gt;do&lt;br /&gt; echo entered nothing&lt;br /&gt; read ans&lt;br /&gt;done&lt;br /&gt;echo some character got entered &quot;$ans&quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#display the numbers upto 10 by entered number&lt;br /&gt;echo enter the answer&lt;br /&gt;read num&lt;br /&gt;while [ $num -le 10 ]&lt;br /&gt;do&lt;br /&gt;&lt;br /&gt; echo $num&lt;br /&gt; num=`expr $num + 1`&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;df - command used to display the diskspace usage&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Write a script to accept a string and reverse the same.&lt;br /&gt;&lt;br /&gt;echo enter a string&lt;br /&gt;read str&lt;br /&gt;len=`echo str | wc -c`&lt;br /&gt;#len=`expr $len - 1`&lt;br /&gt;&lt;br /&gt;while [ $len -gt 0 ]&lt;br /&gt;do&lt;br /&gt;        n1=` echo $str | cut -c $len`&lt;br /&gt;        newstr=`echo $newstr$n1`&lt;br /&gt;        len=`expr $len - 1`&lt;br /&gt;done&lt;br /&gt;echo $newstr&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;calender&lt;br /&gt;--------&lt;br /&gt;cal -1      Display single month output.  (This is the default.)&lt;br /&gt;&lt;br /&gt;cal -3      Display prev/current/next month output.</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/5782529339651995586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/5782529339651995586' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/5782529339651995586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/5782529339651995586'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2008/11/second-day.html' title='Second Day'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9025803393047781590.post-2004899067056097978</id><published>2008-11-12T06:12:00.000-08:00</published><updated>2008-11-12T06:26:06.143-08:00</updated><title type='text'>First Day</title><content type='html'>Unix treats all the peripherals as file.&lt;br /&gt;&lt;br /&gt;- (hyphen ) is the standard input (keyboard) &lt;br /&gt;&lt;br /&gt;&gt; - standard output&lt;br /&gt;&lt;br /&gt;&lt; - input from file&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;File Types:&lt;br /&gt;-----------&lt;br /&gt;drwxrwxrwx&lt;br /&gt;&lt;br /&gt;d- directory&lt;br /&gt;l- soft links&lt;br /&gt;c- charcter file  - used in keyboard&lt;br /&gt;b- blocks - used in printer&lt;br /&gt;&lt;br /&gt;Help in Unix:&lt;br /&gt;-------------&lt;br /&gt;&lt;br /&gt;date --help&lt;br /&gt;man date&lt;br /&gt;info date&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ls :&lt;br /&gt;----&lt;br /&gt;&lt;br /&gt;ls command displays total 108 - this number is total number of memory block get utilized to store data&lt;br /&gt;&lt;br /&gt;ls -li&lt;br /&gt;ls -lr   reverse listing&lt;br /&gt;ls -R   recursive &lt;br /&gt;&lt;br /&gt;ls -l file1 file2 &gt;| outfile 2&gt;| error - creates file with out and error&lt;br /&gt;&lt;br /&gt;ls -l file1 file2 &gt;&gt; res 2&gt;&gt; error  redirects with appending&lt;br /&gt;ls -l file1 file2 1&gt;&gt; res 2&gt;&gt; error   redirects with appending&lt;br /&gt;&lt;br /&gt;ls [!abc]*   other than starts with a,b,c character file will be displayed.&lt;br /&gt;&lt;br /&gt;ls -l /dev    device folder - stores character files&lt;br /&gt;&lt;br /&gt;ls jk gh 2&gt; /dev/null - do not display erro message&lt;br /&gt;&lt;br /&gt;kernel version&lt;br /&gt;ls /boot/vm*   vmlinuz-2.6.9-55.EL here, 2.6 version, 9-55 patch, EL english&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;cat &lt;br /&gt;----&lt;br /&gt;cat &lt; file1 &gt; file2  - creates file2&lt;br /&gt;cat file1 - &gt; file3  creates file3 with content of file1 along with standard input&lt;br /&gt;cat &gt;&gt; file2 -  appending&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wild Cards:&lt;br /&gt;----------&lt;br /&gt;?- single character&lt;br /&gt;* - multiple character&lt;br /&gt;[] - range of character ex: [0-9] [abc] [!abc]&lt;br /&gt;! - not&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;alias&lt;br /&gt;-----&lt;br /&gt;alias cls=&#39;clear&#39;    sets shortcut&lt;br /&gt;unalias cls    removes alias&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;^u   clears the prompt&lt;br /&gt;^c   kills current prompt&lt;br /&gt;^s   stop displaying typing commands&lt;br /&gt;^q   to release&lt;br /&gt;^r   searches command in reverse&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;set -o    environment settings to control activities like exit using ^D&lt;br /&gt;set nu &lt;br /&gt;set nonu&lt;br /&gt;&lt;br /&gt;stty&lt;br /&gt;-----&lt;br /&gt;stty   shows terminal type&lt;br /&gt;stty -a   shows commands in detail&lt;br /&gt;stty eof \^a   eof character changed from ^d to ^a&lt;br /&gt;stty sane   revert back to default setting&lt;br /&gt;&lt;br /&gt;Hard links&lt;br /&gt;----------&lt;br /&gt;drawbacks 1. can&#39;t accessible across the file system , 2 can&#39;t create on directories&lt;br /&gt;&lt;br /&gt;ln a a.link&lt;br /&gt;&lt;br /&gt;426000 -rw-rw-r--  2 user3 user3  15 Oct 21 11:16 a&lt;br /&gt;426000 -rw-rw-r--  2 user3 user3  15 Oct 21 11:16 a.link&lt;br /&gt;&lt;br /&gt;rm a.link  removes the link&lt;br /&gt;&lt;br /&gt;ln file1 file2 folder2/  creates file1, file2 links in folder2&lt;br /&gt;&lt;br /&gt;ln folder2 /opt/mm - cross device error will be produced.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Softlinks / Symbolic Links&lt;br /&gt;---------------------------&lt;br /&gt;Make use of inode table, same number also shared with the files. &lt;br /&gt;&lt;br /&gt;ln -s folder2 folder2soft&lt;br /&gt;&lt;br /&gt;ls -il folder2 folder2soft &lt;br /&gt;&lt;br /&gt;26010 lrwxrwxrwx  1 user3 user3    7 Oct 21 12:10 folder2soft -&gt; folder2&lt;br /&gt;&lt;br /&gt;folder2:&lt;br /&gt;total 16&lt;br /&gt;426001 -rw-rw-r--  2 user3 user3 6 Oct 21 11:18 file1&lt;br /&gt;426004 -rw-rw-r--  2 user3 user3 6 Oct 21 11:18 file2&lt;br /&gt;&lt;br /&gt;Here first line says size as number of characters of actual folder. here it is 7.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;date&lt;br /&gt;----&lt;br /&gt;date +%H&lt;br /&gt;date +%T&lt;br /&gt;date +%D&lt;br /&gt;date +%d-%m-%y&lt;br /&gt;date +%H-%M-%S &lt;br /&gt;date +%d-%b-%y&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;who&lt;br /&gt;---&lt;br /&gt;whoami show my login name&lt;br /&gt;who  who are all there&lt;br /&gt;who am i show my terminal details&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Default Folders in unix&lt;br /&gt;-----------------------&lt;br /&gt;bin - normal executable files kept here&lt;br /&gt;sbin - super user executables&lt;br /&gt;dev - device files&lt;br /&gt;var - holds dynamic information - especifically logs&lt;br /&gt;etc - configuration files &lt;br /&gt;home - for user accounts&lt;br /&gt;proc - which holds all the process running on the system&lt;br /&gt;boot - kernal image directory&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To display system information&lt;br /&gt;-----------------------------&lt;br /&gt;uname -m i686&lt;br /&gt;uname -s Linux&lt;br /&gt;uname -o GNU/Linux&lt;br /&gt;uname -r 2.6.9-55.EL&lt;br /&gt;&lt;br /&gt;tty  to show terminal details&lt;br /&gt;&lt;br /&gt;who &gt; /dev/pts/1  write in terminal 1 console&lt;br /&gt;who &gt; /dev/tty list tty with login details&lt;br /&gt;&lt;br /&gt;Editors&lt;br /&gt;-------&lt;br /&gt;Line editors - ed, ex, sed&lt;br /&gt;Screen editors - vi, vim, emacs&lt;br /&gt;&lt;br /&gt;vi works with three mode - command, insert, colon / last line mode / esc mode / ex mode&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To set custom commands for Vi permanently, create a file in home directory&lt;br /&gt;.exrc file&lt;br /&gt;  set nu&lt;br /&gt;  abbr os Operating Systems&lt;br /&gt;  map ^W  :w^M&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Pipes and Filters&lt;br /&gt;-----------------&lt;br /&gt;&lt;br /&gt;Types of Commands available in unix - 1. Filters, 2. no std in , but stdout. 3. no stdin and no std out&lt;br /&gt;&lt;br /&gt;wc -c -l -w&lt;br /&gt;&lt;br /&gt;who | wc -l&lt;br /&gt;&lt;br /&gt;head -3 /etc/passwd&lt;br /&gt;tail -5 /etc/passwd&lt;br /&gt;&lt;br /&gt;tail +3 /etc/passwd | head -1&lt;br /&gt;&lt;br /&gt;cut -c 1  displays first character of each line&lt;br /&gt;&lt;br /&gt;cut -c 2-5  displays 2 to 5 character in each line&lt;br /&gt;&lt;br /&gt;cut -f 2  displays the second field of the input&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;cut -f3 -d &quot;:&quot; /etc/passwd&lt;br /&gt;&lt;br /&gt;cut -f1,3 -d &quot;:&quot; /etc/passwd&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;cut -f1 -d &quot;:&quot; /etc/passwd &gt;file1&lt;br /&gt;cut -f7 -d &quot;:&quot; /etc/passwd &gt;file2&lt;br /&gt;paste file1 file2&lt;br /&gt;paste -d &quot;+&quot; file1 file2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Translate sequencing of characters&lt;br /&gt;----------------------------------&lt;br /&gt;tr a A&lt;br /&gt;tr &quot;a-z&quot; &quot;A-Z&quot;  translates lowercase to uppercase&lt;br /&gt;tr abc 123  converts a to 1, similarly for bc characters 2 and 3 will be printed&lt;br /&gt;tr &quot;a-z&quot; &quot;0-9&quot; converts a to 1 and similarly remaining characters &lt;br /&gt;tr -d &quot;a-z&quot;  removes lowercase characters&lt;br /&gt;tr -d &quot;a-zA-Z&quot; removes all the alphabets&lt;br /&gt;&lt;br /&gt;tr -s &quot;a&quot;  quising multiple sequence occurence of a character into one character&lt;br /&gt;tr -s &quot;a-z&quot;&lt;br /&gt;&lt;br /&gt;ls -l | tr -s &quot; &quot; | cut -f5,9 -d &quot; &quot; | tr -s &quot; &quot; &quot;\t\t&quot; | tr a-z A-Z  cut 5,9 th coulumn and display with tab space.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;tee &lt;br /&gt;---- &lt;br /&gt;&lt;br /&gt;Command used to redirect to file and also for next pipe.&lt;br /&gt;ls -l | tr -s &quot; &quot; | cut -f5,9 -d &quot; &quot; | tee filename | tr -s &quot; &quot; &quot;\t\t&quot; | tr a-z A-Z&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;sort&lt;br /&gt;----&lt;br /&gt;&lt;br /&gt;sort -r&lt;br /&gt;sort  -n&lt;br /&gt;ls -l | sort -k 5 -n&lt;br /&gt;ls -l | sort -k 5 -n -o outfile   sort data stored back in outfilename&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;unique&lt;br /&gt;------&lt;br /&gt;sort -n | uniq  quises adjacent duplicate value&lt;br /&gt;&lt;br /&gt;ls -l | tr -s &quot; &quot;  | cut -f5 -d &quot; &quot; | sort -n | uniq &lt;br /&gt;&lt;br /&gt;uniq -d  shows duplicate item&lt;br /&gt;uniq -c  shows number of time it got repeated&lt;br /&gt;uniq -u shows only unique items&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;who | tr -s &quot; &quot; | cut -f1 -d &quot; &quot; | sort | uniq | wc -l&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;grep&lt;br /&gt;----&lt;br /&gt;grep [options] &quot;pattern&quot; [filenames]&lt;br /&gt;&lt;br /&gt;grep -c  count the number of lines&lt;br /&gt;&lt;br /&gt;grep -e &quot;root&quot; -e &quot;halt&quot; /etc/passwd  Specify multiple patterns&lt;br /&gt;&lt;br /&gt;cat pat&lt;br /&gt;root&lt;br /&gt;halt&lt;br /&gt;&lt;br /&gt;grep -f pat /etc/passwd  does same grep command&lt;br /&gt;&lt;br /&gt;grep -f pat -e &quot;shutdown&quot; /etc/passwd  takes pattern from pat and commandline&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Regular Expressions: metacharacters&lt;br /&gt;--------------------&lt;br /&gt;1. Basic regular expressions(BRE)&lt;br /&gt;2. Extented regular expressions(ERE)&lt;br /&gt;&lt;br /&gt;BRE:&lt;br /&gt;&lt;br /&gt;grep &quot;^root&quot; /etc/passwd   ^ - beginning of the line with root&lt;br /&gt;grep &quot;^[aeiou]&quot; /etc/passwd   ^ - beginning of the line with a,e,i,o,u&lt;br /&gt;grep &quot;bash$&quot; /etc/passwd   $ - end of the line with bash&lt;br /&gt;grep &quot;[0-9]$&quot;    line starts with number&lt;br /&gt;grep &quot;^[0-9][0-9]$&quot;  anything with only two digit numbers&lt;br /&gt;grep &quot;^$&quot;  shows any line is empty&lt;br /&gt;grep &quot;^[^a-z]&quot; other than lower case letter lines will be displayed&lt;br /&gt;grep &quot;^[a^z]&quot;  line starts with any of a , ^ , or z will be displayed&lt;br /&gt;grep &quot;a.t&quot;  line contains character sequence beginning with a and ends with t, in between any character can present&lt;br /&gt;grep &quot;a\.t&quot;  line contains a.t &lt;br /&gt;grep &quot;a[.]t&quot; line contains a.t&lt;br /&gt;grep &quot;[-+/*]&quot;  display only arithmatic character containing lines&lt;br /&gt;&lt;br /&gt;. (operator) one occurence of any character&lt;br /&gt;? (operator) zero or one occurence of previous expression&lt;br /&gt;* (operator) zero or more occurences of previous regular expression&lt;br /&gt;&lt;br /&gt;grep &quot;^aaa*&quot;  line starts with minimum of two a characters&lt;br /&gt;grep &quot;^aaa*$&quot; line which has exactly minimum of two aa or more a characters&lt;br /&gt;grep &quot;^aaa.*$&quot; line with minimum of three a characters and any characters with any number of occurences&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ERE:&lt;br /&gt;Bar operators |&lt;br /&gt;&lt;br /&gt;egrep  or grep -E&lt;br /&gt;&lt;br /&gt;grep -E &quot;linux|freebsd|unix&quot; - multiple pattern with egrep&lt;br /&gt;&lt;br /&gt;egrep &quot;bell lab(s|aratories)&quot; - it matches bell labs and bell labaratories&lt;br /&gt;&lt;br /&gt;+ (operator) one or more occurences&lt;br /&gt;&lt;br /&gt;egrep &quot;^aaa+$&quot; line starts with aaa and with one or more characters&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;grep &quot;\&lt;root\&gt;&quot;  gets the exact word&lt;br /&gt;grep &quot;away\&gt;&quot;  gets the word ending with away&lt;br /&gt;grep &quot;^[0-9]\{4\}$&quot;  madates the numbers with 4 digit&lt;br /&gt;grep &quot;^[a-z]\{4,\}$&quot; madates atleast four characters&lt;br /&gt;grep &quot;^.\{4,\}$&quot;  any of four or more characters&lt;br /&gt;grep &quot;^[a-z]\{4,10\}$&quot; any of the word with minimum of four and maximum of 10 characters&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;grep -E &quot;(^| )[:/(]?book[s]?[./)/:/?]?&quot; book</content><link rel='replies' type='application/atom+xml' href='http://unixtraining.blogspot.com/feeds/2004899067056097978/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9025803393047781590/2004899067056097978' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/2004899067056097978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9025803393047781590/posts/default/2004899067056097978'/><link rel='alternate' type='text/html' href='http://unixtraining.blogspot.com/2008/11/unix-treats-all-peripherals-as-file.html' title='First Day'/><author><name>Krishna</name><uri>http://www.blogger.com/profile/06528998850000314814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>