用 Shell 在 PDF 檔案中,找出指定字串

From: http://stackoverflow.com/questions/14449968/find-string-inside-pdf-with-shell

Find string inside pdf with shell

As nicely pointed by Simon, you can simply convert the pdf to plain text using pdftotext, and then, just search for what you’re looking for.

After conversion, you may use grep, bash regex, or any variation you want:

while read line; do

    if [[ ${line} =~ [0-9]{4}(-[0-9]{2}){2} ]]; then
        echo ">>> Found date;";

done <<(pdftotext infile.pdf -)

vim 編輯文件時,每行後面總有個錢字符號「$」


Dollar sign at the end of every line

I am relatively new to Vim and am planning to code and learn Ruby on it. But whenever I start the Vim (e.g. vim LearnRuby.rb), a dollar sign appears at every line. I am wondering what’s it all about.

:set nolist

will turn off special characters for the current buffer, such as tabs being presented as ^I and end of line characters showing up as $.

However, if it’s doing that consistently when you run vim, you need to look into your .vimrc (or other startup file where applicable) and find out what’s doing the set list that causes it.

在 vim 執行「:set list!」命令,切換顯示或隱藏這一些特殊字元。

關閉 vim 搜尋的反白 指令


關於 vim 的搜尋反白

各家 distrobution 或者各個工作站的 global settings 裡的 vimrc 可能都有各自的設定, 若您遇到的環境剛好預設把「搜尋反白」打開(set hlsearch), 說不定您會想把它關掉.

如果是搜尋動作完, 想把反白弄掉而已, 可以用「讓 vim 搜尋一段檔案裡不可能出現的字串」的方式, 我的習慣是打:


若想暫時關掉, 可打:

:set nohlsearch


若想把這功能永遠關閉的話, 在 ~/.vimrc 裡寫入 set nohlsearch 就可以了.

[nagios] CRITICAL – popen timeout received, but no child process

CRITICAL – popen timeout received, but no child process.

需要指定使用 ipV4 參數來執行 check_ping 的檢查

修正 nagios 的 command.cfg check_ping 命令的設定僅使用IPV4來檢查

