Friday, February 21, 2014

Linux常用指令集 (Linux/Unix command sets)

這邊不多說,相信開始使用Linux系統後,一定感覺不像Windows那麼方便,滑鼠多點幾就搞定。為了適應這個強大的作業系統,使用終端機(Terminal)指令來控制一定是免不了的,而傻孩子我也相信大多人一定跟我一樣陷入了指令使用的迷思,所以這邊列舉幾個常用的重要指令,希望能為大家指點迷津,也供本人複習之用

常用指令
  • ls: 檢視目錄 [link]
Example:
ls        <-檢視當前目錄下的檔案
ls /      <-檢視根目錄下的檔案
ls ~      <-檢視家目錄下的檔案(等同於指令下ls /home)
ls ..     <-檢視上層目錄中的檔案
ls ../..  <-檢視上兩層目錄中的檔案
ls -al    <-檢視當前目錄中的檔案,可看到包含隱藏檔(-a)、長檔名檔案及軟連結的情況(-l)
ls -t     <-先依照時間排序並檢視當前目錄下的檔案


  • nl: 檢視檔案(附行數) [link]

Example:
nl file1.txt  <-檢視file1.txt中的內容(附行數)


  • ln: 建立連結 [link]

Example:
ln -s file1.txt link <-將link軟連結(Symbolic link)到file1.txt,檢視link有如同在檢視file1.txt

  • pwd: 顯示目前路徑 [link]
Example:
pwd 

  • find: 尋找指令 [link]
Example:
find / -name robert       <- 尋找根目錄下(/)有檔名為robert的檔案

  • su: 切換身份 [link]
Example:
su -l robert <-切換身份到robert (ps. 指令打完須輸入robert身分的登入密碼)


  • sudo: 使用root身分執行指令 [link]
Example:
sudo apt-get install openssh-server <-切換身份帳號到root執行安裝openssh-server (ps. 指令打完需要輸入root密碼)
sudo su                             <-切換身份帳號到root (ps. 指令打完需要輸入root密碼)


  • cat: 觀察或複製多檔  [link]
Example:
cat file1.txt                        <-在cmd模式下看file1.txt的內容
cat -n file1.txt                     <-在cmd模式下看到有顯示行數的file1.txt內容
cat -A file1.txt                     <-在cmd模式下看file1.txt的內容,亦可看到句尾的斷行符號
cat file1.txt | more                 <-當檔案大於一頁,可以用此方式檢視file1.txt較為方便
cat file1.txt file2.txt > file3.txt  <-將file1.txt與file2.txt合併到file3.txt,在file3.txt依序顯示file1.txt然後顯示file2.txt


  • cp: 複製檔案或目錄(含內容) [link]
Example:
cp ../file1.txt .          <-複製上一層目錄下的file1.txt到目前的目錄
cp -r ../folder1 .         <-複製上一層目錄下的資料夾folder1(含內部檔案)到目前的目錄
cp -a file1.txt file2.txt  <-複製一份檔案相同於file1.txt的檔案(含檔案屬性)到file2.txt
cp -a . folder1/            <-複製目前目錄下所有檔案(包含隱藏檔跟資料夾)到資料夾folder1

  • mv: 移動檔案或重新命名 [link]
Example:
mv app1.c folder1         <-將單一app1.c檔案移動到folder1中
mv app1.c app2.c folder1  <-將app1.c與app2.c檔案移動到folder1中 (ps.資料夾要放最後一個參數)
mv file1.c file2.c        <-將file1.c更名為file2.c


  • rm: 移除指令  [link]
Example:
rm file1.c     <-刪除file1.c的檔案
rm -i file1.c  <-詢問是否刪除file1.c的檔案 (使用這個指令比較安全)
rm -r folder1  <-刪除folder1下的所有檔案 (危險,請配合-i指令一起使用)
rm -rf folder1 <-強制刪除folder1下的所有檔案 (使用-f後,會忽略-i的警告提示)
rm -rf .* *    <-強制刪除folder1下包含隱藏檔的所有檔案 (超危險,使用前請三思)


  • source: 讀入環境設定檔  [link]
Example:
source env_setup.sh  <-讀入env_setup.sh的環境設定檔
source ~/.bashrc     <-讀入預設載入的./bashrc的環境設定檔 (當.bashrc經過修改時可使用)

Example:
grep int app1.c        <-螢幕列出app1.c檔案中有int字串的行數及內容
grep -n int app1.c     <-螢幕列出app1.c檔案中有int字串的行數及內容(包含行數)
grep -r int *          <-螢幕列出當目錄下(含子目錄)所有檔案中含有int字串的行數及內容
grep -I "is a girl" folder  <-螢幕列出folder目錄下所有非binary檔中含有is a girl字串的行數及內容
grep "a girl" * --exclude=*.log  <-螢幕列出當目錄下所有檔案(除了名為xxx.log外)中含有a girl字串的內容


  • which: 指令位置  [link]
Example:
which ls             <-螢幕秀出ls指令的執行binary的檔案位置


Tuesday, February 18, 2014

Power point saving/converting to pdf without white border (PPT投影片轉存PDF去白邊)

I don't sure whether you have suffered from the problem of power point saving/converting to pdf with white border. 
不知道大家有沒有這個經驗,在用許多PDF轉檔程式把投影片PPT轉成PDF時,常常都會在旁邊出現不必要的白邊,影響轉檔美觀。


Fig. 1 power point with white border

Hence, I will teach everybody how to solve this problem. You can follow the steps as below.
因此,這邊就是要教大家如何把你辛辛苦苦製作的投影片轉成剛剛好大小的PDF檔案,步驟如下:

1. First, please install the Adobe Acrobat (e.g., I installed the Acrobat XI Pro)
1. 請先安裝Adobe Acrobat (版本我不確定會不會有影響,我是用Acrobat XI Pro的版本,不過我想應該大同小異:P)

2. Open your power point slide, and then click "File/print". I think you can find the same snapshot as Fig. 1.
2. 接下來打開你的投影片資料,點選檔案/列印,應該會看到與Fig. 1相同的畫面

3. Click "Print Contents/Setup/Advance Setting", change the size to "ARCH A"
3. 接著點選"印表機內容/版面配置/進階",並將紙張大小選擇成"ARCH A"

Fig. 2 the print configuration in Acrobat

4. The last step is to select the "Follow the paper size"
4. 最後一個步驟是按下選擇頁數後裡面的"配合紙張大小調整
Fig. 3 detailed configuration for Acrobat

5. Eventally, you can obtain the best result that you want. It has removed the extra white border and suitable to be used the full screen in your PDF display :D
5. 調整完可以看到紙張大小跟投影片的頁面大小一致,所以可以直接按下"列印"後存檔就完成啦,是不是很簡單就得到你想要的完美PDF投影片,這個尺寸放到PDF使用全螢幕看起來也跟投影片呈現的結果一致唷:D
Fig. 4 Wonderful Results for your power point



Monday, February 17, 2014

如何在linux遠端登入的ssh server

可以透過輸入

ssh <ip_addr>

如果有不同的身分的話,請輸入

ssh <user_id>@<ip_addr>

範例如下:
ssh abc@140.118.122.50
然後接著輸入密碼即可登入