Tuesday, June 4, 2013

exclude files in rm

rm `ls | grep -v 'txt$'`

-or-

rm `find . -type f | grep -v 'txt$'`


For file types

rm -rf `ls | grep -v '.gz$'`

Monday, February 4, 2013

The gzip Recovery Toolkit

So you thought you had your files backed up - until it came time to restore. Then you found out that you had bad sectors and you've lost almost everything because gzip craps out 10% of the way through your archive. The gzip Recovery Toolkit has a program - gzrecover - that attempts to skip over bad data in a gzip archive. This saved me from exactly the above situation. Hopefully it will help you as well.

 99% of "corrupted" gzip archives are caused by transferring the file via FTP in ASCII mode instead of binary mode. Please re-transfer the file in the correct mode first before attempting to recover from a file you believe is corrupted.

 This program is provided AS IS with absolutely NO WARRANTY. It is not guaranteed to recover anything from your file, nor is what it does recover guaranteed to be good data. The bigger your file, the more likely that something will be extracted from it. Also keep in mind that this program gets faked out and is likely to "recover" some bad data. Everything should be manually verified.


Downloading and Installing

You need the following packages:
  • gzrt-0.7.tar.gz (2013-02-02) - gzrt sources
  • github repository
  • zlib - You might already have this.
  • GNU cpio (version 2.6 or higher) - Only if your archive is a compressed tar file and you don't already have this (try "cpio --version" to find out)
First, build and install zlib if necessary. Next, unpack the gzrt sources. Then cd to the gzrt directory and build the gzrecover program by typing make. Install manually by copying to the directory of your choice.

Usage

Run gzrecover on a corrupted .gz file. Anything that can be read from the file will be written to a file with the same name, but with a .recovered appended (any .gz is stripped). You can override this with the -o option. To get a verbose readout of exactly where gzrecover is finding bad bytes, use the -v option to enable verbose mode. This will probably overflow your screen with text so best to redirect output to a file. Once gzrecover has finished, you will need to manually verify any data recovered as it is quite likely that our output file is corrupt and has some garbage data in it. Note that gzrecover will take longer than regular gunzip. The more corrupt your data the longer it takes. If your archive is a tarball, read on.
For tarballs, the tar program will choke because GNU tar cannot handle errors in the file format. Fortunately, GNU cpio (tested at version 2.6 or higher) handles corrupted files out of the box.
Here's an example:
$ ls *.gz
my-corrupted-backup.tar.gz
$ gzrecover my-corrupted-backup.tar.gz
$ ls *.recovered
my-corrupted-backup.tar.recovered
$ cpio -F my-corrupted-backup.tar.recovered -i -v
Note that newer versions of cpio can spew voluminous error messages to your terminal. Also, cpio might take quite a long while to run.
If you have a previous release, please note that the patches to GNU tar have been discontinued. They were only marginally successful at best and GNU cpio does what is needed out of the box and does it far better.

Thursday, December 20, 2012

How to open/extract ISO file in Linux?

mount -o loop -t iso9660 filename.iso /mnt/iso

(remember to create the directory /mnt/iso first)

Then browse to /mnt/iso and install

Wednesday, October 31, 2012

HowTo: Speedup ping and traceroute Command Responses under Linux / Unix

The ping command line utility act as a computer network tool. It used to test whether a particular host is reachable across an IP network. The traceroute command also act as a computer network diagnostic tool for displaying the route (path) and measuring transit

Speedup ping command

The syntax is:

 ping -n -W VALUE -i VALUE host

Where,
  1. -n : Disable DNS lookup to speed up queries.
  2. -W NUMBER : Time to wait for a response, in seconds. The option affects only timeout in absence of any responses, otherwise ping waits for two RTTs.
  3. -i SECONDS : Wait interval seconds between sending each packet. The default is to wait for one second between each packet normally, or not to wait in flood mode. Only super-user may set interval to values less 0.2 seconds.
The default command will produce output as follows:
 ping -c 5 google.com

[sibin@localhost]$ ping -c 5 google.com
PING google.com (74.125.235.8) 56(84) bytes of data.
64 bytes from sin01s04-in-f8.1e100.net (74.125.235.8): icmp_req=1 ttl=54 time=234 ms
64 bytes from sin01s04-in-f8.1e100.net (74.125.235.8): icmp_req=2 ttl=54 time=45.7 ms
64 bytes from sin01s04-in-f8.1e100.net (74.125.235.8): icmp_req=3 ttl=54 time=88.1 ms
64 bytes from sin01s04-in-f8.1e100.net (74.125.235.8): icmp_req=4 ttl=54 time=45.7 ms
64 bytes from sin01s04-in-f8.1e100.net (74.125.235.8): icmp_req=5 ttl=54 time=46.2 ms

--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4002ms
rtt min/avg/max/mdev = 45.758/92.011/234.135/72.918 ms


 Now optimize the ping command:

$ ping -c 5 -n -i 0.2 -W1 google.com