define command{
        command_name    check-host-alive
        command_line    $USER1$/check_ping -4 -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5 -4

nginx + PHP-FPM = “permission denied” error 13 in nginx log; configuration mistake?


因為新建立的目錄無法讓 nginx 服務進入到該目錄(沒有[x]的權限屬性),所以會找不到指定路徑的檔案(在新建目錄下的檔案)。雖然我確定這些檔案路徑是存在的,但網頁服務卻無法取得檔案。


You need to ensure you have +x on all of the directories in the path leading to the site’s root – so /home, /home/noisepages and /home/noisepages/www

[轉貼] Debian Linux 完整移除套件 / 重新安裝套件 / 鎖定套件版本(apt)

文章來源:Tsung’s Blog

很多人常會發生把某個套件搞爛了, 或者設定檔之類不小心砍掉了,

再來想到的當然是移除再重新安裝 或直接 (apt-get install –reinstall package),

但是怎麼裝, 設定檔就是回不來, 搞爛的資料也還是留著.

這並不是 Debian 的錯, 主要是怕你在移除時,

不小心就將重要資料跟著就砍掉了(ex: MySQL 不小心移除就把 DB 砍掉, 這就很尷尬了.)

此篇文章也有說明發生狀況: 如何在 Debian Etch 系統下完全移除套件與實體目錄?


就上述那篇文章的例子, 不小心將 Apache 的設定檔蓋掉/砍掉, 所以打算重新安裝 Apache.

套件移除重新安裝, 和 apt-get install –reinstall apache2 並沒有錯,

只不過問題是, apache2 的 package 裡面並沒有 設定檔. Orz.

由此可見 Package 套件內容:

  • dpkg -L apache2 | grep conf
  • dpkg -L apache2.2-common | grep conf # Debian 設定檔都放在 package_name-common 中
  • 或者上述文章作者的做法是 less /var/lib/dpkg/info/apache2.list 也是可以.
  • 所以要重新取得設定檔, 應該直接

    apt-get install –reinstall apache2.2-common

    即可. (請修改成自己系統的 apache2 版本)


現在遇到的另一個狀況是, MySQL 被搞爛了, 所以要將全部移除(含資料都要移除), 再重新安裝.


apt-get remove –purge mysql-server mysql-server-5.0 mysql-common mysql-client mysql-client-5.0

這一行就會將 DB/設定檔都完整移除(–purge 會將所有移除), 不過大多人的問題是, –purge 後面那一串是從哪來的?


  • dpkg -l | grep mysql # dpkg -l 會列出此系統安裝的所有 package
  • ls /var/lib/dpkg/info/*mysql*

移除之後, 重新安裝直接 apt-get install 就可以囉~ :)

註: 若只是 Database file 爛了, 只要 apt-get remove –purge mysql-server-5.0, 再重新安裝 mysql-server-5.0 即可.


此段內容詳可見: Apt和dpkg快速參考

假設現在要鎖定 gaim 版本, 不想要 gaim 被升級或降級,有下述兩種做法:

  1. echo “gaim hold" | dpkg –set-selections # 將 gaim 鎖定版本
    dpkg –get-selections “gaim" # 檢查: 出現 gaim hold # 狀態是 hold, 就不能被升級了.
  2. vim /etc/apt/preferences # 內容如下, 把版本編號寫死.

    Package: gaim
    Pin: version 0.58*


  1. echo “gaim install" | dpkg –set-selections
  2. dpkg –get-selections “gaim" # 檢查: 出現 gaim install # 狀態被重置為 install, 就可以繼續升級了


  • hold / install 這些狀態標誌都寫在 /var/lib/dpkg/status 裡, 也可以手動去修改變 hold / install 等狀態.


  • apt-get clean #/var/cache/apt/archives 會清掉 *.deb 檔
  • apt-get update # 會更新 /var/lib/apt/lists 的資料


Run Flashtool in Ubuntu Linux

From: http://duopetalflower.blogspot.tw/2012/08/flashtool-in-ubuntu-linux.html

Flashtool in Ubuntu Linux

Everytime I wanted to change firmware for my Xperia phone, I used to reboot into Windows 7

Recently I feel lots of Blue Screen Of Death in Windows 7 (think due to nvidia driver problem), and did not want to reinstall Windows 7

I tried flashtool in Ubuntu Linux and it worked, I changed firmware in my Xperia phone!! Thanks XDA devs and Flashtool devs

Here is how

Download flashtool for Linux from (Refer, http://forum.xda-developers.com/showthread.php?t=1588586)


After downloading the linux version with extension tar.7z, unzip it

To do this, install p7zip, p7zip-full from synaptic or from software center

Unzip the Flashtool folder,

Add this rules to following file (create this file by copying existing 70-persistent-net.rules as follows,
sudo cp /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/80-persistent-usb.rules)

sudo vi /etc/udev/rules.d/80-persistent-usb.rules

and add

SUBSYSTEM=="usb", ACTION=="add", SYSFS{idVendor}=="0fce", SYSFS{idProduct}=="*", MODE="0777″

Before running flashtool install ia32-libs

sudo apt-get install ia32-libs

To run the flashtool enter the directory where the 7zip got extracted and run FlashTool as super user

For e.g I did this

cd Downloads/FlashTool/

sudo su


I choose to install a firmware to my Xperia phone and Flashtool in action

After installing new Firmware my phone screen looks as below

Need help with a PIL Error — IOError: decoder zip(jpeg) not available

From: http://stackoverflow.com/questions/3544155/need-help-with-a-pil-error-ioerror-decoder-zip-not-available

I am getting the:

IOError: decoder zip not available

when I try to draw an image and save to a jpeg in PIL. Any thoughts on how to resolve this? PIL has worked fine for me in the past, when it comes to viewing/uploading images.

It likely only needs the zip decoder to save the jpeg. I think I needed to follow these steps in OS X to preview jpegs.

It probably means you need to: