Who am I?

Posted by root Mon, 10 Mar 2008 23:05:00 GMT

Tags ,  | no comments

Perl script opening (vim variant)

Posted by root Mon, 04 Feb 2008 21:57:00 GMT

#!/bin/bash

file=$1

if [ -e $file ]
then
        vim $file
else
        touch $file
        echo '#!/usr/bin/perl' > $file
        echo '' >> $file
        echo 'use strict;' >> $file
        echo 'use warnings;' >> $file
        echo 'use diagnostics;' >> $file
        echo '' >> $file
        chmod +x $file
        vim $file
fi

Posted in ,  | Tags  | no comments

find command (practical books' dir copy)

Posted by root Sun, 03 Feb 2008 11:26:00 GMT


Copy all those formats (pdf|chm|txt|html) from $HOME/Desktop to the current working directory:

find  ~/Desktop/ -iname "*.pdf" \
  -o -iname "*.chm" \
  -o -iname "*.txt" \
  -o -iname "*.html" \
-exec cp -v {} . \;



more about find command

Posted in  | Tags  | no comments

Everyday UNIX Commands

Posted by root Thu, 23 Aug 2007 15:23:00 GMT


find
Recursively find and print all files, having 'txt' extention:
find ./ -type f -name "*.txt"

The same but case insensititve:
find ./ -type f -iname "*.txt"

cat all found 'txt' files:
find ./ -type f -name "*.txt" -exec cat '{}' \;

rm all found 'txt' files, starting with capital letter:
find ./ -type f -name "[A-Z]*.txt" -exec rm '{}' \;

rm all except 'txt' files:
find ./ -type f ! -name "*.txt" -exec rm '{}' \;


grep
Find and print all lines in all files, containing 'tester':
grep tester *

Find and print all lines in all files, which do not contain 'tester':
grep -v tester *

The same but recursively:
grep -r -v tester *

The same but case insensitive:
grep -i -v tester *


processes
simple Perl daemon:
perl -e 'use POSIX qw(setsid); fork; setsid; sleep 1, print $c++,$/ while 1'

checking the process existance: ps x perl
another way to find the process id: pgrep perl
kill all processes, related to perl interpreter: pkill perl


archive
Archive directory and all files and sub-directories:
tar cvf home.tar /home

The same but gzip compresses:
tar zcvf home.tar.gz /home

The same but bzip2 compressed:
tar jcvf home.tar.bz2 /home

"untar" gzip compressed archive:
tar zxvf home.tar.gz

"untar" bzip2 compressed archive:
tar jxvf home.tar.gz


column extraction
Let's assume that we need all user names from "/etc/passwd", which is the 1st column (the columns delimiter is : ):

cut command
cat /etc/passwd | cut -f1 -d:

awk script
cat /etc/passwd | awk -F':' '{print $1}'

Perl source code
perl -ne '/(\w+)/ && print $1,$/' /etc/passwd

Ruby source code
ruby -ne 'puts $1 if /(\w+)/' /etc/passwd


ISO image manipulation
ISO image creation:
dd if=/dev/cdrom of=/tmp/cdr.iso
mkisofs -rJTV "books label" /home/books > /tmp/books.iso

ISO image reading:
mount -o loop -t iso9660 /tmp/books.iso /mnt/isoimage



Posted in  | Tags ,  | no comments