2012年7月23日 星期一

copy files according the list file

其實這是 moore 的 script。
他把各系統要 copy 的 filename 寫在同一個 list file 中,每個 filename 用 ≶ > 刮起來。
仿造 xml 格式,裡面是 系統名稱。
<N_Series>MyBrowser.apk</N_Series>

所以要寫一個 script,依照這個 list 內容來 copy files..




要注意那個從 filelist xml 中剔除 tag 的 sed,要先把 </...> 剔除,再剔除開頭的。
否則因為整個 entry 剛好被包圍,所以會被整個剔除。

2012年7月22日 星期日

mount , 並指定 uid, gid 和 charset

mount 並且設定 mount folder 的 uid, gid, (or iochartset).

都是用 -o

uid, gid:
# mount -o uid=charles-chang,gid=charles-chang /dev/sdd1 ~/sd

如果是要 mount windows 的 share (samba, cifs),中文的問題可以用: iocharset:
mount -t cifs -o username=softwaretest,password=softwaretest,iocharset=utf8,uid=charles-chang,gid=charles-chang //192.168.147.225/ODM3 /home/charles-chang/buildingmachine

兩個 -o 可以何在一起,中間用 ',' 隔開

2012年5月17日 星期四

find .. then cd to it(them)

找到含 .git 的目錄,cd 過去,run git status..

ref: http://www.linuxquestions.org/questions/programming-9/shell-script-to-cd-into-the-result-of-find-592503/

#/bin/sh find . -type d -name '.git' | while read F; do D=$F/../ cd "$D" echo $PWD git status cd - > /dev/null echo --------------- done 找到的 path 含 .git,所以要cd 到 .git 上一層。
做完後,回到剛剛的目錄: cd - 不要把 cd - 的 command 印(echo) 出來,所以加上 > /dev/null

2012年4月24日 星期二

string operation -- replace file extension name

如果只是簡單的filename 操作,可以用 "${filename...}"
例如:把所有 mp4 檔 rename 成 avi: for file in *.mp4;do mv "$file" "${file/.mp4/.avi}";done
像這個 ${file/.mp4/.avi} 就是把 $file 中 .mp4 換成 .avi,其中的兩個 "/" 符號就是 replace。


ref:
  1. http://www.thegeekstuff.com/2010/07/bash-string-manipulation/
  2. http://www.faqs.org/docs/abs/HTML/string-manipulation.html

2012年4月17日 星期二

sed -- delete lines containing string

刪除包含某些字串的內容(行)

這個用 sed 來作 sed '/match string/d' file > out
sed 是用 '/.../' 來指定操作。

/../ 內是 match 的 pattern,
最後的/ 後面指定操作。
/../d 代表刪除。

所以 sed '/match string/d' infile > out
會把infile 中,所有包含 "match string" 的字行都刪除。



要是要刪除很多字串,可以用 -e 選項把所有 pattern command 連起來.. sed '/stringA/d' -e '/stringB/d' -e '/stringC/d' infile > out

但是要是 pattern command 有很多,也可以寫在 file 裡,一行代表一個command.. # delabc : del stringA.B.C /stringA/d /stringB/d /stringC/d
然後用以下command: sed -f delabc infile > out

2011年8月28日 星期日

mount partition with read-write permission for all users

mount 時,使用 umask option 可以指定 mount 位置得權限。

#mount -o umask=0002 /dev/sdd1 /sd
這樣 /sd 的權限會是:
rwxrwxr-x


umask 的 內容是 八進制,而且是 "not"。
所以 0002 就是不包含 other 的 write 權限。



所以 -o umask=0000 就是所有人,所有權限

2011年7月21日 星期四

test condition : file, directory

用在 if, while 等 流程控制 的判斷,像
if [ -f /etc/passwd ]; then
echo "found"
else
echo "not found"
fi

其中的 -f 就代表 is a file.

https://sites.google.com/site/tiger2000/home 有列出所有的 file test 選項:
[ -e file ] file exists
[ -f file ] file is a file
[ -d file ] file is a directory
[ -c file ] file is a character device
[ -b file ] file is a block device
[ -p file ] file is a named pipe
[ -s file ] file is not empty
[ -k file ] file's sticky bit is set
[ -S file ] file is a socket
[ -L file ] file is a symbolic link
[ -r file ] file is readable by user
[ -w file ] file is writeable by user
[ -x file ] file is executeable by user
[ -O file ] file is owner by user
[ -G file ] file is group owned by a greoup
[ -u file ] file has its set user ID bit set
[ -g file ] file has its group user ID bit set
[ file1 -nt file2 ] file1 is newer than file2
[ file1 -ot file2 ] file1 is older than file2
[ file -ef file2 ] file1 is another name for file2

[ $str1 = $str2 ] str1 string is the same as string str2

另外一個,是 and , or 的 邏輯運算:

-a and
-o or
! not

* 奇怪的是 這些 邏輯運算後面的 operand 好像要加"" 括號