Saturday, December 27, 2008

some tips

  1. "\ls" will use the raw "ls" instead of the aliased one
  2. in Android, if two projects with the same package name are created in Eclipse, they are not going to co-exist on the emulator, the later-installed apk will overwrite the earlier one.
  3. resue damaged hard drive:
    dd bs=512 conv=noerror,sync if=/dev/hda of=/some_dir/foo.image
    Also can use gzip or bzip2 to compress.
  4. FAT32 can only allow a maximum file size of 4GB. So when doing the data rescue with a destination of FAT32 partition, it will show "stdout: file too large" when the image file reaches 4G. It's not the gzip or bzip2 problem. Solution is to change the file system. BTW: better stay away from HFS, an Apple monoply file system, except some frenetic apple fans who are using HFS for all their drives.
  5. On an Apple iBook G4, hold down 'Option' key when it boots, will let you choose the boot media. If having trouble ejecting a disc, ultimate solution is to restart the computer while holding down the trackpad button.
  6. The hfsplus file system is supported in linux kernel, which has to be selected. The location is 'File systems -> Miscellaneous filesystems -> Apple xxxx support'.
  7. To burn an toast image under windows: use daemon-tools to mount the toast image, then use DVD burn software to copy from the virtual device to the destination DVD-RAM. Windows is not able to read files from the toast image.
  8. convert dmg file to iso (under mac os x)
    hdiutil convert /path/to/filename.dmg -format UDTO -o /path/to/savefile.iso
    It will add a .cdr suffix. Just rename it to iso.
  9. xargs with blank space in file name. The GNU xargs (used on Linux) has a -0 (zero) option; this means the pathnames it reads are separated by NUL characters instead of whitespace. GNU's find (also used by Linux) has a -print0 operator that puts a NUL between pathnames instead of a newline. Use them together like this:
    find . -type f -mtime +7 -print0 | xargs -0 rm
    Here is a good article on find/xargs.

Tuesday, November 18, 2008

The art of font selection.

Recently I am reading the manual of latex-beamer, because I want to use it for presentation. There is a chapter called `Guidelines for Creating Presentations' in beameruserguide.pdf, which is worth reading line by line. Besides guide lines for presentation, it describes cons and pros of various fonts and how to select appropriate ones. There is art in font selection. Well, everyone who has played with linux desktop optimization will agree. But it is still interesting to read the user guide.

For example, in the small caps part, it first states the disadvantage of uppercase text.
Text typeset in small caps is harder to read than normal text. The reason is that we read by seeing the “shape” of words. For example, the word “shape” is mainly recognized by seing one normal letter, one ascending letter, a normal letter, one descending letter, and a normal letter. One has much more trouble spotting a misspelling like “shepe” than “spape”. Small caps destroy the shape of words since shape, shepe and spape all have the same shape, thus making it much harder to tell them apart. Your audience will read small caps more slowly than normal text.


Then it adds
This is, by the way, why legal disclaimers are often written in uppercase letters: not to make them appear more important to you, but to make them much harder to actually read.

Wednesday, October 15, 2008

Great Article on Linux dd command

Author: AwesomeMachine @ LinuxQuestions.org

original link

I followed the instructions to create an image for my windows drive. It's killing me to reinstall xp.

creating backup image
dd if=/dev/hda1 | bzip2 > /home/winxp.image.bz2
restoring image
dd if=/home/winxp.image.bz2 | bunzip2 | dd of=/dev/hda1

Compiz Fusion: a not recommend configuration

UPDATE: Hooooray!! The border is on after I add the `decoration` plugin to the very last line of /usr/bin/compiz-start. Also I change this file to use `emerald` instead of `gtk-window-decorator` and it works!!!! So I know one thing, can't fully trust `ccsm` and always turn to reliable command line. Oh, if `emerald --replace` has no output, no error, it's probably means it's working. Compiz fusion rocks! Even better if I can have a better video card~



Compiz Fusion is not working perfectly on my gentoo. First of all, no window border. After several days googling, I gave up. A note, if `emerald --replace` or `gtk-window-decorator --replace` is working fine, then that's the compiz configuration problem. My case is that these two commands does nothing, no output, no change, no error. But I can live with that.

Second problem that took me a long time is the configuration. The setting in `ccsm` does not take effect and even cause a compiz segmentation error. Then I used a brute force configuration. Not recommended, only for desperate people.

  1. gain root privilege
  2. use `ccsm` to determine which plugins should be needed, the plugin name can be found in Preferences | plugins list.
  3. modify the last line of /usr/bin/compiz-start, delete "gconf", add all the plugins you want to enable. Backup before change.
  4. modify the corresponding xml files in /usr/compiz to change the behavior, remember to make backup file before change. And be careful.
  5. add all the compiz fusion related packages to package.mask to prevent from any modificaton.
  6. compiz-start and good luck. Check the error output in case the xml format is messed up.


APPENDIX: /etc/X11/xorg.conf
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "aticonfig-Screen[0]" 0 0
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "TouchPad" "AlwaysCore"
InputDevice "Mouse1" "CorePointer"
EndSection

Section "Files"

FontPath "/home/fonts"
FontPath "/usr/share/fonts/100dpi"
FontPath "/usr/share/fonts/cyrillic"
FontPath "/usr/share/fonts/wqy-bitmapfont"
FontPath "/usr/share/fonts/75dpi"
FontPath "/usr/share/fonts/default"
FontPath "/usr/share/fonts/misc"
FontPath "/usr/share/fonts/Type1"
FontPath "/usr/share/fonts/ttf-bitstream-vera"
FontPath "/usr/share/fonts/corefonts"
FontPath "/usr/share/fonts/zh-kcfonts"
FontPath "/usr/share/fonts/util"
# FontPath "/usr/local/share/fonts"
# FontPath "/usr/X11R6/share/fonts"

EndSection

Section "Module"
Load "freetype"
# Load "xtt"
Load "extmod"
Load "glx"
Load "dri"
Load "dbe"
Load "record"
Load "xtrap"
Load "type1"
Load "speedo"
EndSection

Section "InputDevice"
Identifier "Mouse1"
Driver "mouse"
Option "Protocol" "IMPS/2"
Option "Emulate3Buttons"
Option "ZAxisMapping" "4 5"
Option "Device" "/dev/input/mice"
EndSection

Section "InputDevice"
Driver "synaptics"
Identifier "TouchPad"
Option "Device" "/dev/input/mouse0"
Option "Protocol" "auto-dev"
Option "LeftEdge" "1700"
Option "RightEdge" "5300"
Option "TopEdge" "1700"
Option "BottomEdge" "4200"
Option "FingerLow" "25"
Option "FingerHigh" "30"
Option "MaxTapTime" "180"
Option "MaxTapMove" "220"
Option "VertScrollDelta" "100"
Option "MinSpeed" "0.09"
Option "MaxSpeed" "0.18"
Option "AccelFactor" "0.0015"
Option "SHMConfig" "on"
EndSection


Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XkbModel" "pc104"
Option "XkbLayout" "us"
EndSection

Section "Monitor"

### Comment all HorizSync and VertSync values to use DDC:
Identifier "Monitor0"
HorizSync 31.5 - 64.3
VertRefresh 60.0 - 90.0
DisplaySize 331.8 207.3 ## for 15.4", DPI=98
EndSection

Section "Monitor"
Identifier "aticonfig-Monitor[0]"
Option "VendorName" "ATI Proprietary Driver"
Option "ModelName" "Generic Autodetecting Monitor"
Option "DPMS" "true"
EndSection

Section "Device"
Identifier "Card0"
Driver "radeon"
Card "ATI Graphics Xpression"
EndSection

Section "Device"
Identifier "aticonfig-Device[0]"
Driver "fglrx"
# BusID "PCI:2:0:0"
Option "DesktopSetup" "horizontal"
Option "VideoOverlay" "on"
Option "UseFastTLS" "2"
Option "EnablePrivateBackZ" "on"
Option "DynamicClocks" "on"
Option "XAANoOffscreenPixmaps" "true"
Option "TexturedVideo" "On"
Option "DRI" "true"
Option "MonitorLayout" "LVDS,AUTO" #Enable Externel Monitor
EndSection

Section "DRI"
Mode 0666
EndSection

Section "Extensions"
Option "Xvideo" "Enable"
Option "Composite" "Enable" ## critical
EndSection

Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 24
Modes "1280x800" "1024x640"
EndSubSection
EndSection

Section "Screen"
Identifier "aticonfig-Screen[0]"
Device "aticonfig-Device[0]"
Monitor "aticonfig-Monitor[0]"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 24
Modes "1280x800" "1024x640"
EndSubSection
EndSection

Section "ServerFlags"
# Option "DontVTSwitch" "True" # kills the Ctrl+Alt+F(1-6) virtual terminal switch commands
# Option "DontZap" "True" # kills the Ctrl+Alt+Backspace command
EndSection


Sunday, October 12, 2008

Gentoo troubleshootings

After 3 and half days. I got gentoo upgraded on my acer 5102WLMi. Gentoo is a great distro. Love it. Now audio is working, but still not camera.

The Name:
The Gentoo species is the fastest swimming penguin.
Hardware specification
    1. Processors : AMD Turion 64x2 TL50 (1.60GHz, 512K L2 cache)
    2. Chipset: ATI RS480
    3. Displays: 15.4" WXGA (1280 x 800 resolution)
    4. Graphics Card: ATI Radeon Xpress 1100
    5. Optical Drive: DVDRW
    6. Sound Card: integrated, snd-hda-intel, realtek
    7. Wireless Networking: Atheros AR5005G 802.11abg
    8. MMC reader: ENE Technology Inc SD/MMC Card Reader
    9. I/O Ports : 3 USB 2.0, Audio jacks, 15-pin monitor connector, PCMCIA slot.
Useful links
  1. Gentoo documentation
  2. audio setup: http://gentoo-wiki.com/HARDWARE_Acer_Aspire_5102WLMi
  3. articles with gentoo tag: http://kunxi.org/
  4. Google
Notes:
  1. when upgrading, first emerge update all packages, resolve blockings(uninstall or upgrade, if circular blocking, --nodep). Then revdep-rebuild.
  2. use "equery" to look at installed packages
  3. gcc-config, kernel-config, etc to choose from different slots.
  4. make.conf, package.keywords, package.mask, package.unmask, package.use, ...
  5. if use "startx", add "gnome-session" to .xinitrc, else X will not load gnome.
  6. firefox+flash

    sudo echo "net-www/netscape-flash" >> /etc/portage/package.unmask
    sudo emerge -av netscape-flash nspluginwrapper

  7. firefox+mplayerplug-in (UPDATE: "emerge adobe-flash" will do the job)
    sudo echo "net-www/mplayerplug-in -firefox divx quicktime realmedia wmp" >> /etc/portage/package.use
    ## Make sure no browser running
    sudo emerge -av mplayerplug-in

    ln -s /usr/lib/nsbrowser/plugins/mplayerplug-in.so $HOME/.mozilla/plugins/mplayerplug-in.so
  8. cp936 support is not default in kernel, so need to add support in kernel.
    File Systems --->
    DOS/FAT/NT Filesystems --->
    Native Language Support
  9. teTeX set up, "latex" does not come with the package automatically, seems there are a lot of high-level TeX users.
    emerge -av tetex
    texconfig confall ## check all the output
    texconfig rehash
    texconfig init ## will generate all other binaries: latex, omega,...
    emerge -av app-emacs/auctex ## a must-have package for emacs+latex
    emerge -av emacs-update ## as the package suggest
  10. use TuxOnIce to do hibernate and hibernate-ram, just follow this HOWTO. Work like a charm. ATTENTION: if the lid-and-battery script is used, DO NOT put the code directly in `/etc/conf.d/local.conf'. It will run forever and will not act as a child. Instead, paste the script code into a file, say `/etc/lid_battery_suspend', do a `chmod u+x /etc/lid_battery_suspend.sh', and then add one line `/etc/lid_battery_suspend.sh &' to `/etc/conf.d/local.conf'.
    HOWEVER, after one suspend/hibernation, this script will be stopped and not be loaded. An alternative way is to let acpi take care of this. Look at /etc/acpi/events and change the actions for lid and battery. Then restart acpid service. Well, you take the risk.
  11. clean gnome desktop, use gconf-editor (looks like register table in Windows), find apps \ nautilus \ desktop, uncheck, uncheck, uncheck. Nice pure wallpaper.
  12. HOWTO take compiz screen shot: open gimp, go to File > Aquire > Screenshot. You can set a delay of however many seconds to give yourself time to get the cube in the right position. Hold it there until the PC's speaker beeps.
  13. HOWTO_NTP, NTP (Network Time Protocol) is used to synchronize your system's time with an online server.
    echo "net-misc/ntp caps" >> /etc/portage/package.use
    emerge -av ntp
    vi /etc/conf.d/ntp-client # can change the OPTS, change time servers
    /etc/init.d/ntp-client start # start sync
    #rc-update add ntp-client boot # optional
    ntp-client is only a wrapper of ntpdate program. If need to sync automatically, need to start ntpd. Ahh, before setting NTP, check /etc/localtime, if not in the right time zone, copy or link corresponding zone file from /usr/share/zoneinfo/.
  14. (Nov 16,2008) Well, alsa packages(alsa-driver, alsa-lib, alsa-headers, alsa-util) 1.0.18 update is not working and I cannot figure out why, the sound card can not be found. So I downgraded back to 1.0.17, but the alsa-lib remains 1.0.18. And it's back to work! Mask them at once.
