注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

My Unix World

不要迷恋Unix,Unix只是计算世界很小的一部分!

 
 
 

日志

 
 

转:Ctrl key combination & the magic SysRq  

2009-12-11 19:47:44|  分类: basic-linux |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

转一篇基础知识,原文名字:Linux tips and tricks

URL:http://www.cdrinfo.com/Sections/Reviews/Specific.aspx?ArticleId=19672

You probably know key combinations like Ctrl-C or Ctrl-Z. You'd be surprised to learn that there are quite a few more useful key combinations that you probably haven't heard of. Here are a few to keep in mind when working at the console (note: most of these should also work under Konsole or other GUI console):

  1. Ctrl-C (usually) sends the kill signal, which terminates a process abruptly.

  2. Ctrl-Z sends the stop signal, which stops process execution immediately, without terminating. Use “fg” or “bg” after that to restart the process of send it to the background. Ctrl-Y is an interesting variant, which stops process execution only when the process tries to read user input from the console.

  3. Ctrl-S is the scroll lock: when you have too much output scrolling quickly, you can use Ctrl-S to stop process output. You can then use Shift-PageUp/PageDown to scroll up and down and read it. Ctrl-Q resumes. Technically speaking, Ctrl-S and Ctrl-Q send the XON/XOFF terminal commands, that may be ignored in some cases. The Bash shell translates Ctrl-S to “search”, so it depends on where you are working.

  4. Ctrl-L clears the screen and positions the prompt at the top left corner. Use this if your screen has become garbled.

  5. Ctrl-A and Ctrl-E take you to the beginning and the end of the line, respectively. Home and End also work, but not always.

  6. Alt-F and Alt-B take you to the next or previous word, very useful if you're typing a long sequence of commands or a command with many arguments.

  7. Tab is probably the most useful key when using the shell. Tab will do filename completion, but also hostname completion, variable name completion and other useful things.

The X-Windows environment

There are a few key combinations that work under the X-windows server, regardless of whether you are under KDE or Gnome (or any other environment, for that matter):

  1. Ctrl-Alt-F1/F2... : switch to the corresponding character virtual console. This is meaningful only if you are running under the appropriate init level, otherwise you won't find a login prompt. You will need Alt-F7 to get back to X-windows (this depends on the kernel settings for the number of virtual consoles, could also be Alt-F9 or Alt-F11, for example).

  2. Ctrl-Alt-Backspace : Kill the X-server

  3. Ctrl-Alt- + or - : Cycle between resolutions, according to the xf86config file. You need to have multiple resolutions defined in your config file for this to work.

The Magic SysRq key

You need to enable the magic SysRq key during compilation of the kernel. Some distributions enable it by default. Otherwise you can simply compile the kernel yourself (easier than it seems, trust me) after enabling it under “Kernel Hacking”.

Once you have the SysRq key enabled, the following keystrokes will work (more can be found in the kernel documentation) :

  1. Alt-SysRq-S: emergency sync, tries to write all unsaved buffers

  2. Alt-SysRq-U: emergency remount read only for all file systems

  3. Alt-SysRq-E: send the terminate (15) signal to all processes except init

  4. Alt-SysRq-I: send the kill (9) signal to all processes except init

  5. Alt-SysRq-B: emergency IMMEDIATE reboot (unsafe, like pressing the reset button!)

  6. Alt-SysRq-K: emergency kill of all programs under the virtual console


When the system crashes, emergency sync, remount and reboot are a convenient way to ensure a relatively safe system reboot. The following sequence best emulates a normal software reboot : Alt-SysRq-S, 5 sec pause, Alt-SysRq-E, 5 sec pause, Alt-SysRq-S, 5 sec pause, Alt-SysRq-I, Alt-SysRq-S, 5 sec pause, Alt-SysRq-U, Alt-SysRq-B (the pauses and multiple syncs are a bit excessive, but better safe than sorry). If a console crashes really bad, emergency kill may remedy the situation and get you back to a login prompt.

Note that these commands are immediate and potentially unsafe, so only use as a last resort before doing a real hardware reset or something equally drastic. Also, bear in mind that the magic sysrq key can be used as a denial-of-service attack by malicious hackers/crackers, so don't enable it in servers that are particularly vulnerable and exposed to such threats.

Quitting Vim/Vi

I remember playing with various linux commands and applications back in the days when I was beginning to use linux. One of the most annoying ways to get stuck was inside the Vi/Vim editor, that captures the Ctrl-C and Ctrl-Z keystrokes. Although I'm sure there are several readers who think that Vi is the best thing since sliced bread, most people should just know how to exit, in case they accidentally get trapped inside it. Simply type “:q!”, without the quotation marks, of course.

Conclusion

So many things, so little time. Although the examples given above may at first seem to be daunting, I think that every linux user should at least try to use them. After a while, these make life seem so much easier that it will be definitely worth it. That being said, if you only had to know ONE key, Tab would be it. Trust me on this...

  评论这张
 
阅读(359)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017