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]