顯示具有 Linux Command 標籤的文章。 顯示所有文章
顯示具有 Linux Command 標籤的文章。 顯示所有文章

2011年10月3日 星期一

compression tools

bzip2 bunzip2 gzip gunzip zip unzip lzma unlzma or lzma -d 7za za e # 7za -h 7-Zip (A) 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03 p7zip Version 4.65 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs) Usage: 7za [...] [...] [<@listfiles...>] a: Add files to archive b: Benchmark d: Delete files from archive e: Extract files from archive (without using directory names) ==> I ever used this command to extract file l: List contents of archive t: Test integrity of archive u: Update files to archive x: eXtract files with full paths

2011年4月4日 星期一

Linux Command - vi, ctags, taglist

produce the ctags
# ctags -R ./*

Enable the taglist feature
:TlistOpen


my $HOME/.vimrc config file
"set Tlist_Ctags_Cmd=/root/vimfiles/plugin/taglist.vim
filetype plugin on
"let Tlist_Ctags_Cmd = "/usr/bin/ctags"
"let Tlist_WinWidth = 50
map :TlistOpen
map :TlistToggle ==> add the shortcut of taginfo to quickly jump to the taginfo window
map :!/usr/bin/ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .


taginfo howto document
http://vim-taglist.sourceforge.net/manual.html

Linux Command - vim, vimrc example

#將這個檔案放在$HOME/下即可以設定VIM的功能,
#如果你是root,就把它放在/root/.vimrc (命名為.vimrc)即可

set softtabstop=4
set shiftwidth=4
set autoindent

2011年2月21日 星期一

Linux Command - tr

1. translate upper case alphabets to lower case alphabets
# echo "ABCD" | tr [:upper:] [:lower:]
abcd

2. 如何將 dos 檔案格式轉換 unix ? (by using "tr" command)

unix或linux主機上會呈現^M的記號(於windows系統為跳行),

如何執行dos2unix的程序進行格式轉換?

# vi dosfile ==> extra characters in the tailing of each line
aaa^M
bbbb^M
ccccc^M
^Z

use "tr" command to delete the tailed characters


# tr -d "\015\032" <> unixfile



# vi unixfile ==> it is ok now
aaa
bbbb
ccccc


3.
去处^M的方法 tr -s "\015" "\n"
出去M Z的方法 tr -s "\015\032" "\n"

Linux Command - ln

Linux command - ln, create the hard-link or soft-link

standard usage includes the following syntaxs
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET (2nd form)
ln [OPTION]... TARGET... DIRECTORY (3rd form)
ln [OPTION]... -t DIRECTORY TARGET... (4th form)

General Usage includes following

a. 1st command type example: create symblic link with specify-name in the specify directory (symbolic link name is differ with target)
# pwd
/tmp
# ln -sf ./mapping-root ./bbb
# ls -la
[omit]
[info-omit] 14 Feb 21 16:40 bbb -> ./mapping-root
[omit]

b. 3rd command type example: create symblic link with the same name with the target in the specify directory (symbolic link name is the same with target)

# ln -sf /tmp/aaa $HOME
# cd $HOME
# ls -la
[info-omit]
8 Feb 21 16:53 aaa -> /tmp/aaa ==>automatically generate the same name with the target in the specify directory ($HOME directory)
[omit]

2011年1月12日 星期三

Linux Command - grep, egrep, fgrep

Use regular expression extension patten of grep to filter the text-string

--> Use "-E" to represent using the extended regular expression in the grep
# svn info ./* | grep -E "Last Changed Rev|Path"
or
--> Use twice "-e" to indicate the search pattern double times, means we search the two patterns in the source text string
# svn info ./* | grep -e "Last Changed Rev" -e "Path"
or
--> Directly use the egrep as the program to instead of the grep program
# svn info ./* | egrep "Last Changed Rev|Path"

various type from simplest to complicated one
fgrep -> grep -> egrep

2011年1月7日 星期五

Linux Command - chkconfig, service, boot service

If you want to have the NTP server start up automatically, you can use the checkconfig command as follows:

# chkconfig --level 345 ntpd on // In this example, we turn on runlevel 3,4,5 on
# chkconfig --level 0126 ntpd off // In this example, we turn off runlevel 0,1,2,6 off

# chkconfig --list | grep ntpd
ntpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off

