<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Vidul Nikolaev Petrov: Tag UNIX</title>
    <link>http://www.vidul.com/articles/tag/unix</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Who am I?</title>
      <description>&lt;div style="overflow:auto; width:540px;"&gt;
&lt;img src="http://www.vidul.com/files/work.png"&gt;
&lt;/div&gt;</description>
      <pubDate>Mon, 10 Mar 2008 17:05:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:1bc104a9-4003-4866-8db9-b9e2aaab32db</guid>
      <author>root</author>
      <link>http://www.vidul.com/articles/2008/03/10/who-am-i</link>
      <category>UNIX</category>
      <category>commands</category>
      <enclosure type="image/png" url="http://www.vidul.com/files/work.png" length="141852"/>
    </item>
    <item>
      <title>Perl script opening (vim variant)</title>
      <description>&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;#!/bin/bash

file=$1

if [ -e $file ]
then
        vim $file
else
        touch $file
        echo '#!/usr/bin/perl' &amp;gt; $file
        echo '' &amp;gt;&amp;gt; $file
        echo 'use strict;' &amp;gt;&amp;gt; $file
        echo 'use warnings;' &amp;gt;&amp;gt; $file
        echo 'use diagnostics;' &amp;gt;&amp;gt; $file
        echo '' &amp;gt;&amp;gt; $file
        chmod +x $file
        vim $file