xorg-x11 troubleshooting:
  1. "xauth: error in locking authority file /home/usrname/.Xauthority", will result in a dark screen with cursor usable after "startx", but nothing shows up. And the command window keeps prompting:
    xlib: connection to :0.0 refused by X server
    xlib: no specified protocol
    The solution is to use
    xauth -b quit
    to break existing lock, also check the permission of .Xauthority.
  2. ati-drivers
    fglrx(0): incompatible kernel module .......
    update ati-driver, even with the ~ keyword
  3. cannot startx, the error shows
    Synaptics DeviceOn Called
    Can't initialize SocketServer
    Failed to initialize Panel Agent

    It's probably because you have deleted or modified the /tmp directory, please check the permission of this directory, or just do a sudo chmod 777 /tmp.
hibernate troubleshooting:
  1. The Problem: hibernate works under text mode. But under X mode, it resumes at the "Going Atomic" step and gives an error saying
    another suspend already in progress?
  2. The Solution:
    The error in 'Going Atomic' is probably because you need to increase the
    allowance we make for drivers allocating memory during the atomic copy.
    Assuming you're using the hibernate script, this is done by editing
    /etc/hibernate/suspend2.conf. If you cat /sys/power/tuxonice/debug_info
    after an attempt at hibernating, the last line will say something like:

    - Extra pages: 1069/500.

    This means that 1069 pages were needed, but we only allowed for 500. In
    that case, you'd want to add something along the lines of

    ProcSetting extra_pages_allowance 2000

    to /etc/hibernate/suspend2.conf.

    (courtesy from http://lists.tuxonice.net/pipermail/tuxonice-users/2008-February/000202.html)

Wednesday, October 08, 2008

VIM tricks and tips

Efficient Editing With vim

Use Vim Like A Pro


Two important concepts in
vi:

marks and registers.

marks: start with ` and '
ma        set mark '''a''' at current cursor location
'a jump to line of mark a (beginning of line)
`a jump to position of mark a
d'a delete from current line to line of mark a
d`a delete from current cursor position to position of mark a
c'a change text from current line to line of mark a
y`a yank text to unnamed buffer from cursor to position of mark a
'' jump back (to line where jumped from)
`0 jump to position in last file edited (when exited Vim)
`` jump back (to position where jumped from)
:marks list all the current marks

registers start with ", use "* register to communicate with system clipboards.
There are nine types of registers:
1. The unnamed register ""
2. 10 numbered registers "0 to "9
3. The small delete register "-
4. 26 named registers "a to "z or "A to "Z
5. four read-only registers ":, "., "% and "#
6. the expression register "=
7. The selection and drop registers "*, "+ and "~
8. The black hole register "_
9. Last search pattern register "/

ATTENTION: 26 named registers, upper case is used to append contents, not different registers.

registers manual

fast notes for registers:

When you copy and cut stuff, it gets saved to registers. You can pull stuff from those registers at a later time.

 :reg     - show named registers and what's in them
"5p - paste what's in register "5

You can also record a whole series of edits to a register, and then apply them over and over.

 qk       - records edits into register k
(q again to stop recording)
@k - execute recorded edits (macro)
@@ - repeat last one
5@@ - repeat 5 times

"kp - print macro k
(e.g., to edit or add to .vimrc)
"kd - replace register k with what cursor is on

Tips And Tricks

The * and # Keys

In normal mode you can use * and # to search for the word under the cursor. * search forwards, # backwards.

The . Key

Also useful is the . key. In normal mode it repeats the last change. Very useful for XML editing and where you have to do similar stuff.

The % Key

Pressing the % key in normal mode while being on a parenthesis or a similar construct jumps to the opposite parenthesis. There are a couple of plugins that extend that functionallity but the default behavior is usually good enough for most of the programming languages.

The <> Keys

When working with Python you often have to indent or outdent a couple of lines. Just mark them using the visual mode and press > to indent them. press 4< to outdent them 4 steps etc.

Advanced Undo Features

Vim has a different system of undoing changes. The normal undo is u in normal mode and ^r is redo. But what happens if you undo a few things and then change something? A normal editor forgets about the new changes. It's not possible to redo that again.

In Vim it's different. Vim starts a new undo branch. Using :undolist you can have a look at the possible undo states. With :earlier 20s / 1m / 2h you can then go back 20 seconds, one minute etc. Traveling forward in time works using :later and a timedelta as argument.

The Search Feature

I really like the firefox search feature. Just hit "/" and you can search in the current file and get the results in real time. That works with vim exactly the same. All you have to to is to either add :set incsearch into your vimrc or type it into the command prompt. Using n you can go to the next result. If you want to have all the search results highlighted use :set hlsearch. Hiding the results works using :nohl

Closing XML Tags

If you have the closetag.vim plugin installed (link above) you can add this to your vimrc in order to get the feature working: autocmd FileType html,xhtml,xml source ~/.vim/scripts/closetag.vim (update the path to your installation and your filetypes of course) Once this is done you can close open tags using ^_.

Regexp Replacement after Search

If you searched for a text using /foo and you now want to replace the found results with something you don't have to write this regexp again. Just do :%s///replacement/g and is automatically replaced with the last search regular expression.

Using Bookmarks

Bookmarking in vim is darn easy. If you are on the current line just bookmark it with mX where X is a lowercase letter from a to z. Go to that mark using 'X where X is the same letter again. Using '' you can jump back to the position you were before jumping to the bookmark. You can get the list of bookmarks using :marks.

The Vim File Browser

The Vim File browser is a nice thing. If you open a file using :e and that file is a directory you get a nice file browser for the files in that directory. If you are a python developer you probably want to filter some files out (*.pyc etc). Add this to your vimrc: let g:explHideFiles='^\.,.*\.pyc$' This hides pyc files as well as hidden files.

The Wildmenu

The best vim feature is the wildmenu. Add a set wildmenu to your vimrc and discover the possibilities of filesystem surfing ^^ Enter :e in the command line and press ^D. Vim will show you all possibitilites in a nice little window. By entering the start of a filename and pressing tab it completes for you then. If it was a folder you can now press ^D again to get the contents. Once you finished the command this window will disappear again and you can continue working. Works of course for all commands not only the open command.

Vim Completion Features

Last tip but maybe the most powerful one :). If you have vim7 and omni completion for your language you can use ^X^O to get the completion similar to intelli sense or how it's called. Note that the default color (pink) can be overridden in the theme. In my fruity.vim file i use this to get white letters on a dark red background: hi Pmenu guifg=#ffffff guibg=#cb2f27

Also nice is ^N. It looks up all used words in the open buffers and presents then in a dropdown completion. Useful if you have long variable names and don't remember them. Just type in the start of the variable name and press ^N. Vim will either complete it or show the list of possibilities.

Thursday, February 14, 2008

罗大佑 -- 告别的年代









告别的年代----罗大佑

风轻轻的吹,
夜沉沉的醉.
谁又在午夜的远处里想念着你,
远处的午夜的梦里相偎依
仰望着蓝色的天边的回忆,
好像你无声的临别的迟疑.
每一次手牵着手像在守护着你,
守护着仅剩的潇洒和犹豫.
每一次凝视的眼神的凝聚,
羽化成无奈的离愁的点滴.

道一声别离,
忍不住想要轻轻地抱一抱你.
从今后姑娘我将在梦里早晚也想一想你.
告别的年代,
分开的理由,
终不须诉说出口.
亲爱的让我快见你一面,
请你呀点一点头.

黄色的蓝色的白色的无色的你,
阳光里闪耀的色彩真美丽.
有声的无声的脸孔的转移,
有朝将反射出重逢的奇迹.
风轻轻的吹,
夜悄悄的睡.
夜沉沉的醉.



appendix:
Embedding Windows Media Player WMA

Tuesday, February 12, 2008

pdflatex and pdfpages are your friends

when you wanna insert multi-page external pdf files to the current latex file or merge several multi-page pdf files into one single pdf file.

Refrash filename database

teTeX
Run:
texhash
web2c
On a current web2c distribution, texhash ought to work; if it doesn't, run mktexlsr
fpTeX
Click Start-> Programs-> Texlive-> Maintenance-> Rebuild ls-R filenames databases, or open a "command" window and run texhash
MikTeX
On a MikTeX distribution earlier than v2.0, click Start-> Programs-> MikTeX-> Maintenance-> Refresh filename database

or get a DOS window and run:
initexmf --update-fndb

On a MikTeX distribution v2.0 or later, do:
Start-> Programs-> MikTeX 2-> MikTeX Options, and press the Refresh now button (Update filename database in earlier versions of MikTeX).

Friday, February 08, 2008

宾克斯的酒 -- 热情海贼版本

尾田大神One Piece第488话, 宾克斯的酒, 热情海贼汉化,演绎版本按照沧海一声笑填词,挺好.

====[[[[宾克斯的酒]]]]====


演绎版本

哟霍霍霍霍 哟霍霍霍霍

送你杯,宾克斯的酒
迎风破浪任我遨游
夕阳好,汹涌浪潮
歌声豪壮气势如涛

离港口,莫回呀头
纵歌一曲不念乡愁
波光粼粼,男儿之道
扁舟驶向,天涯海角

啦...啦...

送你杯,宾克斯的酒
大海上我独领风骚
立舰桥,发长啸
骷髅旗帜分外妖娆

雷电怒,风雨急
巨浪起舞啊我吹笛
好男儿,艰险不避
明日自然云开雨霁

哟霍霍霍霍 哟霍霍霍霍

送你杯,宾克斯的酒
昨夜今宵梦里寻不到
岸上的人儿,越来越小
纵然永别你莫懊恼


送你杯,宾克斯的酒
放声高歌乐陶陶
人生苦短,福祸难料
更要在今宵畅饮欢笑

直译版本

哟霍霍霍 哟霍霍霍 X4

我给你送去,宾客斯的酒
海风,自由自在,随波逐流
海潮的对面,夕阳夺目
鸟在空中回翔歌唱

再见了港口,纺织品之乡
大着嗓门唱起,出航的歌曲
金银色波光粼粼,化作了飞沫
我们向前行,直到海角

- -

我给你送去,宾客斯的酒
我们海贼,纵横大海
浪做枕头,船做睡袋
帆就是旗帜,骷髅当球踢

暴风雨来了,海荒千里
波浪在跳舞,我们也敲鼓
谁要是胆怯了就完蛋了
又不是说看不见明天的太阳了

哟霍霍霍,哟霍霍霍 x4

我给你送去,宾客斯的酒
梦里是今天还是明天
和挥手的那个人影,已经不能再会
别那么烦恼,明天会有明月

我给你送去,宾客斯的酒
大着嗓门唱起,大海的歌曲
反正不管是谁,早晚也是白骨一堆
没有尽头,没有目标,笑话而已

Tuesday, January 29, 2008

无法规避, 巨大的孤寂.

我一个人.我一个人.我一个人.

树欲静而风不止,子欲养而亲不待.

Saturday, January 12, 2008

Everything on Solaris 10 with a user account

If getting used to GNU/Linux, using pure unix is suffering. To make things worse, I only have a regular user acount. Hands are really tight. Not until now do I appreciate GNU tools, very smart and powerful.


1. make pdflatex.fmt
pdftex -ini -fmt=pdflatex.fmt latex.ltx


2. install AucTeX for emacs
./configure --prefix=/home/cps536-n1.07/elisp # install package
--with-lispdir=/home/cps536-n1.07/elisp # install auctex.el
--with-texmf-dir=/home/cps536-n1.07/texmf-local/ # put config in texmf

make; make install


note: if pdflatex is not working, to compile auctex, just open $auctex-install-dir/preview/latex/Makefile.in, and delete lines that test pdflatex.

3. make TAGS of linux kernel with i386 platform, under emacs
cd $Linux-kernel-dir;
find include/linux/ fs/ init/ ipc/ kernel/ lib/ mm/ net/ arch/i386/ -type f -iregex .*\.[csh] -exec etags -a '{}' -o kernel-TAGS \;
Useful hot keys:
M-. tag
Find first definition of tag (find-tag).
C-u M-.
Find next alternate definition of last tag specified.
C-u - M-.
Go back to previous tag found.
C-M-. pattern
Find a tag whose name matches pattern (find-tag-regexp).
C-u C-M-.
Find the next tag whose name matches the last pattern used.
C-x 4 . tag
Find first definition of tag, but display it in another window
(find-tag-other-window).
C-x 5 . tag
Find first definition of tag, and create a new frame to select the
buffer (find-tag-other-frame).
M-*
Pop back to where you previously invoked M-. and friends.
4. The purpose of __init:

__init tells GCC to put the function in a special section. These functions are
only used during booting, and are removed from memory after boot (see the
"Freeing unused kernel memory: 200k freed" or similar boot message.

5. Funny. If adding "exec bash" in .cshrc, I cannot login to OpenWindows, while change it to "bash", everything is OK. Still wonder when it executes .cshrc.

6. read entire file using c:
  fseek(input, 0L, SEEK_END);  /* Position to end of file */
lFileLen = ftell(input); /* Get file length */
rewind(input); /* Back to start of file */
fread(str, lFileLen, 1, input);


Saturday, December 29, 2007

2007 Xristmas in Dallas, TX

早就想着要去Dallas看阿燕, Thanksgiving忙的要死, 抽不出空, 就定在了Xristmas. 12.24-12.28的飞机. 玩得很开心啊, 现在顺利回来了, 小记一下.

24号中午的飞机, 本来应该2:20到, 结果飞机晚点半小时, 等行李又用了20多分钟, 出来后去租车, 由于是第一次, 手续烦琐, 耽误很久, 提了车, 按照GPS直奔阿燕家. 高速路上大货车换道跟玩似的, 更不用说其他的小车了, 坐在这辆陌生的新车上, 连左右后视镜都忘了调, 惊出好几身冷汗. 大概到5点钟才到, 不过是开到了邻居家, 下车让阿燕出来才找到的, 呵呵, 眼神不好. 看到阿燕清秀依旧, 立马想到以前我写在她毕业册上的话: "清水出芙蓉, 天然去雕饰", 还是非常非常的合适.

24,25号这两天是节日, 每个学校的中国学生们都会聚聚, 我就在他们那蹭饭, 享受大厨厨艺, 改善伙食, 认识那边的同学, 都是很有趣的人. 刚到阿燕家跟她聊天的时候, 说到从ohio过去, 好几次都把"坐"飞机说成了"开"飞机, 舌头停不下来, 糊涂的紧, 笑死了. 24号晚上还组织了一下"杀人", 偷懒当法官,几轮下来, 把他们的名字都记住了. 25号晚上接着跟去他们教授家包饺子, 胖胖的老头, 挺可爱的. 饭桌上听他们聊天, 确实内容和咱理工科不同, 聊政治,文化,法律,历史一套一套的, 其中还夹杂着笑话和调侃, 没冷过场, 这教授真神气啊.

26,27没有饭局了, free time. 刚好她们假期在家也都闷的慌, 就和她们出去转转, 去之前老板曾推荐San Antonio, 阿燕教授也推荐过, 可惜时间紧, 就打算往南开, 只去Autin和San Antonio, 如果再去Houston时间太紧, 就下次吧. 25号晚上规划好行程, 从网上预定了在San Antonio市区附近的旅馆, 记下第二天景点的地址并输入GPS, 26号早上动身.

从Dallas沿着高速往Austin开, 出了城市的立交桥后就是一片开阔地带, 路边几乎没有建筑, 高速偶有起伏, 绵延的车龙之外再无其他. 有些出口出去后什么都没有, 只有一片杂草地和稀稀拉拉的一些树, 真荒啊, 地广人稀用在这更适合. 想起听她们教授说Texas早年是罪犯们逃避法律制裁才会去的地方, 就跟澳大利亚差不多, 总算有些感受了. 1点左右抵达Austin, 这个城市的评价很好, The best small city in the States, 但首先的感觉是, 没有人. 街道空荡荡的. 先去州政府, Texas State Capitol参观, 造的跟Washington DC的Capitol Hill差不多, 圆顶, 顶上有个小雕像. 不过这个Capitol里面都是大星星, 听说是Texas的象征. 还听一个很干净的圆脸小胖子双手插裤带里介绍这个capitol的历史及现状, 讲的飞快, 嘚蹦嘚蹦, 讲好久都不换气的, 估计杨鹏难句对他就是小儿科了. 有点意思的是, 这个capitol里面1-4层的墙上挂着历届governor的画像, 最近的一个是小布什, 现任的州长等离任后会有个画像挂在最后, 然后其他的画像往前移一位, 一楼满了挂到二楼去, 一直到4楼, 这个过程需要4天的时间. 目前还有7个空位, 等7个空位都用完了, "We don't know what's gonna happen. "


Texas State Capitol 外景


穹顶内部


小胖子讲解员

逛完Capitol, 接着去了一下UT at Austin, 很近, 只有几个街区, 不过相比capitol的喧闹, 那边就没有人了, 一条单行道有4车道, 但只有2辆车和一个老太太在路边等公交. 美国和中国在过年的时候很不同, 国内过年总是很热闹, 什么烟花晚会, 彩灯, 街上总是张灯结彩, 但这一到过年路上连个鬼都没有, 每个人都回家自己爽, 没有家的人就自己洗洗睡了, 或者搞出点动静免得太冷清. 当然也有很热闹的节日, 比如Halloween, 但感觉不一样的吧. 在UT at Austin只是逛了下钟楼, 事先调查不够.


钟楼前合影, 到此一游的证明.


这是George Washington的铜像, 就在钟楼正前方, 面向State Capitol. 这仨应该在一条中轴线上. 估计跟Wahsington DC学的, 那里Lincoln Memorial, Washington Monument以及Capitol Hill是在一条中轴线上.

离开Austin开往San Antonio, 晚上6点左右到达, check-in Days Inn, 就去downtown看夜景, 感受传说中的Riverwalk. 过去一看, downtown真小啊, 地图上的景观就集中在一点点地方, 古战场Alamo, Riverwalk, Tower of Americas等都扎堆. 夜景很漂亮, 很多彩灯, 还带闪的, 呵呵. 所谓的Riverwalk就是有条河通过市中心, 在水边走走, 晚上的时候其实就是听水声和看水边的灯饰了, 白天看那河水就挺脏, 完全没感觉. 到了第二天早上我们又去downtown逛了一圈, 两下一比较, 很多晚上看不到的东西白天就很清楚, 而很多晚上很赞的彩灯到了日光下就非常普通非常土, 赚了呀. 白天进古战场Alamo转了一圈, 上Tower of Americas俯瞰这个城市, 最后去了San Antonio zoo玩了一下. 关于动物园, 我在国内都没印象有没有去过, 但第一次看大熊猫是在美国, 是去年在Washington DC的动物园看的, 挺怪的感觉, 而且那时候那一对大熊猫还生了个小熊猫, 特调皮, 一个大妈管理员唠唠叨叨的跟我们讲他们的事情, 真是喜欢的不得了, 估计能讲一星期. 如果只考虑个体, 好像自己的生活挺特别的, 但如果放眼众生, 这点经历就完全没什么特殊的, 只是井底之蛙的些许碎念罢了.


San Antonio夜景, 后面的建筑不知道是啥.


San Antonio夜景, 后面的塔是Tower of Americas.


在Tower of Americas上俯瞰.


在Tower of Americas所在的Hemisphere Park拍的风景, 都可以当桌面了, 处理了一下色调, 随便弄的, 有高手在的话指教一下.


动物园里的American bald eagle, 刚好转过头来让我拍了个正着, 再小小处理了一下, 呵呵.

27号晚上8点回的家, 挺顺利的. 28号早上在抓紧时间参观了一下SMU, 吃到阿燕做的菜了, 很不错. 中午坐飞机回了ohio. 假期结束.

总体来说, 玩得挺开心, 就是时间太短, 买机票的时候根本没想过去哪玩, 只是到了之后一个晚上定的行程, 两天不太够, 下次要早规划. 自己开车很省钱, GPS帮了大忙, 否则我们就死在那了. 由于时间短, 本来打算去tamu看shanhaier改善伙食, 没去成, 太可惜了. 下次吧. 不过见到了阿燕和她的同学们, 看他们过的都挺好, 身体健康, 精神生活也挺充实, 教授很照顾, 嗯, 很好很强大.

2008年就要到了. Happy New Year! 新的一年会有新的气象的. 一切都会好的.

Saturday, November 03, 2007

GRE CS SUB @ Univ. of Cincinnati, Nov 3, 2007

先说一下行程, 考试日期是周六, 上个周日拉着师兄和vicky去了一趟华欣,Cincinnati的中国超市, 算是练练车, 跑跑I-75S. 周二在UD论坛上发帖看看谁在那边有没有同学可以借宿一晚, no luck. 周四在google maps上找了几个motel, 打了一个电话, 说没有reservation, 到时候会有房间的, 就不接着预约了. 然后在google maps上找路, 打印相关UC附近的地图, 定位motel, 确定路径. 周五下午meeting完了后回家收拾东西, 解决了车子remote不好使的问题, 直接废掉alarm, 只用钥匙. 4点半左右上高速了.

高速上一切顺利, 开了大概有一个多小时吧, exit 14至exit 6还堵车, 等了好一会, 终于出去了, 结果一出高速就转错弯, 与既定路径相反, 开了一会看不对了, 幸好看到了一条返程时要走的路, 对照地图, 七转八转终于方向走对了, 也知道怎么走了. 那一片区域路绕来绕去, 而且很多上坡下坡, 大弯一个接一个, 开的心惊胆战的. 这时想起GPS的好来了, 地图上看路径是清清楚楚, 但实际开的时候根本看不清, 如果看清了该转了, 已经被逼在直行道上. 如果带了老戴的GPS应该好很多, 不过目前我还不太会用, 下次吧. 这样经过UC, 开往地图上找的几个motels的位置, 上陡坡, 转大弯, 下陡坡, 到了一个大路口, 四五个方向分的很远, 而且不是直来直去, 没有路牌, 完全晕了, 往前吧, 不认识路了, 往回开, 按照记忆转了个弯, 突然发现前面是一个motel candidate, Rest Inn, 误打误撞找到了, 哈哈. 原来我来的路跟这条路只有30度左右, 实在是大弯. Rest Inn就是两层的房子, 方方正正, 一个一个房间整齐的排列着. check in, 65刀, king-size bed. 其实应该选queen size或更小的, 不过当时没意识到, 那个老板娘就直接定了, 懒得换了. 放好包, 确认了一下去UC的路, 就动身探考场.

UC是在山上, 跟这一片的地形相符. 路上感觉Cincinnati的车好多, 而且路边都停满了车. 路边有计时码表, 靠边, 上山了. UC比UD大气, 建筑分的很开, 中间是大片的绿色和纪念标志什么的, 应该设计过. 一幢幢楼都挺有特色, 有的现代一些,灰色砖瓦加玻璃墙, 有的古典一些. 土黄色方方正正门牌类. 我看的是west campus吧, 感觉就比UD大一点, 中心还有一个橄榄球场, 挺像模像样的. 在路上走一会就看到好几个中国人, 出现频率高多了. 考场在Braunstei Hall RM 300, 一个阶梯教室. 看完天都黑了, 回去吃饭休息.

晚上想看看资料, 打开包竟然找不到笔记本, shit! 带了电源没有带笔记本! 真是糊涂到家了. 只能把practice book里的例卷做了, 70道选择题, 累死了, 明天还要考2小时50分钟, 体力活.

这里讲讲准备情况, 补看了几本书, Hardware, Computing theory, Algorithms, 还看的不全, 没有系统准备过, 例题只做了一小部分. 做了practice book后发现, 题目不是很难,但涵盖的知识点很广, 而且一个不小心就错了. 基本上是做的时候还挺开心的, 一对答案就完了. 就这样打发了大半个晚上, 再浏览了一下算法导论中的图论, 看了一会电视, 大概12点半熄灯, 到了1点多才睡着, 可能床太生. 早上醒过几次, 6点起, 外面还是黑的, 大清早挺冷的, 但已经有人在走动了, 真行. 准备去吃早饭, 结果发现Big Boy 7点钟才开门, 背啊, 回房捱到时间, 吃饭, check out, 出发, 找到加油站的一个停车位, 走到考点, 考试, 考完开车回家, 总算还顺利.

尽人事, 信天命. Move on.

Noting mysterious if the manual is provided.

9月份买了一辆二手车, 1997 Chrysler Concorde LX, full size. 刚到手就老老实实把manual看了两遍, 受益颇多. 这车还有个alarm system, 配了一个remote, 刚开的时候好像那个alarm system没开起来, 用remote 的时候只是开一下车门. 也没有像其他车一样会闪个灯叫一声, 没怎么管. 然后突然有一天带同学回家的时候左脚在仪表板下踢了一脚, 就能叫能闪灯了, 呵呵,当时以为运气好, 没有细察.

这样持续了一个月, 这个remote出问题了, 常常不工作, 按呐按呐就是不亮, 如果不用remote开门, alarm system会警报大作, 而且没法启动, 实在讨厌, 而且还误了几次事. 实在受不了了, 就在网上查有没有什么相关的资料, 同时在随车文件里翻出了这个alarm system的manual, 一切都清楚了. 原来在仪表板下面有个按钮, 可以控制alarm system的启用和禁用, 禁用是处于valet mode. 当时就是踢到了这个按钮所以alarm system就启动了, 会叫了, 要转换必须处于点火或发动机启动状态下. 如果remote不行, 可以用钥匙开门, 不管alarm, 插入钥匙, 转到ignition, 再按一下那个按钮, alarm就停了, 车子就能正常启动了. 可怜我以前还常常围着车子转, 拼命按remote, 完全拼rp. 有了manual, nothing mysterious.

由于是老车, 这个alarm system已经是aftermarket product. 对于在市面上流通的alarm system, 如果remote废了, 只要将钥匙插入车门钥匙孔, 先向左转, 再向右转, alarm就解除了. 这是在网上看到的, 一切以实效为准.

Manuals make life easier. Does our life come with a manual?

Saturday, August 11, 2007

被美可点名,小玩一下

规则系:
1.被点到名字的要在自己的博客里写下自己的答案,然后加上一个你的问题,传给其他8个人,列出其他8个需要回答问题的人的名字,还要到这8个人的博客里留言通知对方——你被点名了,完成游戏的人将会永远得到大家的祝福。
2.这8个人要在自己的博客里注明是从哪里接到的,并且再传给其他8个人,让游戏继续下去,表回传。被点到名字的人将会得到大家的祝福,并且所有美好的愿望都会在不久的将来实现。
1. 上一次哭是什么时候…为什么…
大四散伙饭,喝醉了.
2. 爱上你爱的人那一刻是什么样子的呢? (暗恋也算,暗恋也算哦:)
好像不是很突然的事情,所以不知道.
3. 你认为分手后的男女朋友还能做普通朋友吗?
看人了. 我可以.
4. 你觉得自己会遇到一个爱你并你爱他的人
会的
5. 你怎么知道自己喜欢一个人?
1. 不讨厌. 2. 有喜欢的感觉
6.你现在最想做什么职业?
计算机软硬件相关工程师.
7. 你现阶段最大的愿望是什么?
家人过的好.
8. 你最希望从朋友(不包括爱人)那里得到的是什么?
信任.
9. 你最想去哪个地方?为什么?
回国. 有好东西吃.
10. 最受不了自己的哪个缺点?
记忆力差, 经常记错东西,说错话.
11. 最喜欢自己哪个优点?
走自己的路.
12. 最近最快乐的事情是什么?
知道这一学年要干什么了.
13. 你记得父母的生日?
记得,不知道有没有记错.
14. 当你的感情被异性拒绝时,你会怎么处理与他或她的关系,是保持普通朋友关系还是断绝关系
保持朋友关系.
15. 遇到喜欢的人,你是勇敢表白还是默默关注?
现在应该敢于表白了.
16. 最想要的人生是咋样的?
坚强,勇敢,自信.
17.有没有想过这辈子如果找不到另一半该哪能办呢?
怎么可能找不到.
18.怎样才能确定你爱的人爱你呢?
交流,一起生活,肯定能感觉到的.
19.大家觉得现在的生活状态满意吗?如果不满意,会怎样改变呢?
不满, 要努力做事.
20.如果你发现自己是个gay(或者lala)你怎么办?
至今没发现, 到时候再说了.
21.你不喜欢的人一天到晚追着你,但你又想和他保持朋友关系,你会怎么办?
没碰到过,先谈,然后因人而异.
22.如果周围的朋友突然都不认识你了,你会怎么办?
再认识一次呗.
23.大家什么时候结婚哪?
找到老婆后.
24.当你发现你深爱的人开始不爱你了,怎么办?
找原因,需要的话改变自己,实在不开心就算了.
25.当你失去现在所拥有的一切时,你会怎么办?(失去一切哦...看清楚了)
先去找吃的和穿的.
26.你觉得在爱情中两个人是不是应该一比一得爱呢?
不是,问心无愧就行,不用太计较.
27.你会以怎样的方式去爱一个人?
我的方式.
28.手机铃声响起的时候最期待是来自什么人?
任何人.
29.你会以什么心态去改变自己的性格?
积极的心态.
30. 现在! 给你一次发泄的机会,你想说什么?
Wholly shit.
31 yy的问题:你最崇拜的人是谁?为什么?
没有最崇拜的.
32 请说出我的回答给你的印象和平时我给人的印象有没有区别?有的话请详细说明。
平时没什么印象,无法比较.
33 我的问题:要不就不要把这个题目流传下去了吧,好不好?
这个我同意,就到此为止吧.

Sunday, August 05, 2007

It is time to change.

2007已过半,就要进入master第二年,又要开始选择以后的去向了. 不过这次总算有些自主权了,干吧. 嘿嘿, 总有办法的,一切都会好起来的.

1. 实验有些眉目了, 下半年至少要去个conference.
2. 11月之前买车,驾照考掉,否则以后很麻烦.
3. 11/03, GRE CS SUB@U Cincinnati, GET IT ROLLING!
4. 申请CS.
5. 明年上半年准备找工作, 申请工作都不行就先OPT.

不由想起袁崇焕评传里的广东三字经,"X他妈,顶硬上,几大就几大!"

Saturday, December 30, 2006

Time is chasing us, 2007 Eve now.回顾&展望

回顾2006, 展望2007.

回顾:
1. 家人身体健康,外婆今年逃过一劫,去老佛那走了一圈幸好回来了,身体在好转,可惜我不在身边,佛祖继续保佑。爸爸妈妈依然很忙,酒厂的事,我们的事... 06年我和毛毛毕业,毛毛高考,我张罗出国,让父母更操心了,还好最后结果不错。毛毛上了大学,以后的路就看他自己了。杨柳大四了,找到了实习单位,但由于课程原因还是有些不顺,还有那头疼的英语三级,可惜我帮不上什么忙,bless~。

2. 我的兄弟们,大学的,高中的,以前的,基本都是今年毕业。读研,工作,出国,公务员,继续在学校混,大学毕业让我们经历了很多。大四的时光,腐败,K歌,散伙饭,然后各奔东西,继续在QQ群上联系,科大四人帮的三河DV,璞子哥的羊肉(只有流口水的份)。哦,还有06世界杯,在达达那赌球,一次都没赢过,背啊。凌晨3点的沙县,牛肉面。想死我了。还有一些兄弟没着落,为你们祈祷了。梁,一切都会好的。

3. 06年,经历了一系列的等待和失落,最后接受了Dayton的offer,在这过程中结识了一群光电飞友,OOS成员众多,活动频繁,成绩斐然。加上88 Oversea版的版友们,朋友满天下。签证、行李事毕,8月飞向陌生的国度,新朋友,新生活,算来已是四个多月了,第一个学期忙于作业,常常跟同来的一帮中国学生玩,老板不push,搞的我很愧疚,干活不力。对以后还是很迷茫。但目前生活能自立了,不用花父母的钱,挺好的。

4. 出国前去了趟北京,逛了一圈清华北大故宫圆明园,见了我哥,我嫂和小侄女,跟清华北大的同学吃饭,又去方丹敏老师工作的地方,蹭了一顿饭,哈哈。然后跟泮在未名湖走了一圈,依然single的回来了。在清华都是蔡刚接待,希望蔡刚在青海一切都好。

2007 best wishes:
1. 家人身体安康,外婆身体越来越好,杨柳顺利找到满意工作,毛毛能确定自己目标并向之努力,爸爸妈妈身体健康,不用这么操劳。
2. 兄弟们工作生活依然顺利,没着落的能尽早搞定,都有mm,都能给我发pic。
3. 认识的mm们,虽然很多都不知道近况,也希望能一切顺利,


2007 must-do:
努力干活,发paper,确定以后的方向,攒钱。

2007 bonus:
mm

Sunday, November 19, 2006

vsftpd用户权限设置

今天配置vsftp实现三个用户的不同权限:
a.upload用户,可以上传下载,可以新建文件夹,但不能删除文件和文件夹,不能重命名原有文件和文件夹;
b.download用户,只能下载;
c.admin用户 ,管理员,可以上传,可以下载,可以新建文件夹,可以删除和更改文件和文件夹名。

配置文件

download内容 :
anon_world_readable_only=NO

upload内容:
anon_world_readable_only=NO
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES

admin内容:
anon_world_readable_only=NO
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES (使可以续传上传的文件)

vsftpd上传文件权限设置
除本地用户外的其他用户属性配置函数
anon_umask=022 (最后的权限是rwxrwxrwx-022=rwxr-xr-x)


5、VSFTPD的设置选项

  VSFTPD的配置文件/etc/vsftpd/vsftpd.conf是个文本文件。以“#”字符开始的行是注释行。每个选项设置为一行,格式为“option=value”,注意“=”号两边不能留空白符。除了这个主配置文件外,还可以给特定用户设定个人配置文件,具体介绍见后。
  VSFTPD包中所带的vsftpd.conf文件配置比较简单,而且非常偏执狂的(文档自称:-))。我们可以根据实际情况对其进行一些设置,以使得VSFTPD更加可用。

5.1、连接选项

  本部分主要是一些与建立FTP链接相关的选项。

5.1.1、监听地址与控制端口

  listen_address=ip address
  此参数在VSFTPD使用单独(standalone)模式下有效。此参数定义了在主机的哪个IP地址上监听FTP请求,即在哪个IP地址上提供FTP服务。对于只有一个IP地址的主机,不需要使用此参数。对于多址主机,不设置此参数,则监听所有IP地址。默认值为无。

  listen_port=port_value
  指定FTP服务器监听的端口号(控制端口),默认值为21。此选项在standalone模式下生效。

5.1.2、FTP模式与数据端口

  FTP 分为两类,PORT FTP和PASV FTP,PORT FTP是一般形式的FTP。这两种FTP在建立控制连接时操作是一样的,都是由客户端首先和FTP服务器的控制端口(默认值为21)建立控制链接,并通过此链接进行传输操作指令。它们的区别在于使用数据传输端口(ftp-data)的方式。PORT FTP由FTP服务器指定数据传输所使用的端口,默认值为20。PASV FTP由FTP客户端决定数据传输的端口。PASV FTP这种做法,主要是考虑到存在防火墙的环境下,由客户端与服务器进行沟通(客户端向服务器发出数据传输请求中包含了数据传输端口),决定两者之间的数据传输端口更为方便一些。

  port_enable=YES|NO
  如果你要在数据连接时取消PORT模式时,设此选项为NO。默认值为YES。

  connetc_from_port_20=YES|NO
  控制以PORT模式进行数据传输时是否使用20端口(ftp-data)。YES使用,NO不使用。默认值为NO,但RHL自带的vsftpd.conf文件中此参数设为YES。

  ftp_data_port=port number
  设定ftp数据传输端口(ftp-data)值。默认值为20。此参数用于PORT FTP模式。

  port_promiscuous=YES|NO
  默认值为NO。为YES时,取消PORT安全检查。该检查确保外出的数据只能连接到客户端上。小心打开此选项。

  pasv_enable=YES|NO
  YES,允许数据传输时使用PASV模式。NO,不允许使用PASV模式。默认值为YES。

  pasv_min_port=port number
  pasv_max_port=port number
  设定在PASV模式下,建立数据传输所可以使用port范围的下界和上界,0 表示任意。默认值为0。把端口范围设在比较高的一段范围内,比如50000-60000,将有助于安全性的提高。

  pasv_promiscuous=YES|NO
  此选项激活时,将关闭PASV模式的安全检查。该检查确保数据连接和控制连接是来自同一个IP地址。小心打开此选项。此选项唯一合理的用法是存在于由安全隧道方案构成的组织中。默认值为NO。

  pasv_address=
  此选项为一个数字IP地址,作为PASV命令的响应。默认值为none,即地址是从呼入的连接套接字(incoming connectd socket)中获取。

5.1.3 ASCII模式

  默认情况下,VSFTPD是禁止使用ASCII传输模式。即使FTP客户端使用asc命令,指明要使用ASCII模式,但是,VSFTPD表面上接受了asc命令,而在实际传输文件时,还是使用二进制方式。下面选项控制VSFTPD是否使用ASCII传输模式。

  ascii_upload_enable=YES|NO
  控制是否允许使用ascii模式上传文件,YES允许,NO不允许,默认为NO。

  ascii_download_enable=YES|NO
  控制是否允许使用ascii模式下载文件,YES允许,NO不允许,默认为NO。

5.2、性能与负载控制

5.2.1、超时选项

  idle_session_timeout=
  空闲(发呆)用户会话的超时时间,若是超出这时间没有数据的传送或是指令的输入,则会强迫断线。单位为秒,默认值为300。

  data_connection_timeout=
  空闲的数据连接的超时时间。默认值为300 秒。

  accept_timeout=numerical value
  接受建立联机的超时设定,单位为秒。默认值为60。

  connect_timeout=numerical value
  响应PORT方式的数据联机的超时设定,单位为秒。默认值为60。以上两个选项针对客户端的,将使客户端空闲1分钟后自动中断连接,并在中断1分钟后自动激活连接。

5.2.2 负载控制

  max_clients=numerical value
  此参数在VSFTPD使用单独(standalone)模式下有效。此参数定义了FTP服务器最大的并发连接数,当超过此连接数时,服务器拒绝客户端连接。默认值为0,表示不限最大连接数。

  max_per_ip=numerical value
  此参数在VSFTPD使用单独(standalone)模式下有效。此参数定义每个IP地址最大的并发连接数目。超过这个数目将会拒绝连接。此选项的设置将影响到象网际快车这类的多进程下载软件。默认值为0,表示不限制。

  anon_max_rate=value
  设定匿名用户的最大数据传输速度value,以Bytes/s为单位。默认无。

  local_max_rate=value
  设定用户的最大数据传输速度value,以Bytes/s为单位。默认无。此选项对所有的用户都生效。此外,也可以在用户个人配置文件中使用此选项,以指定特定用户可获得的最大数据传输速率。
  步骤如下:
  ①在vsftpd.conf中指定用户个人配置文件所在的目录,如:
  user_config_dir=/etc/vsftpd/userconf
  ②生成/etc/vsftpd/userconf目录。
  ③用户个人配置文件是在该目录下,与特定用户同名的文件,如:
  /etc/vsftpd/userconf/xiaowang
  ④在用户的个人配置文件中设置local_max_rate参数,如:
  local_max_rate=80000
  以上步骤设定FTP用户xiaowang的最大数据传输速度为80KBytes/s。

  VSFTPD 对于速度控制的变化范围大概在80%到120%之间。比如我们限制最高速度为100KBytes/s, 但实际的速度可能在80KBytes/s 到120KBytes/s 之间。当然,若是线路带宽不足时,速率自然会低于此限制。

5.3 用户选项

  VSFTPD的用户分为三类:匿名用户、本地用户(local user)以及虚拟用户(guest)。

5.3.1、匿名用户

  anonymous_enable=YES|NO
  控制是否允许匿名用户登录,YES允许,NO不允许,默认值为YES。

  ftp_username=
  匿名用户所使用的系统用户名。默认下,此参数在配置文件中不出现,值为ftp。

  no_anon_password=YES|NO
  控制匿名用户登入时是否需要密码,YES不需要,NO需要。默认值为NO。
  
  deny_email_enable=YES|NO
  此参数默认值为NO。当值为YES时,拒绝使用banned_email_file参数指定文件中所列出的e-mail地址进行登录的匿名用户。即,当匿名用户使用banned_email_file文件中所列出的e-mail进行登录时,被拒绝。显然,这对于阻击某些Dos攻击有效。当此参数生效时,需追加banned_email_file参数

  banned_email_file=/etc/vsftpd.banned_emails
  指定包含被拒绝的e-mail地址的文件,默认文件为/etc/vsftpd.banned_emails。

  anon_root=
  设定匿名用户的根目录,即匿名用户登入后,被定位到此目录下。主配置文件中默认无此项,默认值为/var/ftp/。

  anon_world_readable_only=YES|NO
  控制是否只允许匿名用户下载可阅读文档。YES,只允许匿名用户下载可阅读的文件。NO,允许匿名用户浏览整个服务器的文件系统。默认值为YES。

  anon_upload_enable=YES|NO
  控制是否允许匿名用户上传文件,YES允许,NO不允许,默认是不设值,即为NO。除了这个参数外,匿名用户要能上传文件,还需要两个条件:一,write_enable参数为YES;二,在文件系统上,FTP匿名用户对某个目录有写权限。

  anon_mkdir_write_enable=YES|NO
  控制是否允许匿名用户创建新目录,YES允许,NO不允许,默认是不设值,即为NO。当然在文件系统上,FTP匿名用户必需对新目录的上层目录拥有写权限。

  anon_other_write_enable=YES|NO
  控制匿名用户是否拥有除了上传和新建目录之外的其他权限,如删除、更名等。YES拥有,NO不拥有,默认值为NO。

  chown_uploads=YES|NO
  是否修改匿名用户所上传文件的所有权。YES,匿名用户所上传的文件的所有权将改为另外一个不同的用户所有,用户由chown_username参数指定。此选项默认值为NO。

  chown_username=whoever
  指定拥有匿名用户上传文件所有权的用户。此参数与chown_uploads联用。不推荐使用root用户。

5.3.2、本地用户

  在使用FTP服务的用户中,除了匿名用户外,还有一类在FTP服务器所属主机上拥有账号的用户。VSFTPD中称此类用户为本地用户(local users),等同于其他FTP服务器中的real用户。

  local_enable=YES|NO
  控制vsftpd所在的系统的用户是否可以登录vsftpd。默认值为YES。

  local_root=
  定义所有本地用户的根目录。当本地用户登入时,将被更换到此目录下。默认值为无。

  user_config_dir=
  定义用户个人配置文件所在的目录。用户的个人配置文件为该目录下的同名文件。个人配置文件的格式与vsftpd.conf格式相同。例如定义user_config_dir=/etc/vsftpd/userconf,并且主机上有用户xiaowang,lisi,那我们可以在user_config_dir的目录新增名为xiaowang、lisi的两个文件。当用户lisi 登入时,VSFTPD则会读取user_config_dir下lisi这个文件中的设定值,应用于用户lisi。默认值为无。

5.3.3、虚拟用户

  guest_enable=YES|NO
  若是启动这项功能,所有的非匿名登入者都视为guest。默认值为关闭。

  guest_username=
  定义VSFTPD的guest用户在系统中的用户名。默认值为ftp。

5.4、安全措施

5.4.1、用户登录控制

  pam_service_name=vsftpd
  指出VSFTPD进行PAM认证时所使用的PAM配置文件名,默认值是vsftpd,默认PAM配置文件是/etc/pam.d/vsftpd。

  /etc/vsftpd.ftpusers
  VSFTPD禁止列在此文件中的用户登录FTP服务器。这个机制是在/etc/pam.d/vsftpd中默认设置的。

  userlist_enable=YES|NO
  此选项被激活后,VSFTPD将读取userlist_file参数所指定的文件中的用户列表。当列表中的用户登录FTP服务器时,该用户在提示输入密码之前就被禁止了。即该用户名输入后,VSFTPD查到该用户名在列表,VSFTPD就直接禁止掉该用户,不会再进行询问密码等后续步聚。默认值为NO。

  userlist_file=/etc/vsftpd.user_list
  指出userlist_enable选项生效后,被读取的包含用户列表的文件。默认值是/etc/vsftpd.user_list。

  userlist_deny=YES|NO
  决定禁止还是只允许由userlist_file指定文件中的用户登录FTP服务器。此选项在userlist_enable 选项启动后才生效。YES,默认值,禁止文件中的用户登录,同时也不向这些用户发出输入口令的提示。NO,只允许在文件中的用户登录FTP服务器。
  
  tcp_wrappers=YES|NO
  在VSFTPD中使用TCP_Wrappers远程访问控制机制,默认值为YES。

5.4.2、目录访问控制

  chroot_list_enable=YES|NO
  锁定某些用户在自家目录中。即当这些用户登录后,不可以转到系统的其他目录,只能在自家目录(及其子目录)下。具体的用户在chroot_list_file参数所指定的文件中列出。默认值为NO。

  chroot_list_file=/etc/vsftpd/chroot_list
  指出被锁定在自家目录中的用户的列表文件。文件格式为一行一用户。通常该文件是/etc/vsftpd/chroot_list。此选项默认不设置。

  chroot_local_users=YES|NO
  将本地用户锁定在自家目录中。当此项被激活时,chroot_list_enable和chroot_local_users参数的作用将发生变化,chroot_list_file所指定文件中的用户将不被锁定在自家目录。本参数被激活后,可能带来安全上的冲突,特别是当用户拥有上传、shell访问等权限时。因此,只有在确实了解的情况下,才可以打开此参数。默认值为NO。

  passwd_chroot_enable
  当此选项激活时,与chroot_local_user选项配合,chroot()容器的位置可以在每个用户的基础上指定。每个用户的容器来源于/etc/passwd中每个用户的自家目录字段。默认值为NO。

5.4.3、文件操作控制

  hide_ids=YES|NO
  是否隐藏文件的所有者和组信息。YES,当用户使用"ls -al"之类的指令时,在目录列表中所有文件的拥有者和组信息都显示为ftp。默认值为NO。

  ls_recurse_enable=YES|NO
  YES,允许使用"ls -R" 指令。这个选项有一个小的安全风险,因为在一个大型FTP站点的根目录下使用"ls -R"会消耗大量系统资源。默认值为NO。

  write_enable=YES|NO
  控制是否允许使用任何可以修改文件系统的FTP 的指令,比如STOR、DELE、RNFR、RNTO、MKD、RMD、APPE 以及SITE。默认值为NO,不过自带的简单配置文件中打开了该选项。

  secure_chroot_dir=
  这选项指向一个空目录,并且ftp用户对此目录无写权限。当vsftpd不需要访问文件系统时,这个目录将被作为一个安全的容器,用户将被限制在此目录中。默认目录为/usr/share/empty。

5.4.4、新增文件权限设定

  anon_umask=
  匿名用户新增文件的umask 数值。默认值为077。

  file_open_mode=
  上传档案的权限,与chmod 所使用的数值相同。如果希望上传的文件可以执行,设此值为0777。默认值为0666。

  local_umask=
  本地用户新增档案时的umask 数值。默认值为077。不过,其他大多数的FTP服务器都是使用022。如果您的用户希望的话,可以修改为022。在自带的配置文件中此项就设为了022。

5.5、提示信息

  ftpd_banner=login banner string
  此参数定义了login banner string(登录欢迎语字符串)。用户可以自行修改。预设值为无。当ftpd_banner设置后,将取代系统原来的欢迎词。

  banner_file=/directory/vsftpd_banner_file
  此项指定一个文本文件,当使用者登入时,会显示此该文件的内容,通常为欢迎话语或是说明。默认值为无。与ftpd_banner相比,banner_file是文本文件的形式,而ftpd_banner是字串格式。banner_file选项将取代ftpd_banner选项。

  dirmessage_enable=YES|MO
  控制是否启用目录提示信息功能。YES启用,NO不启用,默认值为YES。此功能启用后,当用户进入某一个目录时,会检查该目录下是否有message_file选项所指定的文档,若是有,则会出现此文档的内容,通常这个档案会放置欢迎话语,或是对该目录的说明。

  message_file=
  此选项,仅在dirmessage_enable选项激活方生效。默认值为.message。

5.6、日志设置

  xferlog_enable=YES|NO
  控制是否启用一个日志文件,用于详细记录上传和下载。该日志文件由xferlog_file选项指定。默认值为NO,但简单配置文件中激活此选项。

  xferlog_file=
  这个选项设定记录传输日志的文件名。默认值为/var/log/vsftpd.log。

  xferlog_std_format=YES|NO
  控制日志文件是否使用xferlog的标准格式,如同wu-ftpd一样。使用xferlog格式,可以重新使用已经存在的传输统计生成器。然而,默认的日志格式更为可读性。默认值为NO,但自带的配置文件中激活了此选项。

  log_ftp_protocol=YES|NO
  当此选项激活后,所有的FTP请求和响应都被记录到日志中。提供此选项时,xferlog_std_format不能被激活。这个选项有助于调试。默认值为NO。

5.7、其他设置

  setproctitle_enable=YES|NO
  YES,VSFTPD将在系统进程列表中显示每个会话(session)的状态。也就是说,进程报告将显示每个vsftpd会话在做什么(挂起、下载等),如用ps -ef|grep ftp。出于安全的目的,可以考虑将此选项关闭。NO,进程报告只显示一个vsftpd进程在运行。默认值为NO。

  text_userdb_names=YES|No
  当使用者登入后使用ls -al 之类指令时,目录列表的用户和组信息域,默认是出现拥有者的UID,而不是该档案拥有者的名称。若是希望出现拥有者的名称,则将此功能开启。默认值为NO。

  user_localtime=YES|NO
  默认为NO。YES,VSFTPD显示目录列表时使用你本地时区的时间。默认是显示GMT时间。同样,由ftp命令“MDTM”返回的时间值也受此选项影响。

  check_shell=YES|NO
  此选项仅对不使用PAM方式的VSFTPD生效。当此选项关闭后,当本地用户登录时,VSFTPD不会检查/etc/shells文件以寻找一个有效的用户shell。默认为YES。

  nopriv_user=
  指定一个用户,当VSFTPD不想要什么权限时,使用此用户身份。这用户最好是一个专用的用户,而不是用户nobody。在大多数的机器上,nobody用户被用于大量重要的事情。默认值为nobody。

  pam_service_name=
  指明VSFTPD使用用PAM验证服务时的PAM配置文件名。默认值为ftp。

Thursday, November 09, 2006

screen的特殊功能

以前还真不知道


Screen的另外一个用法要稍微特殊一些,这么说吧,比如你开了n个窗口正在工作,突然有事要停下来,暂时关闭掉作别的事,或者是在公司没作完回家接着作,抑或是到服务器的网络连接断掉了,那么你已经打开的n个窗口、你的工作状态能不能保留呢?答案当然是肯定的!这也是Screen的一大特色,遇到上述情况,你只要Ctrl+a d就从screen的工作界面中跳出来了,回到正常的shell环境,什么时候想回来了,再使用screen -r命令就又能连接到你刚才的工作状态继续工作了。即使是在公司的screen没有用Ctrl+a d命令进行deatach,还可以用screen -x把控制权“抢”过来,嘿嘿。

Screen还具有log功能,使用Screen -L命令启动,就会在用户的home目录下自动生成screenlog.?文件,其中?是你在screen中开的“窗口”号,默认第一个为0。这样用户在 screen中的所有操作就都可以记录下来了,不管是为了写文章还是存档用都很方便。不过screenlog中还记录了Escape Code信息,所以直接用vi或者less查看很不方便,cat出来倒是原汁原味,保存了彩色shell的所有颜色,但毕竟不方便,所以我自己写了一个把screenlog转换为html代码的工具,自己觉得还有点用吧。

screenlog中的颜色和linux shell中的颜色一样,都是用Escape Code中的颜色代码来实现的,关于这些颜色代码,Pradeep Padala有一篇文章介绍的比较详细,值得学习一下。



发信人: qiuxing (球星), 信区: Linux
标 题: GNU Screen -- MITBBS Linux版镇版之宝
发信站: BBS 未名空间站 (Sun Feb 17 19:04:40 2008)

GNU Screen -- MITBBS Linux版镇版之宝

* 什么是GNU Screen

常来我们版的,基本上就算没有自己用过也听说过screen的名字了,那么到底什
么是screen, 它又是干什么的呢?为什么它能称得上是我们的镇版之宝?

screen的手册上说了,screen是一个terminal multiplexer。但是对于普通人来
讲,这个定义和没有定义差不多。我觉得最通俗的解释,应该说screen相当于文
本界面下面的一个desktop,就像GNOME, KDE之于X窗口系统。其次,screen还提
供类似于远程桌面(freenx, vnc, 或者Windows下的remote desktop)的功能,
你可以在本地生成一个"桌面",然后通过网络重新连到这个"桌面",所有你开的
"窗口"都还在。从这一点上说,screen完全可以取代nohup帮助你远程跑长时间的
程序,比如说需要过夜计算的simulation之类。

* Screen的基本功能

在我们谈screen的基本功能之前,我们来看看一个现代desktop,比如说gnome,
到底都为用户提供了什么。

首先,gnome提供了一个多窗口管理机制。以前这一块由metacity提供,现在很多
情况下是由compiz fusion 3D窗口管理器管。无论是老土的metacity还是眩目的
compiz fusion,其实说穿了都不过是给用户一个机制来管理多个同时运行的图形
化程序。广而论之,X下面的virtual desktop也不过是这个机制的延伸。

其次,gnome提供了一个(或者多个)panel,这个panel上可以加载很多有用的插
件。其中最有用的是window list,显示出你当前打开的几个应用程序的名字,然
后提供一个切换的方法。

第二有用的panel插件大概就是system monitor吧,能够显示出系统当前的
loads, memory等等。有的人大概还喜欢在panel上面显示时间,机器名等等信息。

再接下来,gnome还提供了一些别的服务,比如说程序与程序间的copy/paste服务,
设置多语言编码方式,键盘热键设定,必要的时候把屏幕锁上等等。

我们很快就能看到,以上说的这些功能,都有screen下的对应。当然,gnome是个
庞然大物,里头还有无数应用程序,就是那些以g开头的无数程序。但这些严格的
讲并不是一个桌面系统的一部分。甚至连nautilus严格的讲也不能算是desktop里
头不可分割的一部分。这些应用程序其实很多在文本界面下也有对应物,只不过
不由screen负责而已。我会在本文里头附带稍微介绍一下一些文本模式下的应用
程序。

* Screen的基本操作

** 第一次启动screen

每一个screen进程本身代表一个session. 最简单的方法是在一个终端下直接输入
screen然后回车。这时你会看到一个很简陋的greeting界面,然后你随便按一个
空格它就消失了,剩下的就是普通的shell提示符,好像什么都没发生过。你可以
运行一些标准shell指令,比如说ls,你会发现这个shell和别的shell没有任何不
同。

运行如下命令

screen -ls

你会发现它告诉你有一个screen在跑:

$ screen -ls
There is a screen on:
8671.pts-1.inferno (Attached)
1 Socket in /var/run/screen/S-qiuxing.

现在你输入Ctrl-a, 然后单个字母w,会发现左下角出现一个提示,比如说:

0*$ bash

现在再按Ctrl-a然后d,这时你开头运行命令出现的那些文字都不见了。我们现在再来
跑一次screen -ls:

$ screen -ls
There is a screen on:
8671.pts-1.inferno (Detached)
1 Socket in /var/run/screen/S-qiuxing

什么都没变除了状态由Attached变成了Detached。

现在你把你刚刚用的xterm关掉,重开一个xterm,或者有条件的话换一部电脑,
ssh到你的第一部机器,然后输入screen -r。你看见了什么?是不是之前的那些
文字都又回来了?

其实真正发生的是这么一个过程:screen创建了一个socket(一般是在
/var/run/screen/下面),把它伪装成为一个虚拟文本终端(pty device)来充当
标准输入输出设备,然后调用了一个shell 程序让它运行在这个文本终端(其实
是个socket)上。当你从一个xterm里头detach掉了screen,screen下运行的程序
不会直接退出,因为它们用的标准输入输入装置已经不是你的xterm(下面跑的那
个shell)所相关的那个虚拟文本终端,而是一个socket了。

** 管理session

一般来说,我们不会裸起一个screen. 好的practice是每次新开一个screen,都
给它取一个好记的名字:

screen -S a_name

下次再用screen -ls的时候就会发现它有一个名字了(就是随机数后面的那一部
分)。

以下为和管理session有关的命令:

- 检查有多少screen session和它们的状态用screen -ls
- detach一个正在跑的session用Ctrl-a d
- reattach这个session用screen -r,
- 如果有多个detached的session, 而我们又想attach到某一个的话,就用screen
-r a_name
- 在一个正在跑的session里头改名字: 先按Ctrl-a, 然后按冒号:, 出来一个类
似vi的输入命令的界面,在里头运行这个内部命令:sessionname a_name

一个很常见的情况:有时我们需要强制reattach到一个attached session,比如
说忘记detach了,或者是ssh的时候网络断线了. 这个命令是: screen -RD
a_name. 事实上它的实现是先给a_name session发出一个detach指令,然后在发
出一个attach指令。

** 管理窗口

- 生成一个新的窗口: Ctrl-a c。这个新的窗口跑的是你的shell。
- 生成一个新的窗口,并且让它跑某个指定的程序: Ctrl-a :, 然后输入:
screen -t 其中是窗口的名字,是窗口号,
是指定的程序。这个命令主要是在配置文件里头用。
- 关闭一个窗口: 退出这个窗口的程序,则窗口自动关闭
- 在无法退出某个程序的时候强制关闭一个窗口: Ctrl-a K
- 窗口列表: Ctrl-a w
- 窗口切换:
1. Ctrl-a ", 出现一个菜单可以选择
2. Ctrl-a , 是从0到9的窗口ID,这个命令直接切换到第号窗口
3. Ctrl-a SPACE, 下一个窗口
4. Ctrl-a BACKSPACE, 前一个窗口
5. Ctrl-a Ctrl-a, 在当前和前一个窗口之间转换,相当于Alt-Tab的功能
- 窗口改名: Ctrl-a A

** 分屏

- 上下分成两个区域: Ctrl-a S (相当于emacs里的C-x 2
- 在两个区域里头切换: Ctrl-a TAB
- 合并两个区域: Ctrl-a Q (相当于emacs里的C-x 1), Ctrl-a X (相当于
emacs里头的C-x 0)

** copy/paste

正常模式下screen把所有的不以Ctrl-a开头的命令都完全透明地pass给窗口里
头的程序了。其实screen还有一个copy/paste模式,进入这个模式后screen的行
为就更像一个text editor(vi),你可以copy/paste,也可以上下移动(相当于
scroll window)。

- 进入copy/paste mode: Ctrl-a ESC或者Ctrl-a [.
- 在c/p mode下移动光标: 上下左右箭头,pgup/pgdown等。vi的hjkl,BE,/?等
等也都work
- Set mark: SPACE (类似emacs里面的Ctrl-SPACE)
- 两个mark里的内容自动进入screen的c/p buffer, 并且退出c/p mode。
- 这个c/p buffer还可以用文件写出来: Ctrl-a >

在正常模式下,Ctrl-a ]能够paste刚刚选中的内容。

** 其它有用功能/注意事项

第一重要的注意事项: 不要乱按Ctrl-a s. 它会锁死你的shell。不过不小心碰
到了也别怕,再按一下Ctrl-a q,你的shell就活过来了。

第二重要的事情: 我习惯了在shell/emacs里用Ctrl-a而不是Home跳到句首。可
是现在Ctrl-a被screen占用了。那么,我们怎么输入一个Ctrl-a? 答案: Ctrl-a
再加字母a.

推论: 如果在一个screen里头不小心attach了另外一个screen怎么办? 用Ctr-a
a d来detach里头的那个screen.

- 查看系统时间等信息: Ctrl-a t
- 查看screen本身的信息: Ctrl-a v
- 锁住屏幕: Ctrl-a x
- 清理屏幕: Ctrl-a l
- 有时候screen会显示一些信息,想要显示上一次显示的提示内容的话:
Ctrl-a m
- 给当前窗口录像(生成一个log,记录所有的信息): Ctrl-a H
- 使用visual bell: Ctrl-a Ctrl-g

* 配置文件

screen的基本配置文件是~/.screenrc(用户目录下的一个隐藏文件)。事实上在
这里控制的screen参数都可以在一个正在跑的screen里面通过进入命令行模式
(Ctrl-a :),输入相关命令来实现。但写配置文件可以省不少重复性的工作。

启动screen时有一个"-c"的参数来使用任何一个指定文件作为配置文件。比如:

screen -c .screenrc2

附录里有一个screenrc文件例子,里头详细的注释了每一行是干什么的。

* 高级用法

** 关注某个窗口

有时候我们可能开了一个窗口来跑一个要跑很久的程序,又或者那个窗口跑的是
pine/mutt,但我们在另外一个窗口干活。绝大多数时候第一个窗口都不会有任何
信息,但假设出现了变化比如说程序跑完了或者收到了新的email,我们也希望能
够在干活的当前窗口得到一个提示。

还有另外一种相反的情况,比如说编译一个大程序,不断的会出各种信息。但如
果不出了,那就说明编译完了(或者错了),这时候我们也希望得到通知。这个
功能大约对于Gentoo用户来说是最有用的.

这些都可以通过打开/关闭monitoring来实现。

- Ctrl-a M. 这样当前窗口如果出现变化,系统会通过message来通知你
- Ctrl-a _. 正好是上面的反面,如果当前窗口15秒都没动静了,则screen会发
一个msg.

** caption/hardstatus line

之前我提到过screen可以实现类似于gnome panel的功能。这个功能在screen里面
叫做caption line或者hardstatus line。它的配置看起来比较复杂,但一旦搞明
白了你就可以用它干很多很cool的事情。一个类比是配置bash的提示符,也是属
于不大好配置但很强大的东西。

我先举一个简单的例子吧:

caption always "%{+b Yk}%w"
hardstatus alwayslastline "Host: %H Load: %l "

它的效果是出现了两条panel, 第一条叫做caption line, 里头的内容是带颜色的
窗口信息, 第二条是hardstatus line, 里头有host和system load的信息。

在"%{+b Yk}%w"里头,%是escape sequence,+b是指粗体,Yk指的是亮黄(Y)字体,
配黑色(k)背景,%w是窗口号/名字。hardstatus bar里面,%H是hostname, %l是
系统load(和top里头显示的一样),其他就是一般的字符。

下面是一个比较复杂的hardstatus line配置, 视觉效果比单纯的%w要好:

hardstatus alwayslastline '%{Yk}%-w%{.Yk}%n %t%{-}%+w %=%{.w}'

更多的色彩,信息,请参阅screen manual里头关于string escapes那一章。

** Panel插件

虽然screen提供了很多string escapes, 但它们还是不可能满足所有人所有的需
要。比如说我自己就想知道系统使用了多少内存,有的人可能还想查看有没有新
邮件,等等。在gnome panel里头,这些都是通过panel插件来实现的。在screen
的caption/hardstatus line里也有一个类似的机制,让你把任何一个指定的程序
的output放在panel上。

一个简单的例子:

backtick 1 5 5 uptime
hardstatus alwayslastline "%1`"

解释一下:backtick 1 5 5 uptime的意思是定义外部命令uptime的标准输出作为
一个string escape, ID为1. 一次显示5秒钟,5秒钟之后重新运行一次。

比较复杂的例子(这也是我自己在用的screenrc):

backtick 1 5 5 /home/qiuxing/bin/my_sysload1
backtick 2 5 5 /home/qiuxing/bin/my_free

hardstatus string '%{Yk}%-w%{.Yk}%n %t%{-}%+w %=%{.w} %{.Yr}%1` %{.Yb}%2`M %
{kY}%C'

其中my_sysload1和my_free的内容如下:

my_sysload1:

#!/bin/bash
cat /proc/loadavg | cut -d" " -f1

my_free:
free -m | tail -n 2 | head -n 1 | cut -c27-29

** 256色

比较新的screen支持256色。如果自己编译,记得在编译的时候打开这个选项。
Feisty和之前的Ubuntu下的screen没有加这个编译选项,但在Gutsy里这个选项已
经有了。我知道的支持256色的程序有vi/emacs/elinks。如果你知道别的文本模
式程序支持256色,请务必让我知道。

如果你知道你的screen支持256色,请在.screenrc里头加入这么几句:

term xterm-256color
attrcolor b ".I"
termcapinfo xterm-256color 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
defbce "on"

其中第一句让screen伪装成一个xterm-256color,第二句让screen使用bold字体,
第三句告诉screen怎么定义前景背景等信息,最后一句是让screen用背景色来
erase text。

另外要确认一下你的系统上的确有xterm-256color这个term的信息。在Ubuntu里,
这个库叫做ncurses-term。

** X/鼠标支持

有一些文本程序也支持鼠标(emacs, elinks, w3m),有的甚至还支持inline
picture display(w3m)。screen对于这些都支持得很好。只要记住远程连接的时
候打开X11 forwarding开关(ssh -X),另外要检查一下shell变量DISPLAY是不
是设置对了(本地显示应该是:0.0,远程一般是:10.0之类的东西)。

** 编码转换

screen还有一个鲜为人知的功能:实现编码转换。比如说mrxvt只能支持gbk,但
不能支持unicode。可是我的中文文件都是unicode编码的。这时就可以通过
screen来实现编码转换:

encoding GBK UTF-8

只要在一个支持unicode的terminal里头生成一个screen session,detach之,下
次在一个编码为zh_CN.gbk的mrxvt里头reattach上这个session,所有的
zh_CN.utf8编码的中文文字就会自动转换为gbk格式。

** 多用户支持

screen还可以支持多用户。也就是说一个用户生成了一个session,然后让guest
来参与。具体的做法是先让screen变成一个setuid root的程序,然后在
screenrc里头允许另外一个用户连接。

如果你用过这个功能就会发现它相当的cool。但因为有一定的security concern,
我就不写太详细了。真要想用的话请参照这个Gentoo howto:

http://gentoo-wiki.com/HOWTO_Snoop_terminal_session#Screen

* 附录

** screenrc文件范例

# 和256色相关的配置
term xterm-256color
attrcolor b ".I"
termcapinfo xterm-256color 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
defbce "on"

# 编码转换
encoding GBK UTF-8

# 使用visual bell
vbell on

# 断线的时候自动detach
autodetach on

# 不要出来那个烦人的greeting
startup_message off

# make the shell in every window a login shell
# 意思是会去执行~/.bash_profile
shell -$SHELL

# 在copy/paste模式下可以回溯到5000行的历史
defscrollback 5000

#remove some stupid / dangerous key bindings
bind k
bind ^k
bind .
bind ^\
bind \\
bind ^h
bind h
#make them better
bind 'K' kill
bind 'I' login on
bind 'O' login off
bind '}' history

# default windows

screen -t work 0
screen -t shell 1
screen -t su 3 sudo su -
screen -t others 4
chdir /home/qiuxing/Documents/writing/linux
screen -t notes 5
chdir
screen -t mutt 6 mutt
select 0

# hardstatus line hack
backtick 1 5 5 /home/xqiu/bin/my_sysload1
backtick 2 5 5 /home/xqiu/bin/my_free

hardstatus alwayslastline '%{Yk}%-w%{.Yk}%n %t%{-}%+w %=%{.w} %{.Yr}%1` %{.
Yb}%2`M %{kY}%C'

** 常用文本模式程序

- 文件管理器:
1. bash
2. mc (midnight commander)
- 系统资源管理
1. top
2. htop
3. ps
- 文本编辑: emacs -nw, vi, nano, ...
- 网络浏览器: w3m(中文支持很好), elinks
- 聊天:
1. finch. 这个是pidgin/gaim的文本模式, 唯一支持QQ的text mode程序
2. centericq 很早以前用过,功能也很强大
3. irssi 最好的IRC聊天室client
4. irssi + bitlbee 如果你用这个组合,你就是真正的chat geek了!
- 邮件/新闻组
1. mutt
2. pine
3. gnus
- 文件传输
1. lftp (支持很多协议包括sftp, www)
2. wget
3. rsync
4. unison
- 科学运算 R, octave, maxima, python (scipy), ...
- 网络调试
1. tcpdump
2. nmap
3. netcat
- 音乐 mpg321, mplayer, 还有一些比较复杂的比如说cplay, moc等。
- Bittorrent: rtorrent

** 更多信息

最简单的入门:http://blogamundo.net/code/screen/
复杂一点的:http://gentoo-wiki.com/TIP_Using_screen
当然最全的信息还是screen user's manual:
http://www.delorie.com/gnu/docs/screen/screen_toc.html

Thursday, October 26, 2006

最近用来消遣看的一些东西

最近突然在考虑人生问题,马上就郁闷了。也难怪,欲望和不甘总是会让人不满,无法改变的过去,人性的弱点一直在折磨本体,而太过美妙的憧憬会导致更大的现实反差。因此心灰意懒,实验也被搁置了,不过那个实验也不知如何进行下去(借口吧)。其实自己早就想过,这一生也就做个自了汉,从佛的分类来说,就是个罗汉级的人物,只度的了自己就可以了。

要排解郁闷,比较好的办法是睡觉,可惜这样会带来更大的负罪感,已经好几次由于睡觉误事而自责。没办法,尸位素餐吧,又没地方玩,只能玩电脑了。

看naruto动画,漫画,剧场版,下ost来听。漫画要赞的,延续着紧张的剧情。动画到后面感觉像敷衍了,鸣人没成长啊,弄来弄去就那几样东西。

看网络小说,这个是被疯子和大猪头影响的。没有像他们一样博览群书,我只是stick to some books. 紫川,阿里布达,随波逐流之一代军师。以前通宵看 国之利刃,我是特种兵,真是印象深刻,热血贲张。总之,看网络小说消磨时间真的很快很快,特别是我这种一根筋的家伙,副作用也是很大。紫川好久没更新了,不会TJ了吧,散伙饭上喝醉了不省人事,被同学抬回寝室的路上突然有了些意识,意识到自己在说的竟然是“紫川”,“远东”,“魔族”,“光明王”,马上住口,然后继续不省人事。第二天还被同学笑,真怀念。

anyway, 目前拿的出手的兴趣爱好还真没有,什么都会一点但没有一样是很深入的,头疼啊。