// Set vsftpd run on the boot time
# chkconfig vsftpd on
# chkconfig --list vsftpd // list which runlevel the vsftpd was turn on, here the runlevel 2,3,4,5 was turn on automatically
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off


// Do some experiments on the rc runlevels
# pwd
/etc/rc.d/rc3.d ==> Here we will show the runlevel 3 files

# chkconfig --list xinetd ==> list the xinetd runlevel on/off status
xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off ==> run level 3 was "on"
# ls -la *xin* ==> show the file naming (it is always a linked file with different linked name). Here the name is S56xinetd. we find that the name was start with "S"
lrwxrwxrwx 1 root root 16 2009-11-30 16:11 S56xinetd -> ../init.d/xinetd

# chkconfig --list qemu
qemu 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# ls -la *qemu*
lrwxrwxrwx 1 root root 14 2008-04-16 03:13 S35qemu -> ../init.d/qemu ==> The same as above one. The linked file was started with "S".

# chkconfig --list ypbind
ypbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off
# ls -la *ypbin*
lrwxrwxrwx 1 root root 16 2008-04-16 03:31 K73ypbind -> ../init.d/ypbind ==> This time the ypbind was off. Here the linked file was started with "K".

# chkconfig --list psacct
psacct 0:off 1:off 2:off 3:off 4:off 5:off 6:off
# ls -la *psacct*
lrwxrwxrwx 1 root root 16 2008-04-16 03:13 K10psacct -> ../init.d/psacct ==> The same as above one, the config was off. The linked file was started with "K".


// Again, we set the qemu config as off (before was on), and then the linked file was started with "K" as we think.
# chkconfig qemu off
# chkconfig --list qemu
qemu 0:off 1:off 2:off 3:off 4:off 5:off 6:off
# ls -la *qemu*
lrwxrwxrwx 1 root root 14 2009-12-25 16:30 K98qemu -> ../init.d/qemu


Add a new service into chkconfig maintain list, this will add related symbolic link into /etc/rc.d/ folder
# chkconfig --add tscRC