fi&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Mon, 04 Feb 2008 14:57:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:288028e0-f9e9-4bf1-837c-639d92733d9b</guid>
      <author>root</author>
      <link>http://www.vidul.com/articles/2008/02/04/perl-script-opening-vim-variant</link>
      <category>Perl</category>
      <category>scripts</category>
      <category>UNIX</category>
    </item>
    <item>
      <title>find command (practical books' dir copy)</title>
      <description>&lt;p&gt;&lt;br /&gt;
Copy all those formats (pdf|chm|txt|html) from $HOME/Desktop to the current working directory:
&lt;br /&gt;&lt;br /&gt;
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;find  ~/Desktop/ -iname &amp;quot;*.pdf&amp;quot; \
  -o -iname &amp;quot;*.chm&amp;quot; \
  -o -iname &amp;quot;*.txt&amp;quot; \
  -o -iname &amp;quot;*.html&amp;quot; \
-exec cp -v {} . \;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;a href="http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm"&gt;more about find command&lt;/a&gt;
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;</description>
      <pubDate>Sun, 03 Feb 2008 04:26:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:3e416d69-c860-40db-b71f-f4e28a0a3e3d</guid>
      <author>root</author>
      <link>http://www.vidul.com/articles/2008/02/03/find-command-practical-books-dir-copy</link>
      <category>scripts</category>
      <category>UNIX</category>
    </item>
    <item>
      <title>Everyday UNIX Commands</title>
      <description>&lt;p&gt;&lt;BR&gt;
&lt;B&gt;find&lt;/B&gt;&lt;BR&gt;
Recursively find and print all files, having 'txt' extention:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;find&lt;/STRONG&gt; ./ -type f -name "*.txt"&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;
The same but case insensititve:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;find&lt;/STRONG&gt; ./ -type f -iname "*.txt"&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;
&lt;code&gt;cat&lt;/code&gt; all found 'txt' files:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;find&lt;/STRONG&gt; ./ -type f -name "*.txt" -exec cat '{}' \;&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;
&lt;code&gt;rm&lt;/code&gt; all found 'txt' files, starting with capital letter:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;find&lt;/STRONG&gt; ./ -type f -name "[A-Z]*.txt" -exec rm '{}' \;&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;
&lt;code&gt;rm&lt;/code&gt; all except 'txt' files:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;find&lt;/STRONG&gt; ./ -type f ! -name "*.txt" -exec rm '{}' \;&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;&lt;BR&gt;
&lt;B&gt;grep&lt;/B&gt;&lt;BR&gt;
Find and print all lines in all files, containing  'tester':&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;grep&lt;/STRONG&gt; tester *&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;
Find and print all lines in all files, which do not contain  'tester':&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;grep -v&lt;/STRONG&gt; tester *&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;
The same but recursively:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;grep -r -v&lt;/STRONG&gt; tester *&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;
The same but case insensitive:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;grep -i -v&lt;/STRONG&gt; tester *&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;
&lt;B&gt;processes&lt;/B&gt;&lt;BR&gt;
simple Perl daemon:&lt;BR&gt;
&lt;FONT color="brown"&gt;perl -e 'use POSIX qw(setsid); fork; setsid; sleep 1, print $c++,$/ while 1'&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;
checking the process existance: &lt;FONT color="brown"&gt;&lt;STRONG&gt;ps x&lt;/STRONG&gt; perl&lt;/FONT&gt;&lt;BR&gt;
another way to find the process id: &lt;FONT color="brown"&gt;&lt;STRONG&gt;pgrep&lt;/STRONG&gt; perl&lt;/FONT&gt;&lt;BR&gt;
kill all processes, related to perl interpreter: &lt;FONT color="brown"&gt;&lt;STRONG&gt;pkill&lt;/STRONG&gt; perl&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;&lt;BR&gt;
&lt;B&gt;archive&lt;/B&gt;&lt;BR&gt;
Archive directory and all files and sub-directories:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;tar cvf&lt;/STRONG&gt; home.tar /home&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;
The same but gzip compresses:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;tar zcvf&lt;/STRONG&gt; home.tar.gz /home&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;
The same but bzip2 compressed:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;tar jcvf &lt;/STRONG&gt;home.tar.bz2 /home&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;
"untar" gzip compressed archive:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;tar zxvf&lt;/STRONG&gt; home.tar.gz&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;
"untar" bzip2 compressed archive:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;tar jxvf&lt;/STRONG&gt; home.tar.gz&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;
&lt;B&gt;column extraction&lt;/B&gt;&lt;BR&gt;
Let's assume that we need all user names from "/etc/passwd", which is the 1st column (the columns delimiter is &lt;B&gt;:&lt;/B&gt; ):&lt;BR&gt;&lt;BR&gt;
&lt;B&gt;cut&lt;/B&gt; command&lt;BR&gt;
&lt;FONT color="brown"&gt;cat /etc/passwd | &lt;STRONG&gt;cut -f1 -d:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;
&lt;B&gt;awk&lt;/B&gt; script&lt;BR&gt;
&lt;FONT color="brown"&gt;cat /etc/passwd | &lt;STRONG&gt;awk -F':' '{print $1}'&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;
&lt;B&gt;Perl&lt;/B&gt; source code&lt;BR&gt;
&lt;FONT color="brown"&gt;perl -ne '&lt;STRONG&gt;/(\w+)/ &amp;amp;&amp;amp; print $1,$/&lt;/STRONG&gt;' /etc/passwd&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;
&lt;B&gt;Ruby&lt;/B&gt; source code&lt;BR&gt;
&lt;FONT color="brown"&gt;ruby -ne '&lt;STRONG&gt;puts $1 if /(\w+)/&lt;/STRONG&gt;' /etc/passwd&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;
&lt;B&gt;ISO image manipulation&lt;/B&gt;&lt;BR&gt;
ISO image creation:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;dd&lt;/STRONG&gt; if=/dev/cdrom of=/tmp/cdr.iso&lt;/FONT&gt;&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;mkisofs -rJTV&lt;/STRONG&gt; "books label" /home/books &gt; /tmp/books.iso&lt;/FONT&gt;&lt;BR&gt;
&lt;BR&gt;
ISO image reading:&lt;BR&gt;
&lt;FONT color="brown"&gt;&lt;STRONG&gt;mount -o loop -t iso9660&lt;/STRONG&gt; /tmp/books.iso /mnt/isoimage&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;
&lt;BR&gt;
&lt;BR&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 23 Aug 2007 09:23:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:7a785cc5-ff26-4885-a460-cf13fe3c9942</guid>
      <author>root</author>
      <link>http://www.vidul.com/articles/2007/08/23/everyday-unix-commands</link>
      <category>scripts</category>
      <category>administration</category>
      <category>UNIX</category>
    </item>
  </channel>
</rss>
