tag:blogger.com,1999:blog-361089962024-02-22T00:38:28.894-08:00linuxIn which place keep my notes for studywasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-36108996.post-22518756236869883522011-04-07T02:52:00.000-07:002011-04-07T02:53:37.757-07:00How to disable SSH host key checking<p>Original link </p><p>http://linuxcommando.blogspot.com/2008/10/how-to-disable-ssh-host-key-checking.html</p><p></p><p>Remote login using the SSH protocol is a frequent activity in today's internet world. With the SSH protocol, the onus is on the SSH client to verify the identity of the host to which it is connecting. The host identify is established by its SSH host key. Typically, the host key is auto-created during initial SSH installation setup.<br /><br />By default, the SSH client verifies the host key against a local file containing known, rustworthy machines. This provides protection against possible Man-In-The-Middle attacks. However, there are situations in which you want to bypass this verification step. This article explains how to disable host key checking using OpenSSH, a popular Free and Open-Source implementation of SSH.<br /><br />When you login to a remote host for the first time, the remote host's host key is most likely unknown to the SSH client. The default behavior is to ask the user to confirm the fingerprint of the host key.<br />$ ssh peter@192.168.0.100<br />The authenticity of host '192.168.0.100 (192.168.0.100)' can't be established.<br />RSA key fingerprint is 3f:1b:f4:bd:c5:aa:c1:1f:bf:4e:2e:cf:53:fa:d8:59.<br />Are you sure you want to continue connecting (yes/no)? <br /><br />If your answer is yes, the SSH client continues login, and stores the host key locally in the file ~/.ssh/known_hosts. You only need to validate the host key the first time around: in subsequent logins, you will not be prompted to confirm it again.<br /><br />Yet, from time to time, when you try to remote login to the same host from the same origin, you may be refused with the following warning message:<br />$ ssh peter@192.168.0.100<br />@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br />@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @<br />@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br />IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!<br />Someone could be eavesdropping on you right now (man-in-the-middle attack)!<br />It is also possible that the RSA host key has just been changed.<br />The fingerprint for the RSA key sent by the remote host is<br />3f:1b:f4:bd:c5:aa:c1:1f:bf:4e:2e:cf:53:fa:d8:59.<br />Please contact your system administrator.<br />Add correct host key in /home/peter/.ssh/known_hosts to get rid of this message.<br />Offending key in /home/peter/.ssh/known_hosts:3<br />RSA host key for 192.168.0.100 has changed and you have requested strict checking.<br />Host key verification failed.$<br /><br />There are multiple possible reasons why the remote host key changed. A Man-in-the-Middle attack is only one possible reason. Other possible reasons include:<br />OpenSSH was re-installed on the remote host but, for whatever reason, the original host key was not restored.<br />The remote host was replaced legitimately by another machine. <br /><br />If you are sure that this is harmless, you can use either 1 of 2 methods below to trick openSSH to let you login. But be warned that you have become vulnerable to man-in-the-middle attacks. <br /><br />The first method is to remove the remote host from the ~/.ssh/known_hosts file. Note that the warning message already tells you the line number in the known_hosts file that corresponds to the target remote host. The offending line in the above example is line 3("Offending key in /home/peter/.ssh/known_hosts:3")<br /><br />You can use the following one liner to remove that one line (line 3) from the file.<br />$ sed -i 3d ~/.ssh/known_hosts<br /><br />Note that with the above method, you will be prompted to confirm the host key fingerprint when you run ssh to login.<br /><br />The second method uses two openSSH parameters:<br />StrictHostKeyCheckin, and<br /><br />UserKnownHostsFile.<br /><br />This method tricks SSH by configuring it to use an empty known_hosts file, and NOT to ask you to confirm the remote host identity key.<br />$ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no peter@192.168.0.100<br />Warning: Permanently added '192.168.0.100' (RSA) to the list of known hosts.<br />peter@192.168.0.100's password:<br /><br />The UserKnownHostsFile parameter specifies the database file to use for storing the user host keys (default is ~/.ssh/known_hosts).<br /><br />The /dev/null file is a special system device file that discards anything and everything written to it, and when used as the input file, returns End Of File immediately.<br /><br />By configuring the null device file as the host key database, SSH is fooled into thinking that the SSH client has never connected to any SSH server before, and so will never run into a mismatched host key.<br /><br />The parameter StrictHostKeyChecking specifies if SSH will automatically add new host keys to the host key database file. By setting it to no, the host key is automatically added, without user confirmation, for all first-time connection. Because of the null key database file, all connection is viewed as the first-time for any SSH server host. Therefore, the host key is automatically added to the host key database with no user confirmation. Writing the key to the /dev/null file discards the key and reports success.<br /><br />Please refer to this excellent article about host keys and key checking.<br /><br />By specifying the above 2 SSH options on the command line, you can bypass host key checking for that particular SSH login. If you want to bypass host key checking on a permanent basis, you need to specify those same options in the SSH configuration file.<br /><br />You can edit the global SSH configuration file (/etc/ssh/ssh_config) if you want to make the changes permanent for all users.<br /><br />If you want to target a particular user, modify the user-specific SSH configuration file (~/.ssh/config). The instructions below apply to both files.<br /><br />Suppose you want to bypass key checking for a particular subnet (192.168.0.0/24).<br /><br />Add the following lines to the beginning of the SSH configuration file.<br />Host 192.168.0.*<br /> StrictHostKeyChecking no<br /> UserKnownHostsFile=/dev/null<br /><br />Note that the configuration file should have a line like Host * followed by one or more parameter-value pairs. Host *means that it will match any host. Essentially, the parameters following Host * are the general defaults. Because the first matched value for each SSH parameter is used, you want to add the host-specific or subnet-specific parameters to the beginning of the file.<br /><br />As a final word of caution, unless you know what you are doing, it is probably best to bypass key checking on a case by case basis, rather than making blanket permanent changes to the SSH configuration files.<br /><br /></p>wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-62156803457395447862010-09-29T02:13:00.000-07:002010-09-29T02:41:46.898-07:00file manipulation1) output total number of input file<br />awk 'END {print NR}' input_file<br /><br />2) output #3 line Number of Field(NF)<br />awk 'NR==3 {print NF}' input_file<br /><br />3) output lines that contains "INFO"<br />awk '/INFO/ {print}' input_file<br />less input_file | grep INFO<br /><br />4) output lines that doesn't contain "INFO"<br />awk '!/INFO/ {print}' input_file<br />less input_file | grep -v INFO<br /><br />5) output the second colum<br />awk -F "delimter" '{print $2}' input_file<br />cut -d "delimiter" -f2 input_file<br /><br />6) output the first and the third colum<br />awk -F "delimter" '{print $1 $3}' input_file<br />cut -d "delimiter" -f1,3 input_filewasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-32445598388112819032010-09-24T08:53:00.000-07:002010-09-28T08:21:33.338-07:00Install Apache and PHP on Window XPApache: 2.2.16<br />httpd-2.2.16-win32-x86-openssl-0.9.8o.msi<br />http://www.apache.org/dist/httpd/binaries/win32/httpd-2.2.16-win32-x86-openssl-0.9.8o.msi<br /><br />PHP: 5.2.14<br />php-5.2.14-Win32-VC6-x86.zip<br />http://windows.php.net/downloads/releases/php-5.2.14-Win32-VC6-x86.zip<br /><br />Mysql: 5.1.50<br />mysql-essential-5.1.50-win32<br /><br />---------------------------------------------------------------------------------------------<br /><br /><span style="font-size:180%;"><span style="font-weight:bold;">Apache:</span></span><br />1) Download and unpack<br />I used httpd-2.2.16-win32-x86-openssl-0.9.8o.msi<br />http://www.apache.org/dist/httpd/binaries/win32/httpd-2.2.16-win32-x86-openssl-0.9.8o.msi<br /><br /><br />2) Install<br />When you install Apache, you'll get a prompt for "Server Information." Here is the settings I used:<br />Network Domain: localhost<br />Server Name: localhost<br />Admin Email: (any email. real or fake)<br /><br />[checked]: for All Users, on Port 80, as a Service<br /><br /><br />3) Starting/Stop Apache<br />After installing, Apache2 automatically starts. The GREEN icon in the System Tray means it started. The RED icon means the "Monitor Apache Servers" is running, but Apache2 isn't started.<br /><br />You can easily start/stop/restart Apache and Apache2 via that icon in your System Tray. If you get "The requested operation has failed!" error while starting apache use the "Test Configuration" shortcut in the Start Menu to find the error (if the text window pops up then closes before you can read it, your config file is fine).<br /><br />4) Testing<br />Now the ultimate test. To see if it's serving. Open your browser and head to: http://127.0.0.1/ or http://localhost/<br />If it shows the It works! you have your server software installed and running.<br /><br />5) Configuration:<br />Making Apache point to your files, using Notepad open C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf (in the start-menu there should also be a "Apache HTTP Server 2.2 > Configure Apache Server > Edit the Apache httpd.conf Configuration File" shortcut) and search for DocumentRoot.<br /><br />Change it from something like<br /><br /><em>DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"<br />DocumentRoot "C:/public_html"<br /></em><br /><br />it will locate where your HTML files and site are located, then scroll down about one page and change<br /><br /><em>Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs" ><br />Directory "C:/public_html ><br /></em><br /><br /><span style="font-size:180%;"><span style="font-weight:bold;">PHP:</span></span><br />http://www.php.net/manual/en/install.windows.manual.php<br /><br />1) Download and unzip<br />I select to install PHP manually, php-5.2.14-Win32-VC6-x86.zip<br />http://windows.php.net/downloads/releases/php-5.2.14-Win32-VC6-x86.zip<br /><br />Unzip the file to C:\php<br /><br />2) Configuration<br />Rename C:\php\php.ini-dist to php.ini and edit php.ini file for parameters:<br /><br /><em>doc_root = "C:\public_html"<br />extension_dir = "C:\php\ext"</em><br /><br />Edit Apache Conf File in<br />C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd<br /><br />add following at the begin of apache configuration file<br /> <br /><em>LoadModule php5_module "C:/php/php5apache2_2.dll"<br />AddType application/x-httpd-php .php<br />AddHandler application/x-httpd-php .php<br />PHPIniDir "C:/php"</em><br /><br />Then Reboot Microsoft Windows system(very important)<br /><br />3) Testing<br />Restart Apache if it is already running (if it doesn't start or you get errors, use your Apache "Test Configuration" shortcut in the Start Menu to see why).<br /><br /><p>To test your PHP simply create a test.php file in your Apache "DocumentRoot" folder (C:\public_html\ in my case). In your test.php file, type these 3 lines and then load the file in your browser like http://localhost/test.php (you should get a whole long list of php variables, settings, etc):</p><br /><br /><br /><span style="font-size:180%;"><span style="font-weight:bold;">Mysql:</span></span><br />1) Download and installation for mysql-essential-5.1.50-win32<br />Install path is in<br />C:\Program Files\Mysql\mysql server5.1\<br /><br />log files, databases is installed in<br />C:\public_html\mysql_data<br /><br />start mysql using<br />C:\Program Files\Mysql\mysql server5.1\bin\mysqld --console<br /><br />stop mysql using <br />C:\Program Files\Mysql\mysql server5.1\bin\mysqladmin -u root shutdown<br /><br />2) Mysql server instance configuration wizard and keep use default <br /><br />Hint: if you reinstall Mysql, you have to delete mysql data 1) C:\public_html\mysql_data; 2) Ran RegEdit, searched for every instance of MySQL, and deleted it from the registry. <br /><br />then install againwasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-13185611900612708602009-01-22T14:45:00.000-08:002009-01-22T14:48:17.632-08:00Amarok<pre>su -c 'rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm<br />http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm'</pre>OS: fedora 9<br />Installation: sudo yum amarok libtunepimp-extras-nonfree xine-lib-extras-nonfreewasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-14737972204187844742008-01-21T03:15:00.000-08:002008-01-21T03:16:50.134-08:00English names for the characters in keyboard<table border="1" width="100%"><tbody><tr><td width="60">~ </td><td>tilde (sounds like til-da); be prepared to explain to computer-illiterate people saying "you know, the wave-shaped thingy"</td></tr> <tr><td>! </td><td>exclamation; commonly read as bang in case of #!/bin/sh</td></tr> <tr><td>@ </td><td>at</td></tr> <tr><td># </td><td>pound; but commonly read as shee in case of #!/bin/sh, not sure why</td></tr> <tr><td>$ </td><td>dollar</td></tr> <tr><td>% </td><td>percent</td></tr> <tr><td>^ </td><td>caret; not many people know this word so be prepared to say "no, not carrot; it's the character above 6, an arrow pointing up"</td></tr> <tr><td>& </td><td>ampersand</td></tr> <tr><td>* </td><td>star; some read asterisk</td></tr> <tr><td>( </td><td>opening parenthesis (some may shorten it saying paren)</td></tr> <tr><td>) </td><td>closing parenthesis</td></tr> <tr><td>_ </td><td>underscore; once I heard people say underbar</td></tr> <tr><td>+ </td><td>plus</td></tr> <tr><td>- </td><td>minus; as symbol before arguments in commands, some people including me read dash, easier to say one syllable</td></tr> <tr><td>= </td><td>equals</td></tr> <tr><td>` </td><td>backtick or backquote</td></tr> <tr><td>{ </td><td>opening brace</td></tr> <tr><td>} </td><td>closing brace</td></tr> <tr><td>[ </td><td>opening bracket</td></tr> <tr><td>] </td><td>closing bracket</td></tr> <tr><td>| </td><td>pipe or vertical bar</td></tr> <tr><td>\ </td><td>backslash; be prepared to explain to some computer-illiterate people</td></tr> <tr><td>: </td><td>colon</td></tr> <tr><td>; </td><td>semicolon</td></tr> <tr><td>" </td><td>double quote</td></tr> <tr><td>' </td><td>single quote</td></tr> <tr><td>< </td><td>less than; some may read left angle bracket</td></tr> <tr><td>> </td><td>greater than</td></tr> <tr><td>, </td><td>comma</td></tr> <tr><td>. </td><td>dot; period if in English text</td></tr> <tr><td>? </td><td>question mark</td></tr> <tr><td>/ </td><td>slash or forward slash; some computer-illiterate people may be confused about / and \</td></tr> <tr><td> <br /></td><td>space</td></tr> <tr><td>(), [] and {} </td><td>may also be called brackets in general. In that case, they specifically call [] square brackets and {} curly brackets. I never like this. Open and Closing may also be called left and right.</td></tr></tbody></table>wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com14tag:blogger.com,1999:blog-36108996.post-36610100096318739512007-11-25T12:34:00.000-08:002009-01-18T10:19:17.155-08:00Emacs (Auctex) Window XP installation instructionInstallation instruction:<br />This article describes the installation of emacs including Auctex for Window XP. Since most of these files have be precompiled, what you need just download the precompiled file and configurate them.<br /><br />1) Download Emacs(including Auctex) for Window XP. The download page as follow:<br /><br /> http://www.gnu.org/software/auctex/download-for-windows.html<br /><br /> And here we use the version emacs+auctex-w32-2007-07-07.zip, you can download from<br /> ftp://alpha.gnu.org/gnu/auctex/emacs+auctex-w32-2007-07-07.zip<br /><br /> Please read the README file before downloading, and in this manual, which included all lisp code and documentation. We put the unzipped file Emacs to the directory C:\Program Files\Emacs. Then we need to setup environmental variable:<br /><br /> HOME=C:\Program Files\Emacs<br /><br /> Afterwards, .emacs.d and .emacs are under the directory $HOME(C:\Program Files\Emacs)<br /><br /><span style="color: rgb(255, 0, 0);">Note: the configuration of the $HOME is very important, please set if first before the following configuration.</span><br /><br />2) Configuration<br /><br /> Generally speaking, the main purpose of configuration to Emacs is to set up .emacs file, which was located in the $HOME directory. Here we take into account an example of how to set Aspell that could check spelling.<br /><br />**********************************************************************************************************************<br /> Configuration for Aspell:<br /><br /> (1) First, download full installer from<br /> http://aspell.net/win32/<br />and then worldlist setup. Be aware of they are two separately installations.<br /><br /> (2) In my configuration, I installed them into the C:\Program Files\Emacs\Aspell. Then add the path C:\Program Files\Emacs\Aspell\bin to the environmental variable PATH.<br /><br /> (3) Download the ispell.el from<br /> http://kdstevens.com/~stevens/ispell-page.html<br /> and then put ispell.el to directory $HOME/site-lisp<br /><br /> (4) add to the .emacs as<br /> (setq-default ispell-program-name "aspell")<br /> (setq-default ispell-local-dictionary "american")<br /> (global-set-key (kbd "") 'ispell-complete-word)<br />*********************************************************************************************************************<br />Configuration for Latex<br /><br />Thought this emacs version includes Auctex, but we need to download latex for windown XP, you can find more information here:<br /><br />http://www.hi.is/~tpr/latex/index.html<br /><br />Here we use Miktex, a latex compiler. Generally set up and the installation will set latex command to the environmental variable PATH.<br /><br />There is problem for preview functionality, what is resolution here is enter the Miktex installed directory, in my case is<br />C:\Program Files\MiKTeX 2.6\miktex\bin<br />change the yap to xdvi.<br />The reason for this operation is preview functionaliy here is "xdvi file.dvi", however, can not find xdvi in miktex, we just change the command name as xdvi here.<br />To produce PDF file:<br />dvipdft file.dvi<br />To produce PS file:<br />dvips file.dvi<br />***********************************************************************************<br />;my .emacs file<br />;------------------------------------------------------------------------------<br />; Basic set up<br />;------------------------------------------------------------------------------<br /><br />(setq default-major-mode 'text-mode); set defalut mode as text-mode<br />(setq inhibit-startup-message t) ; Don't want any startup message<br />(setq auto-save-default nil) ; Don't want any auto saving<br />(setq auto-save-list-file-name nil) ; Don't want any .saves files<br />(show-paren-mode t) ;parathesis mathcing<br />;; the following setups are for color style, since here I used color.el, not necessary to set anything<br />;(setq make-backup-files nil) ; Don't want any backup files<br />;(set-cursor-color "blue") ; Set cursor and mouse-pointer colours<br />;(set-background-color "white") ; Set emacs bg color<br /><br /><br />(mouse-avoidance-mode 'jump) ;when cursor close to mouse, mouse avoid automatically, funny ^_^<br />(tool-bar-mode nil) ; disappear tool-bar<br />;(menu-bar-mode nil) ; disappear menu-bar<br />(global-set-key [f9] 'tool-bar-mode) ;keybindings for tool-bar<br />;(global-set-key [f10] 'menu-bar-mode) ;keybindings for menu-bar<br />(setq default-line-spacing 10)<br /><br /><br />;---------------------------------------------------------------------------<br />;Some (keybindings)keyboard shortcuts for instance copy f5, cut f6, paste f7<br />;---------------------------------------------------------------------------<br /><br />;(global-set-key [f5] 'copy-region-as-kill) ; Copy<br />(global-set-key [f6] 'kill-region) ; Cut<br />(global-set-key [f7] 'yank) ; Paste<br /><br /><br />;-------------------------<br />;color package<br />;-------------------------<br />;(load-file "/home/wason/myemacs/color-theme-6.5.0.el")<br />;(load-file "C:\Program Files\emacs-22.1\site-lisp/color-theme.el")<br />;(load-file "/home/wason/myemacs/color-theme-6.6.0.el")<br />;(load-file "/home/wason/myemacs/color-theme-6.6.0/color-theme.el")<br />(require 'color-theme)<br />(color-theme-arjen)<br />;(color-theme-dark-blue2)<br /><br />;-------------------------<br />;setup for aspell<br />;----------------------------<br />(setq-default ispell-program-name "Aspell")<br />(setq-default ispell-local-dictionary "american")<br />(global-set-key (kbd "") 'ispell-complete-word)<br /><br /><br />;(load "auctex.el" nil t t)<br />;(load "preview-latex.el" nil t t)<br /><br />;(setq TeX-parse-self t)<br />;(setq-default TeX-master nil)<br />;(add-hook 'LaTeX-mode-hook 'turn-on-reftex)<br />;(setq reftex-plug-into-AUCTeX t)<br /><br />***********************************************************************************<br /><br />Similar, we can configurate any other features in emacs. Enjoy it.wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com1tag:blogger.com,1999:blog-36108996.post-83337586046413740992007-11-04T06:17:00.000-08:002009-01-18T10:40:08.844-08:00MBR恢复今天电脑出现一个非常奇怪的事情,我的本本上装了双系统,XP和Ubuntu, 我的移动硬盘也是双系统,XP和Ubuntu, 然后我在我的本本上用magic对移动硬盘格式化等操作。等操作弄完,重新启动电脑, grub 居然出错, 显示error 17。在网上查了查,17的错误是不能认识引导区。 后来在网上查了查,原来是MBR在格式化硬盘的时候损坏了,真是想不通,对不同的硬盘操作,为什么会相互影响。废话少说,现在来恢复。<p>恢复MBR的办法,直接用XP安装盘启动,进入控制台,然后执行fixmbr。 XP可以恢复了。 Ubuntu仍然进不了。现在的情形几乎是原来双系统,重装xp后linux恢复不了,原因是MBR重写了,这里介绍两个方法来恢复:</p><p>1)一种方法是下载grldr, 放在C盘,然后修改boot.int, 在最后一行加上 C:\GRLDR="GRUB"。 虽然恢复以后的系统不是100%的完美,主要要两次引导,一次是grldr, 然后才是linux下的grub。<br /></p><p>2) 第二种恢复是完全恢复,在恢复以前首先必须从floopy 或者恢复盘进入到GRUB。 比如从floopy恢复,先要把GRUB安装到floopy上面,安装的方法是</p><p><em>cd /usr/lib/grub/i386-pc</em></p><p><em>dd if=stage1 of=/dev/fd0 bs=512 count=1</em></p><p><em>dd if=stage2 of=/dev/fd0 bs=512 seek=1</em></p><p>然后从floopy启动, 进入到GRUB控制台。 </p><p>找可以用的stage1文件 </p><p><em>find /boot/grub/stage1</em></p><p>如果系统安装了多个操作系统,比如</p><ul><li>SUSE on (hd0,1)</li><li>Kubuntu on (hd0,2) </li><li>Mandriva on (hd0,4)</li></ul><p>如果用SUSE的stage1文件</p><p>root (hd0,1)</p><p>如果用Kubuntu的stage1文件</p><p>root (hd0,2)</p><p>同理Mandriva</p><p>root (hd0,4)</p><p>最后setup(hd0)</p><p>然后退出。 </p><p>总结一下</p><p><em>find /boot/grub/stage1 (optional)<br />root (hdX,Y)<br />setup (hd0)<br />quit</em></p><p>重新启动机器 ok</p><p></p>wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-85870498131018457562007-08-03T06:12:00.001-07:002010-10-07T01:00:06.673-07:00What does “> /dev/null 2>&1″ mean?(Original artical can be found:<br /><a href="http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/">http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/</a>)<br /><br />Example command:<br /><br />cmd > file 2>&1<br /><br />Output redirection<br /><br />There are three standard sources of input and output for a program. Standard input usually comes from the keyboard if it’s an interactive program, or from another program if it’s processing the other program’s output. The program usually prints to standard output, and sometimes prints to standard error. These three file descriptors are often called STDIN(0), STDOUT(1), and STDERR(2), and use 0,1,2 to represent correspondingly.<br /><br />by default, it looks like<div align="left"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 261px; height: 160px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1e0BhqiQdPoTyVnC2G6OR1IDMa7u3SjSkJaVE6eLPAH6oV3ifENEwjXnOYqhKr-2v43ZFsZPQ63EFPh-JkThXM-FMVkN8UuoShWNqLbHWDFZogTb9n0lnQRxZ_B0MSZJ69LOQ/s320/default.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5525210796648792514" /><br /><br /><br /></div><p>Given that context, you can see the command above is redirecting standard output into file, then redirecting standard error into standard output (you have to put an & in front of the destination when you do this). It looks like <br /></p><div align="center"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 281px; height: 191px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdmqvGNAHURQrUa7eBuD3kSj9wm0vP9daTZhA4OuSJg_ehwIMrcG9F2IGj0XosyJbq57ONLEdPzbApx8wt5hJO7kzpKMsP99egzdZxPO_Q7Rga8tdtu0RNR5B8pdFrhmmPvVcP/s320/1.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5525209071671035890" /><br /></div><p>if the commnd is cmd <>&1, the it looks like </p><p><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 281px; height: 175px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaPFCTpfyd3Iebjv-hBmm-mLIYLLkG8Km1isRSD-Nyke_qarWUE2Flr5duGC0CVO49by2FlVMYOdzYXMfeg9uLGzBIi7Sj7zbrn6JaagZgt0_d28mkexmnlMrFFSVus2WmKrgy/s320/2.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5525210380513550770" /></p>wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-90618171770724611712007-07-29T08:15:00.000-07:002008-12-08T13:01:38.653-08:00linux 启动过程(一直没有时间看,先保留)本文以RedHat9.0和i386平台为例,剖析了从用户打开电源直到屏幕出现命令行提示符的整个Linux启动过程。并且介绍了启动中涉及到的各种文件。<br /><br /> 阅读Linux源代码,无疑是深入学习Linux的最好方法。在本文对Linux启动过程的介绍中,我们也尝试从源代码的视角来更深入的剖析Linux 的启动过程,所以其中也简单涉及到部分相关的Linux源代码,Linux启动这部分的源码主要使用的是C语言,也涉及到了少量的汇编。而启动过程中也执行了大量的shell(主要是bash shell)所写脚本。为了方便读者阅读,笔者将整个Linux启动过程分成以下几个部分逐一介绍,大家可以参考下图:<br /><br /> 当用户打开PC 的电源,BIOS开机自检,按BIOS中设置的启动设备(通常是硬盘)启动,接着启动设备上安装的引导程序lilo或grub开始引导Linux, Linux首先进行内核的引导,接下来执行init程序,init程序调用了rc.sysinit和rc等程序,rc.sysinit和rc当完成系统初始化和运行服务的任务后,返回init;init启动了mingetty后,打开了终端供用户登录系统,用户登录成功后进入了Shell,这样就完成了从开机到登录的整个启动过程。<br /><br />下面就将逐一介绍其中几个关键的部分:<br /><br /><br /><br /> 第一部分:内核的引导(核内引导)<br /><br /> Red Hat9.0可以使用lilo或grub等引导程序开始引导Linux系统,当引导程序成功完成引导任务后,Linux从它们手中接管了CPU的控制权,然后CPU就开始执行Linux的核心映象代码,开始了Linux启动过程。这里使用了几个汇编程序来引导Linux,这一步泛及到Linux源代码树中的“arch/i386/boot”下的这几个文件:bootsect.S、setup.S、video.S等。<br /><br /> 其中 bootsect.S是生成引导扇区的汇编源码,它完成加载动作后直接跳转到setup.S的程序入口。setup.S的主要功能就是将系统参数(包括内存、磁盘等,由BIOS返回)拷贝到特别内存中,以便以后这些参数被保护模式下的代码来读取。此外,setup.S还将video.S中的代码包含进来,检测和设置显示器和显示模式。最后,setup.S将系统转换到保护模式,并跳转到 0x100000。<br /><br /> 那么0x100000这个内存地址中存放的是什么代码?而这些代码又是从何而来的呢?<br /><br /> 0x100000这个内存地址存放的是解压后的内核,因为Red Hat提供的内核包含了众多驱动和功能而显得比较大,所以在内核编译中使用了“makebzImage”方式,从而生成压缩过的内核,在RedHat中内核常常被命名为vmlinuz,在Linux的最初引导过程中,是通过"arch/i386/boot/compressed/"中的head.S利用 misc.c中定义的decompress_kernel()函数,将内核vmlinuz解压到0x100000的。<br /><br /> 当CPU跳到 0x100000时,将执行"arch/i386/kernel/head.S"中的startup_32,它也是vmlinux的入口,然后就跳转到 start_kernel()中去了。start_kernel()是"init/main.c"中的定义的函数,start_kernel()中调用了一系列初始化函数,以完成kernel本身的设置。start_kernel()函数中,做了大量的工作来建立基本的Linux核心环境。如果顺利执行完 start_kernel(),则基本的Linux核心环境已经建立起来了。<br /><br /> 在start_kernel()的最后,通过调用init ()函数,系统创建第一个核心线程,启动了init过程。而核心线程init()主要是来进行一些外设初始化的工作的,包括调用 do_basic_setup()完成外设及其驱动程序的加载和初始化。并完成文件系统初始化和root文件系统的安装。<br /><br /> 当 do_basic_setup()函数返回init(),init()又打开了/dev/console设备,重定向三个标准的输入输出文件stdin、 stdout和stderr到控制台,最后,搜索文件系统中的init程序(或者由init=命令行参数指定的程序),并使用 execve()系统调用加载执行init程序。到此init()函数结束,内核的引导部分也到此结束了。<br /><br />第二部分:运行init<br /><br /><br /><br /> init的进程号是1,从这一点就能看出,init进程是系统所有进程的起点,Linux在完成核内引导以后,就开始运行init程序,。 init程序需要读取配置文件/etc/inittab。inittab是一个不可执行的文本文件,它有若干行指令所组成。在Redhat系统中, inittab的内容如下所示(以“###"开始的中注释为笔者增加的):<br /><br /> #<br /> # inittab This file describes how the INIT process should set up<br /> # the system in a certain run-level.<br /> #<br /> # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org><br /> # Modified for RHS Linux by Marc Ewing and Donnie Barnes<br /> #<br /><br /> # Default runlevel. The runlevels used by RHS are:<br /> # 0 - halt (Do NOT set initdefault to this)<br /> # 1 - Single user mode<br /> # 2 - Multiuser, without NFS (The same as 3, if you do not havenetworking)<br /> # 3 - Full multiuser mode<br /> # 4 - unused<br /> # 5 - X11<br /> # 6 - reboot (Do NOT set initdefault to this)<br /> #<br /> ###表示当前缺省运行级别为5(initdefault);<br /> id:5:initdefault:<br /><br /> ###启动时自动执行/etc/rc.d/rc.sysinit脚本(sysinit)<br /> # System initialization.<br /> si::sysinit:/etc/rc.d/rc.sysinit<br /><br /> l0:0:wait:/etc/rc.d/rc 0<br /> l1:1:wait:/etc/rc.d/rc 1<br /> l2:2:wait:/etc/rc.d/rc 2<br /> l3:3:wait:/etc/rc.d/rc 3<br /> l4:4:wait:/etc/rc.d/rc 4<br /> ###当运行级别为5时,以5为参数运行/etc/rc.d/rc脚本,init将等待其返回(wait)<br /> l5:5:wait:/etc/rc.d/rc 5<br /> l6:6:wait:/etc/rc.d/rc 6<br /><br /> ###在启动过程中允许按CTRL-ALT-DELETE重启系统<br /> # Trap CTRL-ALT-DELETE<br /> ca::ctrlaltdel:/sbin/shutdown -t3 -r now<br /><br /> # When our UPS tells us power has failed, assume we have a few minutes<br /> # of power left. Schedule a shutdown for 2 minutes from now.<br /> # This does, of course, assume you have powerd installed and your<br /> # UPS connected and working correctly.<br /> pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"<br /><br /> # If power was restored before the shutdown kicked in, cancel it.<br /> pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"<br /><br /> ###在2、3、4、5级别上以ttyX为参数执行/sbin/mingetty程序,打开ttyX终端用于用户登录,<br /> ###如果进程退出则再次运行mingetty程序(respawn)<br /> # Run gettys in standard runlevels<br /> 1:2345:respawn:/sbin/mingetty tty1<br /> 2:2345:respawn:/sbin/mingetty tty2<br /> 3:2345:respawn:/sbin/mingetty tty3<br /> 4:2345:respawn:/sbin/mingetty tty4<br /> 5:2345:respawn:/sbin/mingetty tty5<br /> 6:2345:respawn:/sbin/mingetty tty6<br /><br /> ###在5级别上运行xdm程序,提供xdm图形方式登录界面,并在退出时重新执行(respawn)<br /> # Run xdm in runlevel 5<br /> x:5:respawn:/etc/X11/prefdm -nodaemon<br /><br /> 以上面的inittab文件为例,来说明一下inittab的格式。其中以#开始的行是注释行,除了注释行之外,每一行都有以下格式:<br /><br /><br /><br /> id:runlevel:action:process<br /><br /> 对上面各项的详细解释如下:<br /><br /> 1. id<br /><br /> id是指入口标识符,它是一个字符串,对于getty或mingetty等其他login程序项,要求id与tty的编号相同,否则getty程序将不能正常工作。<br /><br /> 2. runlevel<br /><br /> runlevel是init所处于的运行级别的标识,一般使用0-6以及S或s。0、1、6运行级别被系统保留:其中0作为shutdown 动作,1作为重启至单用户模式,6为重启;S和s意义相同,表示单用户模式,且无需inittab文件,因此也不在inittab中出现,实际上,进入单用户模式时,init直接在控制台(/dev/console)上运行/sbin/sulogin。在一般的系统实现中,都使用了2、3、4、5几个级别,在 Redhat系统中,2表示无NFS支持的多用户模式,3表示完全多用户模式(也是最常用的级别),4保留给用户自定义,5表示XDM图形登录方式。7- 9级别也是可以使用的,传统的Unix系统没有定义这几个级别。runlevel可以是并列的多个值,以匹配多个运行级别,对大多数action来说,仅当runlevel与当前运行级别匹配成功才会执行。<br /><br /> 3. action<br /><br /> action是描述其后的process的运行方式的。action可取的值包括:initdefault、sysinit、boot、bootwait等:<br /><br /> initdefault是一个特殊的action值,用于标识缺省的启动级别;当init由核心激活以后,它将读取inittab中的 initdefault项,取得其中的runlevel,并作为当前的运行级别。如果没有inittab文件,或者其中没有initdefault项, init将在控制台上请求输入runlevel。<br /><br /> sysinit、boot、bootwait等action将在系统启动时无条件运行,而忽略其中的runlevel。<br /><br /> 其余的action(不含initdefault)都与某个runlevel相关。各个action的定义在inittab的man手册中有详细的描述。<br /><br /> 4. process<br /><br /> process为具体的执行程序。程序后面可以带参数。<br /><br /> 第三部分:系统初始化<br /><br /> 在init的配置文件中有这么一行:<br /><br /> si::sysinit:/etc/rc.d/rc.sysinit<br /><br /> 它调用执行了/etc/rc.d/rc.sysinit,而rc.sysinit是一个bash shell的脚本,它主要是完成一些系统初始化的工作,rc.sysinit是每一个运行级别都要首先运行的重要脚本。它主要完成的工作有:激活交换分区,检查磁盘,加载硬件模块以及其它一些需要优先执行任务。<br /><br /> rc.sysinit约有850多行,但是每个单一的功能还是比较简单,而且带有注释,建议有兴趣的用户可以自行阅读自己机器上的该文件,以了解系统初始化所详细情况。由于此文件较长,所以不在本文中列出来,也不做具体的介绍。<br /><br /> 当rc.sysinit程序执行完毕后,将返回init继续下一步。<br /><br />第四部分:启动对应运行级别的守护进程<br /><br /><br /><br /> 在rc.sysinit执行后,将返回init继续其它的动作,通常接下来会执行到/etc/rc.d/rc程序。以运行级别3为例,init将执行配置文件inittab中的以下这行:<br /><br /> l5:5:wait:/etc/rc.d/rc 5<br /><br /> 这一行表示以5为参数运行/etc/rc.d/rc,/etc/rc.d/rc是一个Shell脚本,它接受5作为参数,去执行 /etc/rc.d/rc5.d/目录下的所有的rc启动脚本,/etc/rc.d/rc5.d/目录中的这些启动脚本实际上都是一些链接文件,而不是真正的rc启动脚本,真正的rc启动脚本实际上都是放在/etc/rc.d/init.d/目录下。而这些rc启动脚本有着类似的用法,它们一般能接受 start、stop、restart、status等参数。<br /><br /> /etc/rc.d/rc5.d/中的rc启动脚本通常是K或S开头的链接文件,对于以以S开头的启动脚本,将以start参数来运行。而如果发现存在相应的脚本也存在K打头的链接,而且已经处于运行态了(以 /var/lock/subsys/下的文件作为标志),则将首先以stop为参数停止这些已经启动了的守护进程,然后再重新运行。这样做是为了保证是当 init改变运行级别时,所有相关的守护进程都将重启。<br /><br /> 至于在每个运行级中将运行哪些守护进程,用户可以通过chkconfig或setup中的"System Services"来自行设定。常见的守护进程有:<br /><br /> amd:自动安装NFS守护进程<br /> apmd:高级电源管理守护进程<br /> arpwatch:记录日志并构建一个在LAN接口上看到的以太网地址和IP地址对数据库<br /> autofs:自动安装管理进程automount,与NFS相关,依赖于NIS<br /> crond:Linux下的计划任务的守护进程<br /> named:DNS服务器<br /> netfs:安装NFS、Samba和NetWare网络文件系统<br /> network:激活已配置网络接口的脚本程序<br /> nfs:打开NFS服务<br /> portmap:RPC portmap管理器,它管理基于RPC服务的连接<br /> sendmail:邮件服务器sendmail<br /> smb:Samba文件共享/打印服务<br /> syslog:一个让系统引导时起动syslog和klogd系统日志守候进程的脚本<br /> xfs:X Window字型服务器,为本地和远程X服务器提供字型集<br /> Xinetd:支持多种网络服务的核心守护进程,可以管理wuftp、sshd、telnet等服务<br /><br /> 这些守护进程也启动完成了,rc程序也就执行完了,然后又将返回init继续下一步。<br /><br />第五部分:建立终端<br /><br /><br /><br /> rc执行完毕后,返回init。这时基本系统环境已经设置好了,各种守护进程也已经启动了。init接下来会打开6个终端,以便用户登录系统。通过按Alt+Fn(n对应1-6)可以在这6个终端中切换。在inittab中的以下6行就是定义了6个终端:<br /><br /> 1:2345:respawn:/sbin/mingetty tty1<br /> 2:2345:respawn:/sbin/mingetty tty2<br /> 3:2345:respawn:/sbin/mingetty tty3<br /> 4:2345:respawn:/sbin/mingetty tty4<br /> 5:2345:respawn:/sbin/mingetty tty5<br /> 6:2345:respawn:/sbin/mingetty tty6<br /><br /> 从上面可以看出在2、3、4、5的运行级别中都将以respawn方式运行mingetty程序,mingetty程序能打开终端、设置模式。同时它会显示一个文本登录界面,这个界面就是我们经常看到的登录界面,在这个登录界面中会提示用户输入用户名,而用户输入的用户将作为参数传给 login程序来验证用户的身份。<br /><br /> 第六部分:登录系统,启动完成<br /><br /> 对于运行级别为5的图形方式用户来说,他们的登录是通过一个图形化的登录界面。登录成功后可以直接进入KDE、Gnome等窗口管理器。而本文主要讲的还是文本方式登录的情况:<br /><br /> 当我们看到mingetty的登录界面时,我们就可以输入用户名和密码来登录系统了。<br /><br /> Linux的账号验证程序是login,login会接收mingetty传来的用户名作为用户名参数。然后login会对用户名进行分析:如果用户名不是root,且存在/etc/nologin文件,login将输出nologin文件的内容,然后退出。这通常用来系统维护时防止非 root用户登录。只有/etc/securetty中登记了的终端才允许root用户登录,如果不存在这个文件,则root可以在任何终端上登录。 /etc/usertty文件用于对用户作出附加访问限制,如果不存在这个文件,则没有其他限制。<br /><br /> 在分析完用户名后,login将搜索/etc/passwd以及/etc/shadow来验证密码以及设置账户的其它信息,比如:主目录是什么、使用何种shell。如果没有指定主目录,将默认为根目录;如果没有指定shell,将默认为/bin/bash。<br /><br /> login程序成功后,会向对应的终端在输出最近一次登录的信息(在/var/log/lastlog中有记录),并检查用户是否有新邮件 (在 /usr/spool/mail/的对应用户名目录下)。然后开始设置各种环境变量:对于bash来说,系统首先寻找/etc/profile脚本文件,并执行它;然后如果用户的主目录中存在.bash_profile文件,就执行它,在这些文件中又可能调用了其它配置文件,所有的配置文件执行后后,各种环境变量也设好了,这时会出现大家熟悉的命令行提示符,到此整个启动过程就结束了。<br /><br /> 希望通过上面对Linux启动过程的剖析能帮助那些想深入学习Linux用户建立一个相关Linux启动过程的清晰概念,进而可以进一步研究Linux接下来是如何工作的。<br /><br />***************************************************************************************<br />***************************************************************************************<br /><br /> 由于操作系统正在变得越来越复杂,所以开机引导和关机下电的过程也越来越智能化。从简单的DOS系统转移到 Windows NT系统,人们已经亲身感受到了这些变化——这已不仅仅是核心操作系统的启动引导和关闭了,还包括必须要同时启动或者关闭相当数量的服务项目。类似于 Windows NT,Linux系统启动过程需要打开的服务项目也是数量极大的。<br /><br /> 这里,我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤。<br /><br /> 加载内核<br /><br /> LILO启动之后,如果你选择了Linux作为准备引导的操作系统,第一个被加载的东西就是内核。请记住此时的计算机内存中还不存在任何操作系统, PC(因为它们天然的设计缺陷)也还没有办法存取机器上全部的内存。因此,内核就必须完整地加载到可用RAM的第一个兆字节之内。为了实现这个目的,内核是被压缩了的。这个文件的头部包含着必要的代码,先设置CPU进入安全模式(以此解除内存限制),再对内核的剩余部分进行解压缩。<br /><br /> 执行内核<br /><br /> 内核在内存中解压缩之后,就可以开始运行了。此时的内核只知道它本身内建的各种功能,也就是说被编译为模块的内核部分还不能使用。最基本的是,内核必须有足够的代码设置自己的虚拟内存子系统和根文件系统(通常就是ext2文件系统)。一旦内核启动运行,对硬件的检测就会决定需要对哪些设备驱动程序进行初始化。从这里开始,内核就能够挂装根文件系统(这个过程类似于Windows识别并存取C盘的过程)。内核挂装了根文件系统之后,将启动并运行一个叫做 init的程序。<br /><br /> 注意:在这里我们故意略去了Linux内核启动的许多细节,这些细节只有内核开发人员才感兴趣。如果你好奇的话,可以访问http://www.redhat.com:8080地址处的 “Kernel Hackers Guide”。<br /><br /> init进程<br /><br /> init进程是非内核进程中第一个被启动运行的,因此它的进程编号PID的值总是1。init读它的配置文件/etc/inittab,决定需要启动的运行级别(Runlevel)。从根本上说,运行级别规定了整个系统的行为,每个级别(分别由0到6的整数表示)满足特定的目的。如果定义了 initdefault级别,这个值就直接被选中,否则需要由用户输入一个代表运行级别的数值。<br /><br /> 输入代表运行级别的数字之后,init根据/etc/inittab文件中的定义执行一个命令脚本程序。缺省的运行级别取决于安装阶段对登录程序的选择:是使用基于文本的,还是使用基于X-Window的登录程序。<br /><br /> rc命令脚本程序<br /><br /> 我们已经知道,当运行级别发生改变时,将由/etc/inittab文件定义需要运行哪一个命令脚本程序。这些命令脚本程序负责启动或者停止该运行级别特定的各种服务。由于需要管理的服务数量很多,因此需要使用rc命令脚本程序。其中,最主要的一个是/etc/rc.d/rc,它负责为每一个运行级别按照正确的顺序调用相应的命令脚本程序。我们可以想象,这样一个命令脚本程序很容易变得难以控制!为了防止这类事件的发生,需要使用精心设计的方案。<br /><br /> 对每一个运行级别来说,在/etc/rc.d子目录中都有一个对应的下级目录。这些运行级别的下级子目录的命名方法是rcX.d,其中的X就是代表运行级别的数字。比如说,运行级别3的全部命令脚本程序都保存在/etc/rc.d/rc3.d子目录中。<br /><br /> 在各个运行级别的子目录中,都建立有到/etc/rc.d/init.d子目录中命令脚本程序的符号链接,但是,这些符号链接并不使用命令脚本程序在 /etc/rc.d/init.d子目录中原来的名字。如果命令脚本程序是用来启动一个服务的,其符号链接的名字就以字母S打头;如果命令脚本程序是用来关闭一个服务的,其符号链接的名字就以字母K打头。<br /><br /> 许多情况下,这些命令脚本程序的执行顺序都很重要。如果没有先配置网络接口,就没有办法使用DNS服务解析主机名!为了安排它们的执行顺序,在字母S 或者K的后面紧跟着一个两位数字,数值小的在数值大的前面执行。比如:/etc/rc.d/rc3.d/S50inet就会在 /etc/rc.d/rc3.d/S55named之前执行(S50inet配置网络设置,S55named启动DNS服务器)。<br /><br /> 存放在/etc/rc.d/init.d子目录中的、被符号链接上的命令脚本程序是真正的实干家,是它们完成了启动或者停止各种服务的操作过程。当 /etc/rc.d/rc运行通过每个特定的运行级别子目录的时候,它会根据数字的顺序依次调用各个命令脚本程序执行。它先运行以字母K打头的命令脚本程序,然后再运行以字母S打头的命令脚本程序。对以字母K打头的命令脚本程序来说,会传递Stop参数;类似地对以字母S打头的命令脚本程序来说,会传递 Start参数。<br /><br /> 编写自己的rc命令脚本<br /><br /> 在维护Linux系统运转的日子里,肯定会遇到需要系统管理员对开机或者关机命令脚本进行修改的情况。有两种方法可以用来实现修改的目的:<br /><br /> ● 如果所做的修改只在引导开机的时候起作用,并且改动不大的话,可以考虑简单地编辑一下/etc/rc.d/rc.local脚本。这个命令脚本程序是在引导过程的最后一步被执行的。<br /><br /> ● 如果所做的修改比较细致,或者还要求关闭进程使之明确地停止运行,则需要在/etc/rc.d/init.d子目录中添加一个命令脚本程序。这个命令脚本程序必须可以接受Start和Stop参数并完成相应的操作。<br /><br /> 第一种方法,编辑/etc/rc.d/rc.local脚本,当然是两种方法中比较简单的。如果想在这个命令脚本程序中添加内容,只需要使用喜欢的编辑器程序打开它,再把打算执行的命令附加到文件的末尾就可以了。这对一两行的修改来说的确很便利。<br /><br /> 如果确实需要使用一个命令脚本程序,这时必须选择第二个方法。编写一个rc命令脚本程序的过程并不像想象中那么困难。我们下面就给出一个例子,看看它是怎样实现的(顺便说一句,你可以把我们的例子当作范本,按照自己的需要进行修改和添加)。<br /><br /> 假设你打算每隔60分钟调用一个特殊的程序来弹出一条消息,提醒自己需要从键盘前面离开休息一会儿,命令脚本程序将包括下面几个部分:<br /><br /> ● 关于这个命令脚本程序功能的说明(这样就不会在一年之后忘记它);<br /><br /> ● 在试图运行它之前验证这个命令脚本程序确实存在;<br /><br /> ● 接受start和stop参数并执行要求的动作。<br /><br /> 参数给定后,我们就可以编写命令的脚本程序。这个程序很简单,大家可以自己编写一下,我在这里就不给出了。<br /><br /> 编写好新的命令脚本程序之后,再从相关的运行级别子目录中加上必要的符号链接,来控制这个命令脚本程序的启动或者停止。在我的印象中,只想让它在运行级别3或者运行级别5中启动,原因是我认为只有这两个运行级别才是日常工作的地方。最后,希望这个命令脚本程序在进入运行级别6(重启动)的时候被关闭。<br /><br /> 激活或者禁止服务项目<br /><br /> 有的时候会发现,在引导的时候并不需要某个特定的服务被启动。如果你正在考虑使用Linux替换Windows NT的文件和打印服务器,就更是如此。<br /><br /> 我们已经知道,在特定的运行级别子目录中给符号链接改个名称,就可以让该服务不被启动,如把其名称的第一个字母由S改为K。一旦熟练掌握了命令行和符号链接,就会发现这是激活或者禁止服务的最快办法。<br /><br /> 在学习这个改名方法的时候,可能会觉得图形化的操作界面ksysv比较容易掌握。虽然它原来是设计使用在KDE环境里的,但在 Red Hat Linux 7.2下缺省安装的GNOME环境里也运行得很好。如果想启动它,只需简单地打开一个xterm窗口,并输入ksysv命令就可以了。屏幕上会出现一个窗口,其中列出了能够修改的全部参数,需要时还包括在线帮助。<br /><br /> 警告:如果是在一个现实中的系统上学习本文的知识,要多多运用常识。当试着对启动脚本程序进行修改的时候,要记住所做的修改可能会造成你的系统不能正常工作,而且无法采用重启动的方法恢复。不要在正常运转的系统上实验新的设置,对你准备修改的文件要全部进行备份。最重要的是,在手边要准备一张引导盘以防不测。 <br /><br />**************************************************************************************<br />**************************************************************************************<br /><br />1) 从BIOS到内核<br /><br /> BIOS自检<br /><br /> 计算机在接通电源之后首先由BIOS进行自检,即进行所谓的POST(Power On Self <br />Test),然后依据BIOS内设置的引导顺序从硬盘、软盘或CDROM中读入“引导块”。 在 PC 中,引导 Linux 是从 BIOS 中的地址 0xFFFF0 处开始的。BIOS 的第一个步骤是加电自检(POST)。POST 的工作是对硬件进行检测。BIOS 的第二个步骤是进行本地设备的枚举和初始化。给定 BIOS 功能的不同用法之后,BIOS 由两部分组成:POST 代码和运行时服务。当 POST 完成之后,它被从内存中清理了出来,但是 BIOS 运行时服务依然保留在内存中,目标操作系统可以使用这些服务。<br /><br /> 要引导一个操作系统,BIOS 运行时会按照 CMOS 的设置定义的顺序来搜索处于活动状态并且可以引导的设备。引导设备可以是软盘、CD-ROM、硬盘上的某个分区、网络上的某个设备,甚至是 USB 闪存。通常,Linux 都是从硬盘上引导的,其中主引导记录(MBR)中包含主引导加载程序。MBR 是一个 512 字节大小的扇区,位于磁盘上的第一个扇区中(0 道 0 柱面 1 扇区)。当 MBR 被加载到 RAM 中之后,BIOS 就会将控制权交给 MBR。<br /><br /> 提取 MBR 的信息<br /><br /> 要查看 MBR 的内容,请使用下面的命令:<br /><br /> # dd if=/dev/hda of=mbr.bin bs=512 count=1 # od -xa mbr.bin<br /><br /> 这个 dd 命令需要以 root 用户的身份运行,它从 /dev/hda(第一个 IDE 盘) 上读取前 512 个字节的内容,并将其写入 mbr.bin 文件中。od 命令会以十六进制和 ASCII 码格式打印这个二进制文件的内容。<br /> (2)启动GRUB/LILO<br /><br /> GRUB和LILO都是引导加载程序。最简单地讲,引导加载程序(boot loader) 会引导操作系统。当机器引导它的操作系统时,BIOS 会读取引导介质上最前面的 512 字节(即人们所知的 主引导记录(master boot record,MBR))。在单一的 MBR 中只能存储一个操作系统的引导记录,所以当需要多个操作系统时就会出现问题。所以需要更灵活的引导加载程序。<br /><br /> GRUB 与 LILO 的比较<br /><br /> 如本文开始处所述,所有引导加载程序都以类似的方式工作,满足共同的目的。不过,LILO 和 GRUB 之间有很多不同之处:<br /><br /> * LILO 没有交互式命令界面,而 GRUB 拥有。 <br /> * LILO 不支持网络引导,而 GRUB 支持。 <br /> * LILO 将关于可以引导的操作系统位置的信息物理上存储在 MBR 中。如果修改了 LILO 配置文件,必须将 LILO 第一阶段引导加载程序重写到 MBR。相对于 GRUB,这是一个更为危险的选择,因为错误配置的 MBR 可能会让系统无法引导。使用 GRUB,如果配置文件配置错误,则只是默认转到 GRUB 命令行界面。<br /><br /> 安全提示:<br /><br /> 关于安全性,任何可以接触到引导磁盘/CD 的人,只需要使用没有设置安全性的 grub.conf 或 lilo.conf,就可以绕过本文中提及的所有安全措施。特别是使用 GRUB 时,因为能够引导到单用户模式,所以是一个严重的安全漏洞。解决此问题的一个简单方法是在机器的 BIOS 中禁止通过 CD 和软盘进行引导,并确保为 BIOS 设置了一个口令,使得其他人不能修改这些设置。<br /> (3)加载内核<br /><br /> 当内核映像被加载到内存之后,内核阶段就开始了。内核映像并不是一个可执行的内核,而是一个压缩过的内核映像。通常它是一个 zImage(压缩映像,小于 512KB)或一个 bzImage(较大的压缩映像,大于 512KB),它是提前使用 zlib 进行压缩过的。在这个内核映像前面是一个例程,它实现少量硬件设置,并对内核映像中包含的内核进行解压,然后将其放入高端内存中,如果有初始 RAM 磁盘映像,就会将它移动到内存中,并标明以后使用。然后该例程会调用内核,并开始启动内核引导的过程。<br /><br /> GRUB 中的手工引导<br /><br /> 在 GRUB 命令行中,我们可以使用 initrd 映像引导一个特定的内核,方法如下:<br /><br /> grub> kernel /bzImage-2.6.14.2<br /> [Linux-bzImage, setup=0x1400, size=0x29672e]<br /><br /> grub> initrd /initrd-2.6.14.2.img<br /> [Linux-initrd @ 0x5f13000, 0xcc199 bytes]<br /><br /> grub> boot<br /><br /> Uncompressing Linux... Ok, booting the kernel.<br />如果您不知道要引导的内核的名称,只需使用斜线(/)然后按下 Tab 键即可。GRUB 会显示内核和 initrd 映像列表。<br /> (4)执行init进程<br /><br /> init进程是系统所有进程的起点,内核在完成核内引导以后,即在本线程(进程)空间内加载init程序,它的进程号是1。init进程是所有进程的发起者和控制者。因为在任何基于Unix的系统(比如Linux)中,它都是第一个运行的进程,所以init进程的编号(Process ID,PID)永远是1。如果init出现了问题,系统的其余部分也就随之而垮掉了。<br /><br /> init进程有两个作用。第一个作用是扮演终结父进程的角色。因为init进程永远不会被终止,所以系统总是可以确信它的存在,并在必要的时候以它为参照。如果某个进程在它衍生出来的全部子进程结束之前被终止,就会出现必须以init为参照的情况。此时那些失去了父进程的子进程就都会以init作为它们的父进程。快速执行一下ps -af 命令,可以列出许多父进程ID(Parent Process ID,PPID)为1的进程来。<br /><br /> init的第二个角色是在进入某个特定的运行级别(Runlevel)时运行相应的程序,以此对各种运行级别进行管理。它的这个作用是由/etc/inittab文件定义的。<br />(5)通过/etc/inittab文件进行初始化<br /><br /> init的工作是根据/etc/inittab来执行相应的脚本进行系统初始化,如设置键盘、字体, 装载模块,设置网络,等等。<br /><br /> 对于RedhatLinux来说,执行的顺序为: <br /><br /> * /etc/rc.d/rc.sysinit # 由init执行的第一个脚本<br /> /etc/rc.d/rc.sysinit主要做在各个运行模式中相同的初始化工作,包括:<br /> 设置初始的$PATH变量。<br /> 配置网络。<br /> 为虚拟内存启动交换。<br /> 设置系统的主机名。<br /> 检查root文件系统,以进行必要的修复。<br /> 检查root文件系统的配额。<br /> 为root文件系统打开用户和组的配额。<br /> 以读/写的方式重新装载root文件系统。<br /> 清除被装载的文件系统表/etc/mtab。<br /> 把root文件系统输入到mtab。<br /> 使系统为装入模块做准备。<br /> 查找模块的相关文件。<br /> 检查文件系统,以进行必要的修复。<br /> 加载所有其他文件系统。<br /> 清除几个/etc文件:/etc/mtab、/etc/fastboot和/etc/nologin。<br /> 删除UUCP的lock文件。<br /> 删除过时的子系统文件。<br /> 删除过时的pid文件。<br /> 设置系统时钟。<br /> 打开交换。<br /> 初始化串行端口。<br /> 装入模块。<br /> * /etc/rc.d/rcX.d/[KS]<br /><br /> 首先终止“K”开头的服务,然后启动“S”开头的服务。<br /><br /> 对每一个运行级别来说,在/etc/rc.d子目录中都有一个对应的下级目录。这些运行级别的下级子目录的命名方法是rcX.d,其中的X就是代表运行级别的数字。比如说,运行级别3的全部命令脚本程序都保存在/etc/rc.d/rc3.d子目录中。在各个运行级别的子目录中,都建立有到 /etc/rc.d/init.d子目录中命令脚本程序的符号链接,但是,这些符号链接并不使用命令脚本程序在 /etc/rc.d/init.d子目录中原来的名字。如果命令脚本程序是用来启动一个服务的,其符号链接的名字就以字母S打头;如果命令脚本程序是用来关闭一个服务的,其符号链接的名字就以字母K打头。许多情况下,这些命令脚本程序的执行顺序都很重要。如果没有先配置网络接口,就没有办法使用DNS服务解析主机名!为了安排它们的执行顺序,在字母S或者 K的后面紧跟着一个两位数字,数值小的在数值大的前面执行。比如:/etc/rc.d/rc3.d/S50inet就会在 /etc/rc.d/rc3.d/S55named之前执行。存放在/etc/rc.d/init.d子目录中的、被符号链接上的命令脚本程序是真正的实干家,是它们完成了启动或者停止各种服务的操作过程。当 /etc/rc.d/rc运行通过每个特定的运行级别子目录的时候,它会根据数字的顺序依次调用各个命令脚本程序执行。它先运行以字母K打头的命令脚本程序,然后再运行以字母S打头的命令脚本程序。对以字母K打头的命令脚本程序来说,会传递Stop参数;类似地对以字母S打头的命令脚本程序来说,会传递 Start参数。<br /> * 执行/etc/ec.d/rc.local<br /> Redhat Linux中的运行模式2、3、5都把/etc/rc.d/rc.local做为初始化脚本中的最后一个,所以用户可以自己在这个文件中添加一些需要在其他初始化工作之后,登录之前执行的命令。在维护Linux系统运转的日子里,肯定会遇到需要系统管理员对开机或者关机命令脚本进行修改的情况。如果所做的修改只在引导开机的时候起作用,并且改动不大的话,可以考虑简单地编辑一下/etc/rc.d/rc.local脚本。这个命令脚本程序是在引导过程的最后一步被执行的。<br /> * 执行 /bin/login 程式 <br /> <br /> login 程序会提示使用者需输入账号及密码, 接着编码并确认密码的正确性, 若二者相合, 则为使用者进行初始化环境, 并将控制权交给 shell,即等待用户登录。<br /> 多次为止Linux启动过程全部结束。<br /><br /> 最后笔者使用图1解释全部过程。<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_yq6h9C5ACgk/RqywdlnNaFI/AAAAAAAAAA0/v-UzwG38Z3M/s1600-h/image.php.jpg"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_yq6h9C5ACgk/RqywdlnNaFI/AAAAAAAAAA0/v-UzwG38Z3M/s320/image.php.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5092639301008451666" /></a><br /><br />总结:与 Linux 本身非常类似,Linux 的启动引导过程也非常灵活,可以支持众多的处理器和硬件平台。LILO 引导加载程序对引导能力进行了扩充,但是它却缺少文件系统的感知能力。最新一代的引导加载程序,例如 GRUB将更加灵活。wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-47268301875704631722006-11-14T05:44:00.000-08:002006-11-14T05:45:25.235-08:00重新装window后 grub的恢复1.下载<a href="http://www.box.net/public/uni3d9p6sy">grldr</a>到根目录下<br />2.在boot.ini里加入<br />c:\grldr="grub"<br /><br />加入后boot.ini大体如下<br />[boot loader]<br />timeout=30<br />default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS<br />[operating systems]<br />multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect<br />c:\grldr="grub"<br /><br /><br />3。重新启动,选择grub<br />然后enter command line<br /><br />然后 root (hd0<br />然后按tab,选择你的ubuntu安装分区,比如我是root (hd0,2),ext3分区的<br /><br />setup(hd0,0)<br /><br />重新启动,就ok了wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-33634042353897937112006-11-11T16:50:00.000-08:002006-11-12T04:10:59.132-08:00How to set default application for running a programjust revise the file<br />/usr/share/applications/defaults.list<br />for example:<br />application/pdf=AdobeReader.desktop<br />will set acroread as the default application when viewing pdf file<br />Don't forget make a backup file in the first place ^_^wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-16682009063850663752006-11-05T14:36:00.000-08:002006-11-05T14:38:29.548-08:00Emacs Tips (configuration of .emacs)<table width="100%"> <tbody><tr> <td width="90%"> <center> <h1>Emacs Tips & Tricks<br /><span style="font-size:85%;"><em>Power tools for Emacs users</em></span> </h1> </center> <center><i><br /> </i></center> <p> </p><center>This document is available at <a href="http://geosoft.no/development/emacs.html"> http://geosoft.no/development/emacs.html</a> </center> </td> </tr> </tbody></table> <hr size="1"> <table style="width: 680px; height: 8179px;" border="0" cellpadding="10" cellspacing="0"> <tbody><tr> <!-- ******************************************************************************* Document content on right hand side ******************************************************************************* --> <td> <ul><li><a href="http://geosoft.no/development/emacs.html#Basic%20Tips%20&%20Tricks">Basic Tips & Tricks</a> </li><li><a href="http://geosoft.no/development/emacs.html#File%20Finder">File Finder</a> </li><li><a href="http://geosoft.no/development/emacs.html#Buffer%20Switcher">Buffer Switcher</a> </li><li><a href="http://geosoft.no/development/emacs.html#Navigator">Navigator</a> </li><li><a href="http://geosoft.no/development/emacs.html#Scroller">Scroller</a> </li><li><a href="http://geosoft.no/development/emacs.html#Emacs%20for%20Programmers">Emacs for Programmers</a> </li><li><a href="http://geosoft.no/development/emacs.html#Emacs%20Links">Emacs Links</a> </li></ul> <!-- ******************************************************************************* Basic Tips & Tricks ******************************************************************************* --> <p> </p><hr size="1"> <p> </p><h2><a name="Basic Tips & Tricks"></a> Basic Tips & Tricks </h2> <p> </p><h3>Emacs initialization</h3> <p> When Emacs is launched, a specific <i>initialization file</i> is read. The initialization file can contain Emacs personal preferences like the functions and key bindings examples in this document. In addition it can contain default state settings for Emacs variables. Some examples are given below. </p><p> <code> (setq default-frame-alist (append (list<br /> '(width . 81) ; Width set to 81 characters<br /> '(height . 40)) ; Height set to 60 lines<br /> default-frame-alist))<br /></code> </p><p> <code> (setq inhibit-startup-message t) ; Don't want any startup message<br />(setq make-backup-files nil) ; Don't want any backup files<br />(setq auto-save-list-file-name nil) ; Don't want any .saves files<br />(setq auto-save-default nil) ; Don't want any auto saving<br /></code> </p><p> <code> (setq search-highlight t) ; Highlight search object<br />(setq query-replace-highlight t) ; Highlight query object<br />(setq mouse-sel-retain-highlight t) ; Keep mouse high-lightening<br /></code> </p><p> <code> (set-face-background 'region "yellow") ; Set region background color<br />(set-background-color "wheat3") ; Set emacs bg color<br /></code> </p><p> In the MS-Windows environment the initialization file should be called _EMACS and should be put in the root directory. In UNIX based systems the file should be called .emacs and should be put in the personal home directory. </p><p> </p><h3>Key bindings</h3> <p> For maximum typing and editing efficiency, as many keyboard keys as possible should be bound directly to Emacs functions. Some are already bound when Emacs is installed, but the great variety of keyboards and operating systems available makes it difficult for the Emacs team to pre bind functions in general. </p><p> To bind a function to a key, include a statement of the form </p><p> <code> (global-set-key key-name 'function-name) </code> </p><p> in the initialization file. <tt>key-name </tt> is either given as an actual name within brackets like <tt>[f1] </tt> for the F1 function key, or as <tt>"\C-q" </tt> or <tt>"\M-q" </tt> for a Control-key or Escape-key sequence respectively. </p><p> Remember that function that are <i>not</i> bound to a specific key or key sequence (actually this includes most functions) can always be accessed by typing </p><p> <code> Esc-x function-name<br /></code> </p><p> This document gives many examples of possible Emacs key bindings. Since the name of the keys may differ between keyboards and operating systems, the following approach can be used to find the name of a specific key. Enter </p><p> <code> Esc-x describe-key<br /></code> </p><p> and hit the key (or key combination) in question. This will reveal the name of the key as well as the function it is currently bound to. </p><p> </p><h3>Complete word</h3> <p> Emacs includes a very useful concept called <i>complete word</i>. Whenever in the minibuffer, it is always possible to hit the space bar to let Emacs try to complete the current input. This can save many key strokes and a lot of time. </p><p> For instance when looking for a file one can give one letter of a directory or a file name and, in case it is unique, Emacs will fill in the rest automatically. If it is not unique, Emacs will fill in as much as possible and return the different possible completions to let you choose between them. </p><p> </p><h3>The Emacs region</h3> <p> Emacs includes a powerful concept called a <i>region</i>. A region is like a marked area in a conventional word processor, but more useful in the way Emacs functions can be applied to it directly, for instance for sorting just a few lines of a file, or for printing a portion of a file. </p><p> A region is set implicitly by many Emacs functions, but can be set manually as well using <tt>Ctrl-Space</tt>. This specifies the current cursor position as one end of the region, called <i>the mark</i>. The cursor can then be moved around and its position will specify the other end of the region. </p><p> </p><h3>Cut, copy and paste key bindings</h3> <p> Based on the description of a region above, defining the common functions <i>Cut</i>, <i>Copy</i> and <i>Paste</i> on the region becomes very useful. The functions should be bound to keys for easy access, for instance like: </p><p> <code> (global-set-key [f5] 'copy-region-as-kill) ; Copy <br />(global-set-key [f6] 'kill-region) ; Cut <br />(global-set-key [f7] 'yank) ; Paste<br /></code> </p><p> An element that is cut or copied this way is put into something called the <i>kill-ring</i>. Calling the <tt>yank </tt> function always pastes the last entry from the kill-ring. However, after the yank function as called, it is possible to replace the pasted text by the second last entry in the ring and so on by calling the <tt>yank-pop</tt> (by default boud to the Esc-y key) function repeatedly. In effect, all cut/copy operations of the session is registered, and are easily accessible through this simple sequence of key strokes. </p><p> </p><h3>Column handling</h3> <p> A feature that are missing in most editors and word processors is the possibility to cut/copy and paste a vertical region of a file. In Emacs this is simple. The column to cut or copy is marked as a region as described above. It can then be cut calling the function <tt>kill-rectangle</tt> and re-pasted by <tt>yank-rectangle</tt> </p><p> </p><h3>Navigation key bindings</h3> <p> These are the basic navigation keys. Many keyboard come with two sets of these keys, so each function is bound once for each key. Some of these functions are usually already bound when Emacs is installed. </p><p> <code> (global-set-key [kp-home] 'beginning-of-buffer) ; [Home]<br />(global-set-key [home] 'beginning-of-buffer) ; [Home]<br />(global-set-key [kp-end] 'end-of-buffer) ; [End] <br />(global-set-key [end] 'end-of-buffer) ; [End] <br />(global-set-key [kp-prior] 'my-scroll-down) ; [PgUp]<br />(global-set-key [prior] 'my-scroll-down) ; [PgUp]<br />(global-set-key [kp-next] 'my-scroll-up) ; [PgDn]<br />(global-set-key [next] 'my-scroll-up) ; [PgDn]<br /></code> </p><p> </p><h3>Undo</h3> <p> Emacs has the most amazing undo facility. Anything you have typed since your session began is registered and can be undone. Since this obviously is a very useful function it should be bound directly to a key. Using the keypad [-] (subtraction) key for this purpose is convenient since it indicates the nature of the operation as well as being located so far away that it isn't easily accessed by accident. </p><p> <code> (global-set-key [kp-subtract] 'undo) ; [Undo]<br /></code> </p><p> </p><h3>Insert/overwrite mode</h3> <p> By default Emacs run in insert mode. This state can be toggled with overwrite mode, and is best bound to the Insert key(s) on the keyboard. </p><p> <code> (global-set-key [insert] 'overwrite-mode) ; [Ins] <br />(global-set-key [kp-insert] 'overwrite-mode) ; [Ins] <br /></code> </p><p> </p><h3>Goto line</h3> <p> To go to a specific line can be useful, especially when Emacs is used for programming. This common function can be bound to Ctrl-L by: </p><p> <code> (global-set-key "\C-l" 'goto-line) ; [Ctrl]-[L] <br /></code> </p><p> </p><h3>Window splitting</h3> <p> The Emacs window can be split so that is can display two or more buffers at the same time. This can be useful when comparing two files, or when editing two files simultaneously. Functions for managing window splits: </p><p> <code> (global-set-key [f2] 'split-window-vertically)<br />(global-set-key [f1] 'remove-split)<br /></code> </p><p> </p><h3>Frames</h3> <p> As well as displaying more than one buffer in a window, Emacs can also display more than one window (or <i>frames</i> as it is called in Emacs terminology). Creating and deleting frames can conveniently be done by binding the the functions as follows: </p><p> <code> (global-set-key "\C-f" 'make-frame) ; [Ctrl]-[F]<br />(global-set-key "\M-f" 'delete-frame) ; [ESC]-[F]<br /></code> </p><p> </p><h3>Getting information</h3> <p> Emacs contains lots of features and possibilities and it can be difficult to comprehend and utilize it all. However, Emacs comes with full documentation included. One of the more useful functions is <i>apropos</i>: </p><p> <code> [ESC]-x apropos </code> </p><p> This command prompts for a name or a concept and will return list of all functions or variables that relates to the entry given. This is a very useful approach for getting to know Emacs and the possibilities it contains. </p><p> Given an Emacs function or a variable it can sometimes be difficult to know exactly what it does. An explanation of a function or a variable can be obtained by: </p><p> <code> [ESC]-x describe-function<br />[ESC]-x describe-variable<br /></code> </p><p> They will prompt for a name and return a comprehensive description of it. </p><p> Similarly, as described above </p><p> <code> [ESC]-x describe-key<br /></code> </p><p> prompts for a key and returns the name of the key and the function it is currently bound to. <!-- ******************************************************************************* File Finder ******************************************************************************* --> </p><p> </p><hr size="1"> <p> </p><h2><a name="File Finder"></a> File Finder </h2> <p> This extension to the powerful Emacs complete-word facility is <em>the</em> major time saver for the frequent Emacs user. It is used within the find-file function and makes it possible to enter a given directory in the minibuffer by just entering a predefined two- to four letter sequence followed by the space key. Three different paths are given in the example below. The list can however be extended indefinetly. </p><p> <code> (defun geosoft-parse-minibuffer ()<br /></code> <code class="comment"> ;; Extension to the complete word facility of the minibuffer<br /></code> <code> (interactive)<br /> (backward-char 4)<br /> (setq found t)<br /> (cond<br /> ; local directories<br /> ((looking-at "..cd") (setq directory "c:/users/john/"))<br /> ((looking-at ".doc") (setq directory "c:/users/john/documents/"))<br /> ((looking-at "java") (setq directory "c:/users/john/src/java/"))<br /> (t (setq found nil)))<br /> (cond (found (beginning-of-line)<br /> (kill-line)<br /> (insert directory))<br /> (t (forward-char 4)<br /> (minibuffer-complete))))<br /></code> </p><p> The function is made an extension to the minibuffer complete-word function by: </p><p> <code> (define-key minibuffer-local-completion-map " " 'geosoft-parse-minibuffer)<br /></code> <!-- ******************************************************************************* Buffer Switcher ******************************************************************************* --> </p><p> </p><hr size="1"> <p> </p><h2><a name="Buffer Switcher"></a> Buffer Switcher </h2> <p> After a file has been loaded once, it is available in an <em>Emacs buffer</em>. Emacs is installed with lots of clever functions for fast retrieval of buffers. The function below is different however. It makes it possible to browse through the buffer list by single key-strokes only. It is also clever in its handling of the buffer stack in the way that the most frequent visited buffers (i.e. files) always are at the top of the stack. </p><p> <code> (defvar LIMIT 1)<br />(defvar time 0)<br />(defvar mylist nil)<br /><br />(defun time-now ()<br /> (car (cdr (current-time))))<br /><br />(defun bubble-buffer ()<br /> (interactive)<br /> (if (or (> (- (time-now) time) LIMIT) (null mylist))<br /> (progn (setq mylist (copy-alist (buffer-list)))<br /> (delq (get-buffer " *Minibuf-0*") mylist)<br /> (delq (get-buffer " *Minibuf-1*") mylist)))<br /> (bury-buffer (car mylist))<br /> (setq mylist (cdr mylist))<br /> (setq newtop (car mylist))<br /> (switch-to-buffer (car mylist))<br /> (setq rest (cdr (copy-alist mylist)))<br /> (while rest<br /> (bury-buffer (car rest)) <br /> (setq rest (cdr rest)))<br /> (setq time (time-now)))<br /></code> </p><p> The function is bound to a function key (for instance F4) by: </p><p> <code> (global-set-key [f4] 'bubble-buffer)<br /></code> </p><p> When you are definitely done with a buffer (i.e. a file) it can be convinient to remove it from the buffer stack. To silently remove the current buffer from the stack (and retrieve the next one on the stack), bind the following function to the Ctrl-Del key. </p><p> <code> (defun geosoft-kill-buffer ()<br /></code> <code class="comment"> ;; Kill default buffer without the extra emacs questions<br /></code> <code> (interactive)<br /> (kill-buffer (buffer-name))<br /> (set-name))<br /></code> </p><p> Bind by: </p><p> <code> (global-set-key [C-delete] 'geosoft-kill-buffer)<br />(global-set-key [C-kp-delete] 'geosoft-kill-buffer)<br /></code> <!-- ******************************************************************************* Navigator ******************************************************************************* --> </p><p> </p><hr size="1"> <p> </p><h2><a name="Navigator"></a> Navigator </h2> <p> For fast navigation within an Emacs buffer it is necessary to be able to move swiftly between words. The functions below change the default Emacs behavour on this point slightly, to make them a lot more usable. </p><p> Note the way that the underscore character is treated. This is convinient behaviour in programming. Other domains may have different requirements, and these functions should be easy to modify in this respect. </p><p> <code> (defun geosoft-forward-word ()<br /></code> <code class="comment"> ;; Move one word forward. Leave the pointer at start of word<br /> ;; instead of emacs default end of word. Treat _ as part of word<br /></code> <code> (interactive)<br /> (forward-char 1)<br /> (backward-word 1)<br /> (forward-word 2)<br /> (backward-word 1)<br /> (backward-char 1)<br /> (cond ((looking-at "_") (forward-char 1) (geosoft-forward-word))<br /> (t (forward-char 1))))<br /></code> </p><p> <code> (defun geosoft-backward-word ()<br /></code> <code class="comment"> ;; Move one word backward. Leave the pointer at start of word<br /> ;; Treat _ as part of word<br /></code> <code> (interactive)<br /> (backward-word 1)<br /> (backward-char 1)<br /> (cond ((looking-at "_") (geosoft-backward-word))<br /> (t (forward-char 1))))<br /></code> </p><p> Bind the functions to Ctrl-Left and Ctrl-Right with: </p><p> <code> (global-set-key [C-right] 'geosoft-forward-word) <br />(global-set-key [C-left] 'geosoft-backward-word) <br /></code> <!-- ******************************************************************************* Scroller ******************************************************************************* --> </p><p> </p><hr size="1"> <p> </p><h2><a name="Scroller"></a> Scroller </h2> <p> Scrolling without moving the cursor can be achieved by the functions: </p><p> <code> (defun scroll-down-keep-cursor ()<br /></code> <code class="comment"> ;; Scroll the text one line down while keeping the cursor<br /></code> <code> (interactive)<br /> (scroll-down 1))<br /></code> </p><p> <code> (defun scroll-up-keep-cursor ()<br /></code> <code class="comment"> ;; Scroll the text one line up while keeping the cursor <br /> </code> <code> (interactive)<br /> (scroll-up 1))<br /></code> </p><p> Bind the functions to the /-key and the *-key (on the numeric keypad) with: </p><p> <code> (global-set-key [kp-divide] 'scroll-down-keep-cursor)<br />(global-set-key [kp-multiply] 'scroll-up-keep-cursor)<br /></code> <!-- ******************************************************************************* Emacs for Programmers ******************************************************************************* --> </p><p> </p><hr size="1"> <p> </p><h2><a name="Emacs for Programmers"></a> Emacs for Programmers </h2> <p> </p><h3>Modes</h3> <p> During editing Emacs can be set in different <i>modes</i>. The mode has some knowledge about the structure of the document the user is working on, and can assist on the organization, formatting and editing of this. </p><p> This is particularly helpful when Emacs is used for programming, since programming languages in general has rigid sets of restrictions regarding document structure. For instance, programming statements are normally indented according to specific rules, and if the mode know the rules, it can do the indentation for the user automatically. </p><p> There exists modes for all major and minor programming languages and most types of documents such as HTML, Perl scripts, shell scripts, Unix Makefiles, CSS etc. The mode is automatically set by Emacs based on the name or the extension of the file edited. </p><p> </p><h3>Color coding</h3> <p> A very useful feature is Emacs' ability to render text with different colors and fonts. Emacs packages for color coding analyse the structure of the text and color the text according to the structure. For instance can programming comments get one color, reserved words a different color, function definitions yet another and so on. </p><p> A popular color coding package that comes with the standard Emacs distribution is <i>hilite</i>. To use it, include the following statement in the initialization file: </p><p> <code> (load "hilit19") </code> </p><p> During editing, it is in general impossible for the color coding package to color the text since the structure of the edited part of the document may not yet be complete. Beacuase of this, it is handy to be able to refresh the color coding manually. This is done with the function <tt>hilit-highlight-buffer</tt> which can be bound to a key combination for convenience. </p><p> </p><h3>Including predefined element skeletons</h3> <p> Many of the text elements that are used in programming has a standard form based on common skeletons. The ability to include skeletons like these with a single keystroke can be very useful and time efficient. </p><p> For instance, declaration and documentation comments in Java follow the rules dictated by the <i>javadoc</i> automatic documentation system. A typical javadoc method comment will look something like this: </p><p> <code class="comment"> /**<br /> *<br /> * Returns the character at the specified index. An index<br /> * ranges from <code>0</code> to <code>length()-1&</code><br /> *<br /> * @param index of the desired character<br /> * @return the desired character<br /> * @exeption StringIndexOutOfRangeExeption<br /> * if the index is not in the range <code>0</code><br /> * to <code>length()-1&</code>.<br /> * @see java.lang.Character#charValue()<br /> */<br /></code> <code> public char charAt(int index) {<br /> ...<br />}<br /></code> </p><p> To create a skeleton that can be included directly into a java source file, include the following LISP function in the Emacs initialization file: </p><p> <code> (defun javadoc-method-comment ()<br /></code> <code class="comment"> ;; Insert a javadoc method comment at the cursor position<br /></code> <code> (interactive)<br /> (insert<br />"/**<br /> *<br /> *<br /> *<br /> *<br /> * @param<br /> * @return<br /> * @exeption<br /> * @see<br /> */<br />")/<br /> (previous-line 8) <br /> (end-of-line)) <br /></code> </p><p> The function can be bound to a key by for instance: </p><p> <code> (define-key java-mode-map [f9] 'javadoc-method-comment) </code> </p><p> So hitting F9 will in effect include a javadoc method comment skeleton at the cursor position and move the cursor to the position within the comment where the description should start. </p><p> Along the same lines it is easy to predefine a large number of code elements, for instance <i>while loops</i>, <i>if-then-else</i> constructions, <i>file headers</i> etc. and make them available by single key strokes or key combinations. <!-- ******************************************************************************* Emacs Links ******************************************************************************* --> </p><p> </p><hr size="1"> <p> </p><h2><a name="Emacs Links"></a> Emacs Links </h2> <ul><p> </p><li> Emacs home page<br /> <a href="http://www.emacswiki.org/cgi-bin/wiki"> http://www.emacswiki.org/cgi-bin/wiki </a> <p> </p></li><li> Download Emacs<br /><a href="ftp://prep.ai.mit.edu/pub/gnu/emacs"> ftp://prep.ai.mit.edu/pub/gnu/emacs </a> <p> </p></li><li> Emacs online manual<br /><a href="http://www.cl.cam.ac.uk/texinfodoc/emacs_toc.html"> http://www.cl.cam.ac.uk/texinfodoc/emacs_toc.html </a> <p> </p></li><li> JDE - A free Java IDE based on Emacs<br /><a href="http://jdee.sunsite.dk/"> http://jdee.sunsite.d</a> </li></ul> <!-- ******************************************************************************* Footer common for all pages ******************************************************************************* --> <table width="100%"> <tbody><tr> <td> <br /></td> </tr> </tbody></table> </td> </tr> </tbody></table>wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-62158197713895411772006-10-19T12:40:00.000-07:002006-10-19T12:45:03.070-07:00change the default display managerjust run<br />sudo dpkg-reconfigure gdm<br />and then select which display manager as the default display manager. For KDE, select kdm, for GNOME, corresponding gdm.<br />or change the file /etc/X11/default-display-manager<br />/usr/sbin/gdm<br />or<br />/usr/sbin/kdmwasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-89689616324300853832006-10-18T10:13:00.000-07:002006-10-18T10:16:47.554-07:00upgrade java 1.4 to 1.5<h4 id="head-21b44ff330436e9f387606a337f458a3c2113a3e">Ubuntu 6.06</h4> <ul> <li><p> Sun Java5: Install it from the <tt>Applications</tt> -> <tt>Add/Remove...</tt> menu making sure to check the unsupported and proprietary software checkboxes, or install the <tt>sun-java5-bin</tt> package. </p> </li><li class="gap"><p> Blackdown Java2 1.4 packages: Install the <tt>j2re1.4</tt> package, available in the <em>multiverse</em> repositories. Install it from the <tt>Applications</tt> -> <tt>Add/Remove...</tt> menu, or install the <tt>j2re1.4</tt> package. </p></li> </ul><br /><h4 id="head-b6030233763f831b1ff3a43e7ee3d804fd879ce5">Kubuntu 6.06</h4> <ul> <li><p> Sun Java5: Load up Konsole, and type: </p></li> </ul><br /><pre>sudo apt-get install sun-java5-bin<br /><br /></pre> <p>Accept the licence agreement that appears. </p> <p><img src="https://help.ubuntu.com/htdocs/ubuntu/img/icon-info.png" alt="{i}" height="16" width="16" /> Note: The license may not come up and will cause the package installation to fail, to fix this, do the following: </p> <ul> <li style="list-style-type: none;"><p>In a terminal, type </p> </li> </ul> sudo apt-get install libqt-perl sudo dpkg-reconfigure debconf <ul> <li style="list-style-type: none;"><p>The first command will install the needed package for debconf-kde counterpart. The second command will ask a few questions: For the first step, choose "kde". For the second step, choose "high". Then, to fix the packages that did not correctly install, do: </p> </li> </ul> sudo apt-get -f install <ul> <li style="list-style-type: none;"><p>then you are done. </p> </li> </ul> <ul> <li><p> Blackdown Java2 1.4 packages: Install the <tt>j2re1.4</tt> package, available in the <em>multiverse</em> repositories. Install it from the <tt>Applications</tt> -> <tt>Add/Remove...</tt> menu, or install the <tt>j2re1.4</tt> package. </p> </li> </ul> <p><img src="https://help.ubuntu.com/htdocs/ubuntu/img/icon-info.png" alt="{i}" height="16" width="16" /> <em>Note: Scroll down to "Selecting the default Java version" section to enable the JRE you have installed.<br /></em></p> <p><em>more information look up<br /></em></p> https://help.ubuntu.com/community/Javawasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-1161000108453686182006-10-16T04:53:00.000-07:002006-10-17T05:48:48.818-07:00How to add the installed application to the application menuHere we will install the Lumaqq in the directory /home/wason/tools and we will add a shortcut for the application menu of the category internet<br />In the first place, build a new desktop file for lumaqq<br />sudo emacs /usr/share/applications/LumaQQ.desktop <p>然后,在新增的文件内加入下面这几行<br />[Desktop Entry]<br />Name=LumaQQ<br />Comment=QQ Client<br />Exec=/home/wason/tools/LumaQQ/lumaqq<br />Icon=/home/wason/tools/LumaQQ/QQ.png<br />Terminal=false<br />Type=Application<br />Categories=Application;Network;</p> the Categories is independant which one you want to added, we could find corresponding catergory by look up exiested file in /usr/share/applications/wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-1160996464744888852006-10-16T03:29:00.000-07:002006-10-19T08:10:19.417-07:00Tips for change MAC ID, GRUB, install KDE, GNOME in Kubuntu and UbuntuTo change Mac IP, as far as I know there is two ways, one is temporarily change MAC, that means when reboot the system, the original MAC will be recovered. In this way, assume we will alter the MAC of eth0, we can do it by command<br />ifconfig eth0 down<br />ifconfig eth0 hw ether 00:10:11:11:11:22<br />ifconfig eth0 up<br /><br />if you want to reset your MAC IP permanently, you have to revise some system file. There are two way to do it as well.<br />1) add the following to the file /etc/rc.local<br />/etc/init.d/networking stop<br />ifconfig eth0 hw ether 00:10:11:11:11:22<br />/etc/init.d/networking start<br /><br />2)change some contents of the file /etc/network/interfaces, usually, it looks like<br />iface eth0 inet hdcp(static)<br />pre-up ifconfig eth0 hw ether 00:10:11:11:11:22<br />address 141.76.124.81<br />gateway 141.76.124.1<br />netmask 255.255.255.0<br /><br />for DNS, they are stored in /etc/resolv.conf in the format "nameserver [IP Address]", eg<br />nameserver <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://123.123.123.123/" target="_blank">123.123.123.123</a><br /><br />after this correction, restart the networking by<br />/etc/init.d/networking restart<br /><br /><br />My personal GRUB setting<br />/boot/grub/menu.lst<br /><br />## default num<br /># Set the default entry to the entry number NUM. Numbering starts from 0, and<br /># the entry number 0 is the default if the command is not used.<br />default 0<br />#if set 1, windows XP will be the default boot system<br /><br /># Set a timeout, in SEC seconds, before automatically booting the default entry<br /># (normally the first entry defined).<br />timeout 10<br /><br />title Ubuntu<br />root (hd0,1)<br />kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hda2 ro quiet splash<br />initrd /boot/initrd.img-2.6.15-23-386<br />savedefault<br />boot<br /><br />#(the following is the system default, but i remove it, and make it elegant)<br />#title Ubuntu, kernel 2.6.15-23-386 (recovery mode)<br />#root (hd0,1)<br />#kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hda2 ro single<br />#initrd /boot/initrd.img-2.6.15-23-386<br />#boot<br /><br />#title Ubuntu, memtest86+<br />#root (hd0,1)<br />#kernel /boot/memtest86+.bin<br />#boot<br /><br />### END DEBIAN AUTOMAGIC KERNELS LIST<br /><br /># This is a divider, added to separate the menu items below from the Debian<br /># ones.<br />#title Other operating systems:<br />#root<br /><br /><br /># This entry automatically added by the Debian installer for a non-linux OS<br /># on /dev/hda1<br />title Microsoft Windows XP<br />root (hd0,0)<br />savedefault<br />makeactive<br />chainloader +1<br /><br /><br />How to install KDE in ubuntu? Just to run the command<br /><b>sudo aptitude install kubuntu-desktop<br /><br /></b>how to install GNOME in Kubuntu?<b><br /></b><b>sudo aptitude install ubuntu-desktop<br /><br /></b>set the default display manager revise the file <b><span style="font-weight: bold;"><br /></span></b><i>etc/X11/default-display-manager<br /></i>For KDM, the file should read <i>/usr/bin/kdm</i>; for GDM, the file should read <i>/usr/sbin/gdm</i>wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0tag:blogger.com,1999:blog-36108996.post-1160994381982701022006-10-16T03:22:00.000-07:002006-10-17T05:48:48.694-07:00Purpose of this bloggerFor easily look up and check my notes of solution for the problems when use linux. By the way, I am using Ubuntu(Kubuntu) currently, and it work well in my Dell latitude C610.wasonhttp://www.blogger.com/profile/05166749463936913032noreply@blogger.com0