Topic 101 Hardware & Architecture 筆記 Topic 101 Hardware & Architecture · 1.101.1 Configure Fundamental BIOS Settings Description: Candidates should be able to configure fundamental system hardware by making the correct settings in the system BIOS. This objective includes a proper understanding of BIOS configuration issues such as the use of LBA on IDE hard disks larger than 1024 cylinders, enabling or disabling integrated peripherals, as well as configuring systems with (or without) external peripherals such as keyboards. It also includes the correct setting for IRQ, DMA and I/O addresses for all BIOS administrated ports and settings for error handling. Key files, terms, and utilities include: /proc/ioports 有關io address的資訊 /proc/interrupts 有關中斷的資訊 /proc/dma 有關dma的資訊 /proc/pci 有關pci匯流排的資訊 !! bios(basic input output system) 用來設定系統時間,設備的使用與否,設定?動順序與irq的分配。 irq(interrupt request)編號0~15共16個 dma(direct memory access) 編號0~7共8個 共用同一個irq的設備不可能有相同的io address 常見的irq有 ttyS0 4 ttyS1 3 ttyS2 4 ttyS3 3 lp0 7 lp1 5 fd0 6 fd1 2 常見的ioports有 ttyS0 03e8-03ef ttyS1 02e8-02ef 常見的dma 一般只有floppydisk使用dma ** /proc/apm apm電源管理 /proc/cmdline kernel的?動參數 /proc/cpuinfo cpu的資訊,procinfo用 /proc/devices 系統的字元設備與塊設備的列表(包括主設備號),MAKEDEV使用 /proc/filesystems 目前支援的分區類型與使用的分區類型,mount命令沒有-t時自動嘗試這些分區類型 ??/proc/fd ??/proc/execdomains /proc/iomem 系統高位記憶體資訊,通常用來儲存設備ROM /proc/kcore 實體記憶體 ??/proc/kmsg 由dmesg使用 ??/proc/ksyms /proc/loadavg 系統1,5,15分鐘前的負荷,活動進程/總進程數,供uptime等命令使用 /proc/locks 鎖定的文件列表 ??/proc/mdstat /proc/meminfo 記憶體與交換文件的資訊,供free等命令使用 ??/proc/misc /proc/modules 載入的模組資訊 /proc/mounts mount資訊 ??/proc/mtrr /proc/partitions 物理分區資訊 ??/proc/slabinfo /proc/stat 系統狀態資訊 /proc/swaps 交換文件,分區的資訊 /proc/uptime 開機時間 /proc/version 內核版本 /proc/bus /pci/devices pci設備資訊 /usb/devices usb設備資訊 /proc/driver /rtc rtc時間 /proc/ide ide設備資訊 /proc/scsi scsi設備資訊 ??/proc/net /arp arp表 /dev 設備列表 ??/proc/sys /proc下的數位目錄代表一個進程的pid /proc/[:num:]/cmdline 進程命令 /proc/[:num:]/cwd 運行路徑 /proc/[:num:]/environ 環境變數 /proc/[:num:]/exe 進程exe路徑 /proc/[:num:]/root 進程根目錄 /proc/[:num:]/maps 記憶體映射 · 1.101.3 Configure Modem and Sound cards Description:Ensure devices meet compatibility requirements (particularly that the modem is NOT a win-modem), verify that both the modem and sound card are using unique and correct IRQ's, I/O, and DMA addresses, if the sound card is PnP install and run sndconfig and isapnp, configure modem for outbound dial-up, configure modem for outbound PPP | SLIP | CSLIP connection, set serial port for 115.2 Kbps !! 通常音效卡佔用的irq?5,或者7 音效卡的配置 ================================================================================= [Sound SB 相容音效卡] 先確定是否已安裝sndconfig這個RPM。若無,將安裝光碟放入,執行下列安裝? mount /mnt/cdrom cd /mnt/cdrom cd RedHat/RPMS rpm -Uvh *sndconfig* 接下來,執行sndconfig來設定音效卡? sndconfig 1. 畫面出現後按下OK。 2. 程式會自動偵測到ESS1868卡,畫面資訊如下? A PnP sound card was found in your system. The detail are: Model ESS ES1868 Plug and Play Audio Drive  請按下OK按鈕。 3. 接下來是音效測試。正常情況下,人聲會出現。請按下OK按鈕。 4. 接下來是MIDI音效測試。正常情況下,使用者會聽到一連串的MIDI鍵盤聲,請按下OK按鈕,完成音效卡設定。 [非Sound SB 相容音效卡] 以 root 身份使用命令 sndconfig 即可設置,非常方便的. 如果不是sb音效卡, 試著做 1) 使用 sndconfig 來設置 2) 修改/etc/conf.modules ,加入象這樣幾行 alias sound sb options -k sb io=0x220 irq=5 dma=1,5 alias midi opl3 options -k opl3 io=0x388 3) 在win95/dos下,檢查你的音效卡目前的中斷irq及i/o位址的設定, 手動裝入音效卡模組, 如 modprobe opl3 irq=5 dma=1,5 io=220 4) 如果還無法工作,就只好試試?你的音效卡重新編譯一個新的核心了,在/usr/src/linux 下, 執行 make menuconfig ================================================================================= #sndconfig pci音效卡配置軟體 $isapnp isa周邊設備初始化工具 $pnpdump 察看pnp設備資訊,供isapnp使用 ================================================================================= 有ISA PnP卡的情況,看看那個MODEM有沒有列出來。 pnpdump > isapnp.conf 如果列出來了,那一定是一個多配置設備,將其中一組參數非注釋(uncomment)然後說: isapnp isapnp.conf 初始化你的PnP數據機。如果成功了,別著急,還得幹一件事-重新配製你的內核。將Standard/general serial support 改?模組。重新作: make config make dep ; make clean ; make zImage make modules make modules_install 將所需文件拷貝到/boot目錄中後, lilo shutdown -r now 系統重起後,你作?root說 isapnp isapnp.conf insmod serial 這樣做的道理是,如果不編譯成模組,那?串口驅動程式在內核起動時試圖初始化所有的串口但是PnP卡因?沒被PnP程式初始化,故而串口驅動程式看不見,認?沒有這個東西。編譯成模組就不同了,我們可以先用isapnp程式初始化PnP卡,然後insmod。現在卡已經被PnP程式初始化好了,因而串口驅動程式可以看見它了。 ================================================================================= /etc/sysconfig/soundcard 音效卡配置文件 /etc/isapnp.conf isapnp配置文件 /etc/modules.conf|conf.modules 模組配置文件 內容: alias sound sb options -k sb io=0x220 irq=5 dma=1,5 alias midi opl3 options -k opl3 io=0x388 modem配置 =================================================================================首先Linux並不認什?modem,而是去找串口,然後相關的應用程式在modem所連接的串口設備上 使用AT命令集與modem互動式控制.所以配置modem卡其實就是去配置串口. 如果是PnP的modem卡,請先參考設置PnP卡這一節.設置串口的工具是setserial,配置文件是r c.serial(不同的發行版可能位置不一樣).如果你沒有禁止PnP功能的話,應在內核配置�塈潀磥f這一部分編譯成模組,這樣isapnp把irq/io參數設好以後setserial就可以正常工作了. 另外有些軟體缺省使用/dev/modem設備,其實它通常是一個連接,如ln /dev/cua3 /dev/modem winmodem大多不能支援,linmodem可以支援部分winmodem. ================================================================================= ??/etc/ppp/* ================================================================================= 編輯/etc/ppp/pap-secrets文件,由於撥號採用PAP驗證時,需在該文件中設置相應主客戶機資訊及PAP驗證密碼。在該文件中設置如下:   admin jsred "" 202.194.177.66   第一項?客戶機名稱或IP,第二項?撥號伺服器名稱或IP,第三項?PAP密碼,由於我們使用標準的password文件來進行身份驗證,因而將這�堛滷K碼置空,第四項?動態分配給客戶機的IP位址。 ================================================================================= ??$minicom ======================================================================= 在物理線路正確連接後打開Modem的電源,運行minicom來測試Modem是否已經正確安裝。輸入minicom -s 命令設置Modem相關參數,首先查看缺省串列口,缺省? /dev/modem。根據你所用的串列口將之改?/dev/ttyS0或/dev/ttyS1,其次設置通信速率。如果minicom 與Modem連接成功,進入會話狀態,輸入ATS0=1,如果緊接著在下一行出現OK , 且Modem 的AA燈亮起,modem進入自動回應狀態。表明minicom與Modem通訊正常,Modem可以正常工作了. ================================================================================= ??#setserial spd_vhi baud_base 115200 autoconfig auto_irq 例 setserial /dev/ttyS0 setserial /dev/ttyS0 port 0x100 irq 10 spd_vhi setserial /dev/ttyS0 irq 4 setserial /dev/modem spd_vhi com1->cua0->ttyS0 com2->cua1->ttyS1 com3->cua2->ttyS2 com4->cua3->ttyS3 ======================================================================== PPP|SLIP|CSLIP 一、SLIP協定 SLIP是80年代初開始出現的一種串列線路協定,80年代中後期成?國際上流行的、點對點運行的TCP/IP中的一個標準。在撥號場合下,電話線上傳輸速率可達19.2kb/s,適用于多路由器,多主機(伺服器)或多客戶機共存的網路環境,可基本滿足Internet和Intranet的要求。SLIP最大的特點就是簡單,容易實現。這一特點一方面體現了易操作性,而另一方面也帶來了一系列問題: 1. 這種協定無任何檢錯和糾錯能力,對各種丟失報文或出錯報文的處理需要高層協定進行。 2. SLIP只支援IP報文,當Internet不斷發展和擴大且包含很多非IP協定的網路時,SLIP不適用。 3. 每一方需要另一方的IP位址,且在設置時不能動態賦予IP位址。由於IP地址的短缺,而且家庭撥號用戶經常發生變化,這樣就不可能給每個家庭用戶一個固定IP地址,SLIP這個缺點就顯得格外明顯。 4. SLIP不提供任何身份驗證,因此無法知道真正對話者的身份,這對撥號用戶是一個問題。 5. SLIP未被接受?Internet標準,因此有很多不同的版本存在,不易互操作。 在ISP的用戶中,撥號方式多而且雜,他們的Modem所能達到的速率從9600b/s到56kb/s各不相同,所支援的標準也各不相同,這就需要選用的點到點資料連結協定具備容錯以及支援壓縮等功能,這樣會提高網路傳輸的效率。 另外,由於IP位址的短缺,?每個撥號用戶分配一個靜態IP地址是不可能的,但電話用戶同時撥號上網的絕對數量也不會很多,因此可考慮動態分配IP位址。如果撥號訪問伺服器上有16個非同步埠,僅需分配16個IP地址給撥號用戶即可,誰撥通某一埠,誰就佔用相應埠的一個IP地址,這種情況下使用PPP協定就非常適合。 二、 PPP協定 ?了解決SLIP存在的問題,Internet IETF成立了一個組來制定點到點的資料連結協定。該標準命名?PPP,即點到點協定。PPP能支援差錯檢測,支援各種協定,在聯接時IP地址可賦值,具有身份驗證功能,以及很多對SLIP改進的功能。雖然目前很多Internet服務提供者ISP同時支援SLIP和PPP,但從今後發展看,很明顯PPP是主流,它不僅適用於撥號用戶,而且適用于路由器對路由器線路。 1.PPP和SLIP協定的主要區別 1)PPP具有動態分配IP位址的能力,而SLIP必須靜態輸入; 2)PPP支援多種網路協定,比如TCP/IP、NetBEUI、NWLINK等,而SLIP只支援TCP/IP; 3)PPP具有錯誤檢測以及糾錯能力,支援資料壓縮,而SLIP均不具備; 4)PPP具有身份驗證功能,而SLIP不具備。 2.PPP的功能\r 1)成幀的方法可清楚地區分幀的結束和下一幀的開始,幀格式還處理差錯檢測。 2)利用鏈路控制協定(LCP-Link Control Protocol)建立、配置、測試、關閉資料連結。 3)利用網路控制協定(NCP-Network Control Protocol)建立、配置不同的網路層協定。 3.PPP的幀格式 標誌 地址 控制 協定 資料 校驗 其中標誌欄位指明幀的開始和結束位置;位址位元組一般?全1(廣播方式);協定欄位指明協定類型;資料欄位最長可達1500位元組(長度可變,預設值也是1500);校驗欄位一般有2到4個位元組長。 PPP的幀格式類似於HDLC(High Data Link Protocol)的幀格式,但前者是面向字元的,後者是面向位的。PPP不採用編號幀,只有在干擾大的環境可採用編號幀來實現可靠傳輸,如RFC1663所描述。 · 1.101.4 Setup SCSI Devices Description: Candidates should be able to configure SCSI devices using the SCSI BIOS as well as the necessary Linux tools. They also should be able to differentiate between the various types of SCSI. This objective includes manipulating the SCSI BIOS to detect used and available SCSI IDs and setting the correct ID number for different devices especially the boot device. It also includes managing the settings in the computer's BIOS to determine the desired boot sequence if both SCSI and IDE drives are used. Key files, terms, and utilities include: SCSI ID /proc/scsi/scsi scsi設備資訊 scsi_info 察看scsi設備資訊 !! scsi總線速度通常?5~160MB 普通scsi匯流排可以接8個設備(包括SCSI控制器),scsi id 0~7 widescsi匯流排可以接16個設備(包括SCSI控制器),scsi id 0~15 scsi控制器的id?id 7 通常用來?動的設備,scsi id ?0 scsi硬碟:/dev/sda;sdb;sdc scsi磁帶:/dev/st0;st1;st2 scsi光碟機:/dev/scd0;scd1;scd2 scsi bios 設定: ?動設備 scsi id scsi 速度 終結器 · 1.101.5 Setup different PC expansion cards Description: Candidates should be able to configure various cards for the various expansion slots. They should know the differences between ISA and PCI cards with respect to configuration issues. This objective includes the correct settings of IRQs, DMAs and I/O Ports of the cards, especially to avoid conflicts between devices. It also includes using isapnp if the card is an ISA PnP device. Key files, terms, and utilities include: /proc/dma /proc/interrupts /proc/ioports /proc/pci pnpdump(8) isapnp(8) !!基本步驟就是: 1) 運行 pnpdump > isapnp.conf 2) 修改 isapnp.conf , 按照你需要的配置, 去掉相應行前面的# 3) 把新的isapnp.conf, 拷貝到/etc, 然後/sbin/isapnp /etc/isapnp.conf lspci(8) 用來察看pci設備的狀態 例: lspci -t -vvv 以樹狀顯示pci設備詳細資訊 · 1.101.6 Configure Communication Devices Description: Candidates should be able to install and configure different internal and external communication devices like modems, ISDN adapters, and DSL switches. This objective includes verification of compatibility requirements (especially important if that modem is a winmodem), necessary hardware settings for internal devices (IRQs, DMAs, I/O ports), and loading and configuring suitable device drivers. It also includes communication device and interface configuration requirements, such as the right serial port for 115.2 Kbps, and the correct modem settings for outbound PPP connection(s). Key files, terms, and utilities include: /proc/dma /proc/interrupts /proc/ioports setserial(8) · 1.101.7 Configure USB devices Description: Candidates should be able to activate USB support, use and configure different USB devices. This objective includes the correct selection of the USB chipset and the corresponding module. It also includes the knowledge of the basic architecture of the layer model of USB as well as the different modules used in the different layers. Key files, terms, and utilities include: lspci(8) 顯示pci設備 usb-uhci.o UHCI (Intel PIIX4, VIA, ...) support usb-ohci.o OHCI (Compaq, iMacs, OPTi, SiS, ALi, ...) support usbcore.o usb核心支援 ??/etc/usbmgr/ usbmodules ??/etc/hotplug 類比軟碟 A suitable entry for a floppy disk would be: /dev/sda /mnt/usbfd auto noauto,user 0 0 類比硬碟 A suitable entry for a Zip disk would be: /dev/sda1 /mnt/usbzip vfat noauto,user 0 0 問題: /etc/ppp/* Topic 107 Printing 笔记 Topic 107 Printing · 1.107.2 Manage printers and print queues Description: The candidate should be able to manage print queues and user print jobs. This objective includes monitoring print server and user print queues and troubleshooting general printing problems. Key files, terms, and utilities include: lpc 印表機控制 lpq 列印佇列顯示-l 詳細資料 -P印表機名 -a 所有列印佇列 lprm 列印佇列刪除 lpr 脫機列印 -C class A(lowest)-Z(highest ) lpr -C B test.txt -h 不顯示title -K -# -P printer -T title ================================================================= Linux下的列印工作   在Linux下採用周邊同作(spooling)列印方法,當用戶需要列印一個文件時,該文件並不直接送到印表機,而是送到spool目錄下,然後由一個負責列印的後臺進程把這些資料送入印表機。   Linux對每台印表機都定義了一個列印緩衝區,印表機守護程式經常掃描列印緩衝區以查看有無要列印的新文件。如果存在,就按先進先出的順序列印緩衝區中的文件。   Linux系統除了可以在本地印表機上列印外,還可以通過網路印表機遠端列印。   用於列印的命令   Linux系統提供了一組有關列印的命令。一般情況下,列印命令使用默認印表機;如果用戶定義了PRINTER環境變數,列印命令就使用這個變數定義的印表機;另外,用戶還可以在命令行上指定要使用的印表機。   lpr命令   lpr命令是脫機列印命令,該命令將列印作業放到列印緩衝佇列中。?Linux系統指定的每台印表機都有自己的列印緩衝目錄,每個目錄中的minfree文件指定保存列印文件的磁片塊的數量。 lpr同lpd守護進程通訊,lpd掃描/etc/printcap文件,查詢印表機對應的緩存目錄,然後由lpd控制列印,將需要列印的資料送到實際印表機上。如果沒有指定文件,lpr就使用標準輸入。   lpr命令的格式?: lpr [-P printer] [#num] [其他選項] [name…] 命令中各選項的含義如下:   -P 指定印表機。如果不用此選項,則使用缺省印表機或環境變數PRINTER指定的印表機。   -m 列印完畢後發送email。   -#num 列印num份。   lpq命令   lpq是緩衝佇列檢查命令,它通過lpd在緩衝區中檢查列印文件,報告指定作業的狀態或指定用戶的所有作業。不帶任何參數的lpq命令顯示現在佇列中的任何作業。lpq命令的顯示結果中一個重要的資訊就是作業標識號(作業ID),它標識一個特定的作業。如果用戶想取消一個挂起的作業,就必須在命令中指定這個標識號。   lpq命令的格式?: lpq [-l] [-P printer] [job #] [user…] 命令中各選項的含義如下:   -P 指定一個印表機,否則使用缺省印表機或環境變數PRINTER指定的印表機。   -l 列印組成作業的所有文件的資訊。 對提交的每一個作業,lpq報告用戶名、在佇列中的級別、組成作業的文件、作業標識以及總的大小等資訊。   lprm命令   lprm命令用於從緩衝佇列中刪除列印作業,用戶可以使用該命令從緩衝佇列中刪除屬於自己的一個或多個列印作業。   lprm命令的格式?: lprm [-P printer] [-] [job #] [user…] 命令中各選項的含義如下:   -P 指定一個印表機,否則使用缺省印表機或環境變數PRINTER指定的印表機。   - 刪除用戶所有的列印作業。   user 刪除佇列中屬於用戶user的作業(只有超級用戶可以這樣做)。   job # 通過指定作業號#刪除某個列印作業,作業號可以通過lpq命令得到,如:   $ lpq -l   lst:ken [job #013ucbarpa]   (standard input) 100 bytes   $ lprm 13   列印緩衝區目錄   對列印而言,有一個非常重要的目錄,就是列印緩衝區目錄,要列印的資料在被列印之前都集中到這�堙C通常一台印表機對應一個列印緩衝區目錄,這樣比較容易管理印表機。例如,系統使用/var/spool/lpd作?主列印緩衝區,每個單獨的印表機都在主列印緩衝區下有一個與這台印表機同名的目錄。因此,名?ps_nff的印表機把/var/spool/lpd/ps_nff作?它的列印緩衝區目錄。 lpc(8) 程式用來控制 lpd 提供列印的列印機。通過 lpc 程式可控制列印機的列印功能、列印任務列隊、重新安排列隊次序和提供列印機和列隊狀況。 lpc 多數用於設置系統時一機配置多列印機的情況。 $ lpc 上述指令啟動 lpc 程式。在不設置任何參數的情況下,這使用戶進入互動模式,此後可開始輸入指令。使用 lpc 的另一個方式是從指令行輸入參數。 $ lpc status all 所有可用的指令均在 lpd 的使用說明(man page)內可以查到。此處列出一些主要指令。指令中作為 選項 列出的部分可以是列印機名(lp、print 等)或關鍵字 all,此處表示所有列印機。 disable 選項 - 不讓列印機再接受新的列印任務 down 選項 - 停止列印機的一切列印 enable 選項 - 允許列印任務進入列印列隊 quit (或 exit) - 停止 lpc 運行 restart 選項 - 重新開始列印機的 lpd status 選項 - 印出列印機的機況 up 選項 - 重新起始並開始新的 lpd abort topq hold ============================================================== · 1.107.3 Print files Description: Candidates should be able to manage print queues and manipulate print jobs. This objective includes adding and removing jobs from configured printer queues and converting text files to postscript for printing. Key files, terms, and utilities include: lpr lpq mpage 把多頁內容列印在一張紙上 · 1.107.4 Install and configure local and remote printers Candidate should be able to install a printer daemon, install and configure a print filter (e.g.: apsfilter, magicfilter). This objective includes making local and remote printers accessible for a Linux system, including postscript, non-postscript, and Samba printers. Key files, terms, and utilities include: lpd checkpc 檢驗/etc/printcap /etc/printcap ~/printcap /etc/apsfilter/*/ /var/lib/apsfilter/*/ /etc/magicfilter/*/ /var/spool/lpd/*/ /etc/lpd.conf LPRng config ============================================================ Q1. 這個系統怎?這?爛?只能列印 6 頁,超過 6 頁就顯示“file too large (文檔太長)”。 A5. 在 /etc/printcap 檔中有一個參數與列印的文檔長度有關。預設值是 1000 盤區(約 500 k)。對 PostScript 這類文檔而言,這大約是 7-8 頁左右的長度。因此務必在印表機的設定中加入下列內容: mx=0 附加這個指令的主要原因是不使用周邊同作。另一個完成這項工作的方法是用 lpr 在周邊同作目錄內對列印的文檔生成軟連接。務必記得每次均需在 lpr 指令中使用 -s 選項。 Q2. 什?是魔術篩檢程式(magic filter)? A3. 魔術篩檢程式是一種根據文檔的種類採取行動的篩檢程式。例如,如果文檔是沒有排版格式的文本文檔時,則利用一般列印方式列印。如果文檔是 PostScript 文檔或其他格式文檔,則用其他方式列印( ghostscript )。常用的魔術篩檢程式有 magicfilter 和 APSfilter。使用這類篩檢程式的一項要點是在安裝篩檢程式之前必需先安裝應用軟體。 需要注意這項要點的理由是在安裝 magicfilter 時,這個魔術篩檢程式會查詢系統中裝有何種列印程式(例如 ghostscript,如果找到 ghostscript,則 magicfilter 就知道它能處理 PostScript 格式的文檔),然後根據找到的列印程式作出相應的設定。如果系統要處理所有列印文檔,可能至少得安裝下列程式: GhostScript TeX NetPBM jpeg utilities (譯注:jpeg 工具軟體) gzip Ghostscript 是 PostScript 印表機類比程式,透過軟體類比,可以讓非 PostScript 印表機,也能印出 PostScript 文件。 ======================================================================== /etc/printcap;/etc/printcap.local (用戶應該修改/etc/printcap.local,而不是;/etc/printcap) 基本上, 要增加一個列印佇列, 你必須在 /etc/printcap 中加一筆記錄, 以及在 /var/spool/lpd 之下建立一個列印暫存器的工作目錄(spool directory). /etc/printcap 中的記錄看起來像這個樣子: # LOCAL djet500 lp|dj|deskjet:\ :sd=/var/spool/lpd/dj:\ :mx#0:\ :lp=/dev/lp0:\ :sh: 這個例子定義了一個名為 lp, dj, 或是 deskjet 的列印暫存器, 暫存器的工作目錄在 /var/spool/lpd/dj, 沒有單一工作大小的上限, 列印的裝置是 /dev/lp0, 而且不會在每一個工作之前加上標題頁 (有著列印人的姓名之類的資料). 上面這個例子看起來非常簡單, 但是有一個問題 - 除非 DeskJet 500 能看懂我送出去的檔案, 否則便會印出亂碼. 舉例來說, 假如送一個傳統的 Unix 文字檔案給 deskjet 會導致新行字元(newline) 被逐字列印, 而得下面的結果: This is line one. This is line two. This is line three. 同樣的, 列印一個 PostScript 檔到這個列印暫存器會得到同樣階梯狀的 PostScript 命令列表, 而不是我們需要的結果. 很顯然我們還需要些什麼, 這就是 filtering 的目的. 看過 printcap 線上手卌的比較細心的讀者可能已經注意到 if 及 of 這兩個屬性. 其中的 if, input filter 就是我們現在所需要的. 假使我們寫個短短的 shell script 叫 filter 使之在新行字元之前加上回車字元(carriage return), 就可以消除階梯狀. 所以我們必須在前面的 printcap 的記錄中加上 if 這一行: lp|dj|deskjet:\ :sd=/var/spool/lpd/dj:\ :mx#0:\ :lp=/dev/lp0:\ :if=/var/spool/lpd/dj/filter:\ :sh: 這個短短的 filter script 可以是: #!perl # The above line should really have the whole path to perl # This script must be executable: chmod 755 filter while(<STDIN>){chop $_; print "$_\r\n";}; # You might also want to end with a form feed: print "\f"; 假如我們照上面的方法, 我們就會得到一個能正常印出普通 Unix 文字檔的列印暫存器. (還有其他四百萬種更好的方法來寫這個命令稿, 但是這個很適合舉例, 你可以自己寫一個更有效率的.) 剩下的唯一問題是只能印出純文字檔實在是不夠好 - 如果能夠印出 PostScript 或是其他格式化的或是圖形輸出就更棒了. 這可以做的到, 也很容易做到. 方法就是延伸前面的 filter. 如果你寫出一個能接受任意檔案格式, 然後針對每種情況都可以產生 DeskJet 所要的資料的 filter, 那你就有了一個智慧型的列印暫存器. 這種 filter 稱之為 magic filter. 你無需自己寫一個, 除非你要印的東西很奇怪. 網路上已經有很多寫好的, APS Filter 就是非常棒的一個. 也說不定你的 Linux 發行版本(distribution) 已經包括了一個印表機設定工具使得這一切都很容易. # /etc/printcap PS|PostScript:\ :sd=/var/spool/lpd/postscript:\ spool目錄 :mx#0:\ 最大任務 :lp=/dev/lp0:\ 列印埠 :if=/var/spool/lpd/postscript/filter:\ 列印篩檢程式 :sh:\