2014年4月10日 星期四

[Script][Bash + AWK + CURL]

[抓副檔名]
FILE_EXT="`echo ${FILE} | awk -F '.' '{if (NF>1) {print $NF}}'`"

[抓名稱]
NAME="abcd"
NAME="`awk -F '=' '/NAME/ {print $2}' ${CFG} | xargs echo -e`"

[找 symlink]
find . -type l

[用 curl 透過 FTP 傳一整個資料夾到 FTP Server]
find <PATH TO DIR> -type f -exec curl -u <USER NAME>:<PASSWORD> --ftp-create-dirs -T {} ftp://<FTP IP>/{} \;

[用 curl 透過 FTP 刪除遠端資料]
curl -u <USER NAME>:<PASSWORD> -Q "DELE <PATH TO FILE FROM FTP ROOT>" ftp://<FTP IP>

[用 curl 透過 FTP 更改遠端資料權限]
curl -u <USER NAME>:<PASSWORD> -Q "SITE CHMOD 777 <PATH TO FILE FROM FTP ROOT>" ftp://<FTP IP>

[用 curl 獲取遠端有的資料並只刪掉 .tar.gz 檔]
Ref: http://help.directadmin.com/item.php?id=487 

[用 source 一次讀進所有設定檔]
<product.cfg 的內容>
NAME="zqpm"
AGE="26"

source product.cfg 會得到 NAME 和 AGE 兩個變數,並且各自有其值。

2013年11月24日 星期日

[Bash][Redirect 多了個 newline]

好久沒寫 Blog 了。(題外話)

這兩天在拿 The C Programming Language 的習題當練習。

碰到一個問題。

一個程式叫 TARGET 可以計算檔案的 blank、tab、newline、character 數。

我用 ./TARGET < test.txt 進行測試。

每次 newline 的個數都會多一。

不知道是不是 "<" 造成的。

=================================================================

後來乾脆直接把讀到的 char 進行判別後印出來。

發現用 "<" 的話會把 test.txt 的資料直接倒過去 TARGET,然後在最末端加上 newline。

所以用 "<" 或 ">" 時它不止幫忙把資料做 redirect,最後還會 "貼心" 的加個 newline。

好,問題解決。

2013年1月11日 星期五

[Linux][Ubuntu][Intel Audio HD no sound]

好,之前有台比較新的筆電,然後拿來灌 Ubuntu 10.04。

結果灌好後,喇叭沒有聲音.....

察看了下原因,原來是 10.04 的 sound driver 比較舊,所以,就更新 driver 吧。

到 ALSA Project 下載最新的 driver,包含 driver、lib、util 三個檔案。

依序解壓縮並且 sudo ./configure & make & make install 後重開機。
(configure driver 時得加上 --with-cards=hda-intel)

再用 cat /proc/asound/card0/codec#* | grep Codec 得出音效卡的 Module。

再依據 ALSA-Configuration.txt 裡的資料找到相對應的參數值。

接著,編輯 /etc/modprobe.d/alsa-base 這個檔案。

在檔案最尾端加上 options snd-hda-intel model=參數值,以我的為例,參數值是 snd-hda-intel。

接著,再重開機一次,應該就可以聽到聲音了。

Reference:
http://linux.chinaitlab.com/administer/742526.html
http://www.kernel.org/doc/Documentation/sound/alsa/ALSA-Configuration.txt

2012年11月7日 星期三

[Facebook][查 uid]

因為在玩的遊戲出了些問題,需要提供 uid 給遊戲管理者進行確認。

但現在 Facebook 通常在 URL 部份只會顯示英文名稱而已,

以往按自己的照片等方法已經沒辦法獲得 uid 這項資訊。

要查到自己的 uid 資訊,可以用 http://graph.facebook.com/ 後接使用者英文名稱。

如 http://graph.facebook.com/ABCD,就會顯示出 ABCD 這位使用者的 uid 等資訊。

2012年10月26日 星期五

[Ubuntu][一些測試]

[1] 在 Directory 中開啟新檔案,即使沒寫入任何內容,一樣會更動到 Directory 的 Last Modified Time。推測是因為編輯器(如 vim)會創建暫存檔(.swp)所以更動到 mtime。

2012年10月17日 星期三

[Ubuntu][Some problems met recently]

[1] Couldn't make x3270 because of "fatal error: X11/Intrinsic.h: No such file or directory"

sudo apt-get install apt-file
sudo apt-file update
apt-file search Intrinsic.h

X11/Intrinsic.h                     ->   libxt-dev
X11/Xaw/Command.h          ->   libxaw7-dev


2012年9月13日 星期四

[Ubuntu][把新硬碟設定成 NTFS 格式&改既有 NTFS partition 的 label]

標題有點怪,我知道 XD

最近新加了顆硬碟作為資料碟,因為電腦中還有 Win7,
希望能用 Windows 也能讀取的格式,所以想把資料碟用成 NTFS。

首先就是要把它格式改成 NTFS。

=================================================================

sudo fdisk /dev/sde
(sde 是新硬碟在我電腦裡的代號,請自行察看新硬碟在自己電腦中的代號)
=================================================================

在 fdisk 中建立 partition,因為我是想用整顆作為一個 partition,所以
就下指令 n 之後選 primary 後 default default 就建好了,情況像是下面:

=================================================================
Command (m for help): n        <---------------這個是我輸入的
Command action
   e   extended
   p   primary partition (1-4)
p                                              <---------------這個是我輸入的
Partition number (1-4): 1        <---------------這個是我輸入的
First cylinder (1-30401, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-30401, default 30401):
Using default value 30401
=================================================================

然後就順利的把 partition 切好了,可以輸入 p 看看狀況。

=================================================================
Command (m for help): p        <---------------這個是我輸入的

Disk /dev/sde: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xee202071

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1       30401   244196001   83  Linux
=================================================================

因為 System 預設是 Linux,所以現在我要把它改成 NTFS,就輸入 t,
然後 Hex code 輸入 7,當然也可以用 L 看有什麼樣的格式可以選,
因為列出來很難排版,所以有興趣的人再自己去看。然後再輸入 p 列出資訊,
已經把 System 改成 NTFS 了。

=================================================================
Command (m for help): t        <---------------這個是我輸入的
Selected partition 1
Hex code (type L to list codes): 7    <------這個是我輸入的
Changed system type of partition 1 to 7 (HPFS/NTFS)

Command (m for help): p        <---------------這個是我輸入的

Disk /dev/sde: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xee202071

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1       30401   244196001    7  HPFS/NTFS
=================================================================

然後完成了嗎?還沒。還沒把資訊寫進去,所以要用 w 把資訊寫入,
才是真正的把硬碟改成 NTFS 的。

=================================================================
Command (m for help): w        <---------------這個是我輸入的
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
=================================================================

然後就是要格式化它啦,這時可以設定 label 給那 partition,像是我用 Data。
格式化的時間有點長,因為要把 zero 寫入整個 partition 中。
這邊也可以設定 Cluster size,有興趣的自己 man。

=================================================================
sudo mkfs.ntfs -L Data /dev/sde1
Cluster size has been automatically set to 4096 bytes.
Initializing device with zeroes:   3%
=================================================================

等到跑到 100% 了,新硬碟就可以用囉,至於 fstab 那些就自己設定吧。
或者像我用 Ubuntu 的 GUI,可以直接在系統列選 Places,中文翻位置吧,
裡面找到新硬碟,點下去就自動 mount 起來了。

另外要改 label 的話,先把那 partition umount,以我這邊的狀況是。

=================================================================
 sudo umount /media/Data
=================================================================

然後用 ntfslabel 改 label,像是改成 Fun。

=================================================================
sudo ntfslabel /dev/sde1 Fun
=================================================================

這樣就把 label 改掉了,然後再重新 mount 起來硬碟又可以用了。