# find ./* -name *tscRC* -print
./init.d/tscRC
./rc0.d/K92tscRC
./rc1.d/K92tscRC
./rc2.d/S08tscRC
./rc3.d/S08tscRC
./rc4.d/S08tscRC
./rc5.d/S08tscRC
./rc6.d/K92tscRC
# find ./* -name *tscRC* -exec file {} \;
./init.d/tscRC: Bourne shell script text executable
./rc0.d/K92tscRC: symbolic link to `../init.d/tscRC'
./rc1.d/K92tscRC: symbolic link to `../init.d/tscRC'
./rc2.d/S08tscRC: symbolic link to `../init.d/tscRC'
./rc3.d/S08tscRC: symbolic link to `../init.d/tscRC'
./rc4.d/S08tscRC: symbolic link to `../init.d/tscRC'
./rc5.d/S08tscRC: symbolic link to `../init.d/tscRC'
./rc6.d/K92tscRC: symbolic link to `../init.d/tscRC'


If you restart the network service, like following command
# service network restart

All the kernel profile about network settings will be reset to default. So you need to reconfigure those network setting of kernel. For example,

/sbin/sysctl -w net.ipv4.ip_forward=1

GUI service config command to set the boot service
text-mode
# ntsysv

X GUI system
# serviceconf

2010年12月1日 星期三

Linux Commands - patch, diff

>> produce the patch file
# diff -uN file.c file.c.new > file.c.patch

>> patch the file to the original file
# patch -p0 file.c < file.c.patch

2010年10月26日 星期二

Linux Commands - iproute2

Use ip command to set the ip address

show the ip address eth0
# ip addr | grep eth0
2: eth0: mtu 1500 qdisc pfifo_fast qlen 100
0
inet 20.20.20.1/24 brd 20.20.20.255 scope global eth0
inet 10.0.0.1/24 brd 10.0.0.255 scope global eth0:0

reset the ip-address
# ip addr flush dev eth0

show the ip address eth0
# ip addr | grep eth0
2: eth0: mtu 1500 qdisc pfifo_fast qlen 100
0

set the ip-address eth0
# ip addr add 10.0.0.1/24 brd + dev eth0

show the ip address eth0
# ip addr | grep eth0
2: eth0: mtu 1500 qdisc pfifo_fast qlen 100
0
inet 10.0.0.1/24 brd 10.0.0.255 scope global eth0

2010年9月22日 星期三

Linux Command - wget,curl

some tools can communicate(get/post) with the web server (and others) without needing of user interaction

wget
can simulate the get/post client actions
>> wget example
# wget -v --proxy=on --passive-ftp -nd http://www.buildroot.org/downloads/$BUILDROOT_NAME.tar.bz2

>> guessing the cookie (userid=??) assigned by the web server
curl -sb userid=123456789 http://192.168.0.1/login.jsp | grep

2010年9月6日 星期一

tftp usage

Linux Command (busybox)
# tftp -g -r filename 192.168.100.2

Examples from the internet:
Usage: tftp [OPTION]... HOST [PORT]

Transfers a file from/to a tftp server using "octet" mode.

Options:
-l FILE Local FILE.
-r FILE Remote FILE.
-g Get file.
-p Put file.


>> download a file from the tftp server
# tftp -g -r filename.txt 20.20.20.1

>> upload a file to the tftp server
# tftp -p -r filename 1.2.3.4
NOTE: don't add the path prefix on the filename, as
# tftp -p -r ./path/to/filename 1.2.3.4 ==> This case will due to TFTP access violation error

Windows embedded with tftp client
upload file
C:\>tftp -i 192.168.100.2 PUT UploadFile
download file
C:\>tftp -i 192.168.100.2 GET DownloadFile

We can also use Tftpd program, it also has the tftp client

tftp server (shareware)
TFTPD32
http://www.jounin.net/tftpd32.html

2010年7月5日 星期一

Linux Command - watch

Periodically run a command

# each 1 second run the program
while [ 1 ]; do echo "top"; /usr/local/bin/program; sleep 1; done

# each 100 microsecond run the program
while [ 1 ]; do echo "top"; /usr/local/bin/program; usleep 100; done

watch -d -n 1 'program1;program2'

2010年5月26日 星期三

Linux Command - alias

# alias ==> show all the alias settings
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias cp='cp -i'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

# unalias cp ==> release the "cp" alias setting

2010年5月18日 星期二

Linux Command - rpm

rpm download site
http://pkgs.org/search/?keyword=
http://rpm.pbone.net/

安裝
rpm -ivh MySQL-3.23.41-1.i386.rpm

升級
rpm -Uvh MySQL-3.23.41-1.i386.rpm

移除
rpm -e MySQL

rpm-qa //查詢所有安裝過的套件

rpm -qpl MySQL-3.23.41-1.i386.rpm //查某個RPM檔的內容

驗證
不小心誤刪檔案,對整個系統做確認動作,以了解哪些部分檔案遺失。
rpm -Va


查詢某一個檔案是屬於哪一個套件
#rpm -qf /usr/bin/ftp
查詢某一個rpm檔的相關資訊
#rpm –qpi MySQL-3.23.41-1.i386.rpm
查詢某一個rpm檔的內容
#rpm –qpl MySQL-3.23.41-1.i386.rpm
查詢系統已安裝的套件資訊
#rpm –qai
更新許多已安裝套件的新版本
#rpm –Fvh *.rpm

Setup a specified RPM file (remeber to use root privilege)
# rpm –Fvh XXX.rpm
# sudo rpm –Uvh python-lxml-2.2.3-1.1.el6.i686.rpm

>> Guides to list/extract the rpm files to the system specified directory
1.Use rpm2cpio or rpm -qpl to list files and full paths in the package:
$ rpm2cpio | cpio -t

2.To extract everything to the current directory:
$ rpm2cpio | cpio -ivd

2010年5月10日 星期一

Linux Command - unrar

How to use unrar

unrar command supports various options below are common options that you need to use everyday.
Task: To open rar (unpack) file in current directory type command:

$ unrar e file.rar

Please note that replace file.rar filename with your actual filename.
Task: List (l) file inside rar archive:

$ unrar l file.rar
Task: To extract (x) files with full path type command:

$ unrar x file.rar

(D) To test (t) integrity of archive, file type command:
$ unrar t file.rar

2010年2月22日 星期一

rsync

如果要備份給對方, 就下
# rsync -avz "備份的目錄" 帳號@IP:~

這樣就可以透過開給你的帳號備份過來了
rsync的好處是他會只上傳有更動的部分

2010年1月4日 星期一

Linux Command - diff

// Compare the difference between folder_a and folder_b that exclude some files contains the specified pattern
# diff -Nur --exclude=CVS --exclude="*.pl" --exclude=PL --exclude=Release --exclude=cxxtest --exclude="*.sln" --exclude="*.vcproj" --exclude="Release*" --exclude="readme*" ./folder_a ./folder_b

diff -Nurp --exclude="\.svn" /Path/to/Folder1 /Path/to/Folder2

2009年12月18日 星期五

Linux Command - hostname

// Do the hostname positive/negative resolution

// hostname will print the name of the system as returned by the gethostname(2) function.
# hostname

// "-a", Display the alias name of the host (if used).
# hostname -a
// "-f", Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a short host name and the DNS domain name. Unless you are using bind or NIS for host lookups you can change the FQDN and the DNS domain name (which is part of the FQDN) in the /etc/hosts file.
# hostname -f

http://www.faqs.org/docs/securing/chap9sec95.html

example /etc/hosts file:
IPAddress Hostname Alias
127.0.0.1 localhost deep.openna.com
208.164.186.1 deep.openna.com deep
208.164.186.2 mail.openna.com mail
208.164.186.3 web.openna.com web

The leftmost column is the IP address to be resolved. The next column is that host's name. Any subsequent columns are alias for that host. In the second line, for example, the IP address 208.164.186.1 is for the host deep.openna.com. Another name for deep.openna.com is deep.

2009年12月16日 星期三

Linux Command - cvs tar/rtag/branch

// mark a new cvs tag "abc123"
# cvs tag abc123
T turn/lib/TurnClient.hxx ==> mark as "T" label
T turn/lib/TurnHmac.cxx
T turn/lib/TurnHmac.hxx
T turn/lib/TurnMsg.cxx
T turn/lib/TurnMsg.hxx
T turn/lib/log.cxx

// Mark a cvs tag "abc456" on a existing cvs branch
# cvs tag -r sipBranch abc456
# cvs st -v Makefile
userName@1.2.3.4's password:
===================================================================
File: Makefile Status: Up-to-date

Working revision: 1.38
Repository revision: 1.38 /home/cvs/XXX/Makefile,v
Sticky Tag: (none)
Sticky Date: (none)
Sticky Options: (none)

Existing Tags:
abc456 (revision: 1.32) ==> This is produced by cvs tag
abc123 (revision: 1.38) ==> This is produced by cvs tag
sipBranch (branch: 1.32.2) ==> This is produced by cvs rtag -b
main (revision: 1.1.1.1) ==> This is produced by cvs import
vendor (branch: 1.1.1) ==> This is produced by cvs import


# cvs rtag -r branchABC -b branchABC_123 myProjectName
userName@1.2.3.4's password:
cvs rtag: warning: cannot open /home/cvs/CVSROOT/val-tags read/write: Permission denied
cvs rtag: Tagging myProjectName
cvs rtag: Tagging myProjectName/AutoTestAgent
cvs rtag: Tagging myProjectName/AutoTestAgent/AutoTestAgent


// cvs revision/branch 版號的制定邏輯請見下面分析
// 查看目前local 端skype 檔案的目前狀態,目前client 端工作版本為1.3.2.1.2.1, CVS Server 端的版本為1.3.2.1.2.1 (一樣),
目前client 端的檔案是隸屬於ID_1_6 這個branch的分支

// 另外在下面有列出目前隸屬於skype 這個檔案所有的tag name, branch name, 由這邊可知,
目前共存在有3個branch

[root@nestlin-7 l7fw]# cvs st -v ./skype
userName@1.2.3.4's password:
===================================================================
File: skype Status: Up-to-date ==> client 與server 的檔案一致

Working revision: 1.3.2.1.2.1 ==> Client 端, Working Directory revision
Repository revision: 1.3.2.1.2.1 ==> Server 端, Repository Directory revision
Sticky Tag: ABC_123 (branch: 1.3.2.1.2) ==> 目前Working Directory 的branch/revision
Sticky Date: (none)
Sticky Options: (none)

Existing Tags:
PPP_1_6 (branch: 1.5.2)
ABC_123 (branch: 1.3.2.1.2)
III_123 (branch: 1.3.2)

# cvs log ./skype
userName@1.2.3.4's password:

RCS file: /home/cvsroot/X/Y/Z/skype,v
Working file: skype
head: 1.6
branch:
locks: strict
access list:
symbolic names:
PPP_1_6: 1.5.0.2
ABC_123: 1.3.2.1.0.2
III_123: 1.3.0.2

keyword substitution: kv
total revisions: 13; selected revisions: 13
[omit]
----------------------------
revision 1.3
date: 2005/03/04 09:59:51; author: userName; state: Exp; lines: +3 -3
branches: 1.3.2; ==> 從這邊可以知道有切一個branch 1.3.2, 參考上面cvs st -v 的指令可知道,其branch name 為III_123
User Commit Descriptions
----------------------------
[omit]
revision 1.3.2.1
date: 2005/03/09 09:06:03; author: userName; state: Exp; lines: +1 -0
branches: 1.3.2.1.2; ==> 從這邊可以知道有切一個branch 1.3.2.1.2, 參考上面cvs st -v 的指令可知道,其branch name 為ABC_123
User Commit Descriptions
----------------------------
[omit]

# cvs st -v Makefile
userName@1.2.3.4's password:
===================================================================
File: Makefile Status: Up-to-date

Working revision: 1.38
Repository revision: 1.38 /home/cvs/XXXXX/Makefile,v
Sticky Tag: (none)
Sticky Date: (none)
Sticky Options: (none)

Existing Tags:
branch_1_32_branch_20091216 (revision: 1.32)
tag456 (revision: 1.38)
branch_1_32 (branch: 1.32.2)
main (revision: 1.1.1.1)
vendor (branch: 1.1.1)

# cvs log Makefile | more
userName@1.2.3.4's password:

RCS file: /home/cvs/XXXXX/Makefile,v
Working file: Makefile
head: 1.38
branch:
locks: strict
access list:
symbolic names:
branch_1_32_branch_20091216: 1.32
tag456: 1.38
branch_1_32: 1.32.0.2
main: 1.1.1.1
vendor: 1.1.1
keyword substitution: kv


從上面的情況可知
原先在main trunk上面有切了一個branch III_123 (branch 1.3.2), 後來又在該branch (1.3.2) 上面又切了一個branch ABC_123(1.3.2.1.2), 這裡可以做出下面的結論
1. main trunk 的revision 是從1.1, 1.2, 1.3開始的
2. 如果從main trunk 切branch, 則branch 會變成1.X.Y (e.g. 如果從1.3切branch, 則新版號為1.3.2), 如果是從第一層branch 要切第二層branch, 則版號會是1.3.2.M.N (e.g. 譬如上面從III_123 branch 1.3.2 的子版本1.3.2.1 切出來, 版號會變成1.3.2.1.2
所以
main trunck 的revision main number 為1(1碼), main+sub revision number為1.M(2碼, 從1.1開始)
第一層branch 的revision main number 為1.M.2(3碼), main+sub revision number為1.M.2.N(4碼, 從1.M.2.1開始)
第二層branch 的revision main number 為1.M.2.N.2(5碼), main+sub revision number為1.M.2.N.2.O(6碼, 從1.M.2.N.2.1開始)
==> 結論cvs revision 奇數碼數為branch (如1.3.2), 偶數碼數為tag (如1.32), 只有偶數碼才是真正的revision number, 奇數碼只是main trunk/branch 的base而已
3. symbolic names 和 Existing Tags的關係如下
Existing Tags 表示該branch/tag是從哪一個原先的版號切出來的
Symbolic names 則是一個CVS 內部版號link mark(不確定是否正確), 碼數固定為偶數碼, 其規則如下
a. branch 將原先的Existing Tag 尾碼 .2 改成 .0.2, 例如上面branch branch_1_32 1.32.2, 其Symbolic name為1.32.0.2
b. revision 的Existing Tag 和 Symbolic 的revision完全相同
c. 上面a點所描述的情形中, 唯一會有例外的是vendor branch, 這是利用cvs import 所產生的imitial project(將既存的project import到cvs repository當中), 如下所示
cvs import -m "initial" project-name vendor main

會發現vendor 這個branch在 Existing TAG 和 Symbolic Name 上面的revision 完全相同, 而且這是一個branch, 可能這個vendor branch 對cvs而言有特別的意義?

2009年12月2日 星期三

Linux Command - source

read the linux bash scripts
# source script files
e.g.
# source $HOME/.bashrc
# source $HOME/.cshrc
# source crosstools-env.sh