星期一, 7月 23, 2007

Linux 系統備分還原

1.備份
find . -not -name rootfs.cgz| bin/cpio -v -o -H newc|gzip -9 >/rootfs.cgz

2.使用livecd開機掛載硬碟後還原
gzip -dc rootfs.cgz | cpio -iumdv

3.刪除 /proc /var/run 下的檔案及子目錄

4.grub-install --root-directory=/mnt/newhd /dev/sda

5.如還原之新機器scsi控製器不同需重建initrd
mkinitrd --with=scsidriver initrd-LinuxVersion.img LinuxVersion

星期一, 2月 26, 2007

目錄下所有txt檔的內容取代

#!/bin/bash
dirdo ()
{
cd $1
pwd
for fl in *; do
if [ -d $fl ]; then
dirdo $fl
cd ..
elif [[ $fl == *.txt ]] || [[ $fl == *.text ]]; then
mv $fl $fl.old
sed 's/find/replace/g' $fl.old > $fl
else
continue
fi
done
}
dirdo $1

星期三, 1月 10, 2007

C_950.nls 修改方式

各種big5對unicode碼表
http://www.moztw.org/docs/big5/

從c_950.nls讀出對應表
od -v -w2 -A n -t x2 -j 1056 -N 64511 c_951.nls | awk 'BEGIN {a=0x8100} {printf "0x%X\t", a++; print "U+" toupper($1)}' | grep -v 'U+003F' > cp951.txt
http://me.abelcheung.org/diary/general/computer/software/


nls檔案結構
http://shlimazl.nm.ru/eng/nls.htm(碼位不準)

手動修改方式例
964F(big5e) 5803(utf8)
以16位元方式計算
(964F-7EF0)*2=2EBE -> 在檔案2EBE的位址輸入 0358 (utf8碼)
(5803+8011)*2=1B028 -> 在檔案1B028的位址輸入 4F96 (big5e碼)

公式-用16進位計算
utf8碼位址=(big5碼-7EF0)*2
big5碼位址=(utf8碼+8011)*2


/*-----整個檔案轉換-----*/
#!/usr/bin/perl
$file_b5u8 = 'big5e.txt'; # big5e to utf8 table file
$file_nls = 'c_950-.nls'; # c_950.nls file

open(FHb5u8, $file_b5u8) || die "can't update somewhere: $!";
open(FHnls, "+<$file_nls") || die "can't update somewhere: $!"; while (<FHb5u8>) {
my @array = split(' ',$_);
next if (substr($array[1],0,2) ne 'U+');
my $b5s = $array[0];
my $u8s = '0x'.substr($array[1],2);
my $b5s1 = '0x'.substr($b5s,2,2);
my $b5s2 = '0x'.substr($b5s,4,2);
my $u8s1 = '0x'.substr($u8s,2,2);
my $u8s2 = '0x'.substr($u8s,4,2);
my $b5as = (hex($b5s) - hex('0x7EF0'))*2;
my $u8as = (hex($u8s) + hex('0x8011'))*2;
print "$b5s,$u8s:$b5as->$u8s2$u8s1,$u8as->$b5s2$b5s1\n";
seek(FHnls, $b5as, 0);
printf FHnls "%c%c", hex $u8s2, hex $u8s1;
seek(FHnls, $u8as, 0);
printf FHnls "%c%c", hex $b5s2, hex $b5s1;
}

close FHb5u8;
close FHnls;