[sibin@ast-wks-069 ~]$  ping -c 5 -n -i 0.2 -W1 google.com
PING google.com (74.125.235.9) 56(84) bytes of data.
64 bytes from 74.125.235.9: icmp_req=1 ttl=54 time=46.4 ms
64 bytes from 74.125.235.9: icmp_req=2 ttl=54 time=46.4 ms
64 bytes from 74.125.235.9: icmp_req=3 ttl=54 time=45.7 ms
64 bytes from 74.125.235.9: icmp_req=4 ttl=54 time=45.5 ms
64 bytes from 74.125.235.9: icmp_req=5 ttl=54 time=49.5 ms

--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 803ms
rtt min/avg/max/mdev = 45.569/46.762/49.541/1.433 ms






Speedup traceroute command

The syntax is:
 
traceroute -n -w SECONDS -q NUMBER host



Where,
  1. -n : Disable DNS lookup to speed up queries.
  2. -w seconds : Set the time (in seconds) to wait for a response to a probe (default 5.0 sec).
  3. -q NUMBER : Sets the number of probe packets per hop. The default is 3.
The following example will wailt 3 seconds (instead of 5), only send out 1 query to each hop (ineader of 3):
$ traceroute -n -w 3 -q 1 www.google.com

 The -N option specifies the number of probe packets sent out simultaneously. Sending several probes concurrently can speed up traceroute considerably. The default value is 16:
$ traceroute -n -w 3 -q 1 -N 32 www.google.com
Please Note that some routers and hosts can use ICMP rate throttling. In such a situation specifying too large number can lead to loss of some responses. You can also limit the maximum number of hops to 16 before giving up (instead of default 30) using the -m option:
$ traceroute -n -w 3 -q 1 -N 32 -m 16 www.google.com

Friday, October 12, 2012

Centos Extra Repos for yum packages


Epel.repo

[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

webtatic.repo

[webtatic]
name=Webtatic Repository $releasever - $basearch
#baseurl=http://repo.webtatic.com/yum/centos/5/$basearch/
mirrorlist=http://repo.webtatic.com/yum/centos/5/$basearch/mirrorlist
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy

[webtatic-debuginfo]
name=Webtatic Repository $releasever - $basearch - Debug
#baseurl=http://repo.webtatic.com/yum/centos/5/$basearch/debug/
mirrorlist=http://repo.webtatic.com/yum/centos/5/$basearch/debug/mirrorlist
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy

[webtatic-source]
name=Webtatic Repository $releasever - $basearch
#baseurl=http://repo.webtatic.com/yum/centos/5/SRPMS/
mirrorlist=http://repo.webtatic.com/yum/centos/5/SRPMS/mirrorlist
enabled=0
gpgcheck=1

rpmforge.repo

# Name: RPMforge RPM Repository for Red Hat Enterprise 5 - dag
# URL: http://rpmforge.net/
[rpmforge]
name = Red Hat Enterprise $releasever - RPMforge.net - dag
#baseurl = http://apt.sw.be/redhat/el5/en/$basearch/dag
mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1


Wednesday, September 12, 2012

Batch resize your images using mogrify in Linux

Batch resize your images using mogrify

Let's say you have lots of images and want to upload them to Facebook or to your website but you have to resize or edit all the images to suitable size for faster web access without losing too much of the quality of them. One tool to help you in this situation is mogrify.

mogrify is in imagemagick package. So you just need to install the package to get it. How to use it? Let's see some examples below:

1. mogrify -resize 320x240 *.jpg
This command will resize all files ending with .jpg (jpeg image) to resolution of 320x240 and replace all the files with the same name. mogrify may not produce the exact resolution to preserve aspect ratio.

2.mogrify -path Image-Small/ -resize 800x600 -density 25x25 *.gif
This command will resize all images ending with .gif to 800x600 with density 25x25. The resized images will be saved in Image-Small directory. So the original files is unmodified.

3. mogrify -resize 50% rose.jpg
This will resize the image to 50% and the original file replaced.

4. mogrify -format jpg *.png
This will convert all png files in currect directory to jpeg.

mogrify has many options for you to explore. Just man mogrify to read the manual or go to http://www.imagemagick.org/www/mogrify.html.

Monday, September 10, 2012

Mounting a Logical Volume in linux

  1. Install lvm2:
    $ sudo yum install lvm2
    
  2. Load the necessary module(s):
    $ sudo modprobe dm-mod
    
  3. Scan your system for LVM volumes and identify in the output the volume group name that has your Fedora volume (mine proved to be VolGroup00):
    $ sudo vgscan
    
  4. Activate the volume:
    $ sudo vgchange -ay VolGroup00
    
  5. Find the logical volume that has your Fedora root filesystem (mine proved to be LogVol00):
    $ sudo lvs
    
  6. Create a mount point for that volume:
    $ sudo mkdir /mnt/fcroot
    
  7. Mount it:
    $ sudo mount /dev/VolGroup00/LogVol00 /mnt/fcroot -o ro,user
    
  8. Copied my files.