This area is my sharing area. Include some technical/believing/life experiences. Hope you can enjoy with me. God bless you. :)
2009年9月22日 星期二
Linux Command - screen, change scrollback buffer
http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer/
GNU Screen: Working with the Scrollback Buffer
By Chris Pettitt | March 11th, 2007
GNU Screen is a UNIX tool that allows multiple console applications to be run, each in its own “window”, from the same terminal. In a single Screen session, you can run interactive shells, mail programs, SSH sessions, and other console based applications, and you can easily switch between these using hotkeys. You can even split up the Screen display so that multiple Screen windows can be viewed at the same time.
If you’ve never used Screen, but frequently use console applications, it is definitely a tool worth exploring. An introduction to Screen can be found on the Kuro5hin website.
In this article I share my experience with one of my favorite screen features: its scrollback buffer. As you interact with a Screen window, Screen stores a configurable number of lines of history in its scrollback buffer. The scrollback buffer makes it easy to browse or even search through the history of your windows. In addition, it makes it easy to copy and paste any section of text from the history.
Configuring the Scrollback Buffer
By default, the scrollback buffer only keeps the last 100 lines of text, which is not enough for my typical interaction with Screen. I’ve found a setting of 5000 lines to be more than adequate for my usage. The number of scrollback lines can be configured in your $HOME/.screenrc file, by adding the following line:
defscrollback 5000
This sets the scrollback to 5000 lines.
You can also override this default value when starting screen using the -h [num] option, where num is the number of scrollback lines.
Finally, if you want to change the number of lines of scrollback for a single window, using the “scrollback” command. Hit C-a (Ctrl-A) : to go to the Screen command line and type "scrollback num", where num is the number of scrollback lines.
How to do it?
1. Enter scrollback command mode: Ctrl+A :
2. change scrollback buffer size: scrollback num
You can check the number of scrollback lines in your window. Hit C-a i to display window information. You will see a status line with information similar to the following:
(27,42)/(186,42)+20 +flow UTF-8 3(bash)
In this case, my scrollback is 20 lines (it is displayed as +20 in the output above).
Entering Scrollback Mode and Navigating
To enter scrollback hit C-a [. A status line will indicate that you've entered copy mode. To exit scrollback mode, hit the escape button.
Navigating in scrollback mode will be pretty familiar to VI users. Here are some of the most common navigation keys (taken from the screen manpage):
h - Move the cursor left by one character
j - Move the cursor down by one line
k - Move the cursor up by one line
l - Move the cursor right by one character
0 - Move to the beginning of the current line
$ - Move to the end of the current line.
G - Moves to the specified line
(defaults to the end of the buffer).
C-u - Scrolls a half page up.
C-b - Scrolls a full page up.
C-d - Scrolls a half page down.
C-f - Scrolls the full page down.
I often use the page up and page down commands to quickly scroll back through the window's history.
In addition to traditional navigation, Screen allows you to search the scrollback buffer using the following commands:
/ - Search forward
? - Search backward
Search is a very useful feature. For example, you could run a script and search for keywords in the output (such as Error), without having to redirect the output.
Copy and Paste
Scrollback mode is also know as copy mode and it allows you to copy any section of text into a copy buffer. To copy text, move the cursor to the start of the text you want to copy, hit spacebar, move the cursor to the end of the text you want to copy (Screen will highlight the text to be copied as you move), and again hit spacebar. Screen will indicate the number of characters copied into the copy buffer.
To paste text, simply hit C-a ].
Copying to the Mac Clipboard
While copying and pasting in a terminal is very useful, I also find that I often want to copy some text from a terminal into my clipboard. This next tip will show you how to do this for Mac OSX, but I'm sure it can be easily modified to work with other operating systems.
Open $HOME/.screenrc and add the following line:
bind b eval "writebuf" "exec sh -c 'pbcopy < /tmp/screen-exchange'"
This line tells Screen to write its copy buffer to a temporary file (defaults to /tmp/screen-exchange), and then sends that file to pbcopy, a Mac OSX utility that copies text into the Mac clipboard. In this case, I’ve bound the command to C-a b, but you can change to best suit your own environment.
Conclusion
This wraps up my review of Screen’s scrollback buffer. I hope this tutorial is useful, especially to those that frequently work in terminal windows.
Do you have interesting ways of using Screen’s scrollback buffer, or Screen in general?
* How to delete scrollback buffer?
In the window whose scrollback you want to delete, set the scrollback to zero, then return it to its normal value (in your case, 15000).
If you want, you can bind this to a key:
bind / eval "scrollback 0" "scrollback 15000"
You can issue the scrollback 0 command from the session as well, after typing C-a :.
My experience
>> Show the scrollback buffer size
C+a i
will show the buffer size in the title
2009年9月1日 星期二
Linux Command - ls
# ls -la -h /root/
show the files sorted by the date reversely
# ls -latr
2009年8月26日 星期三
Linux debug by using strace
Another point is that you can find which configure file was opened by the specified program. Does the specified program open the wrong configuration files not as you expected?
# strace ./myprog -l 1234 -d 4
execve("./tsa", ["./myprog", "-l", "1234", "-d", "4"], [/* 53 vars */]) = 0
brk(0) = 0x9adb000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=108397, ...}) = 0
mmap2(NULL, 108397, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f7e000
close(3) = 0
open("/lib/libpthread.so.0", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 \30l\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=131528, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f7d000
mmap2(0x6bd000, 98784, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x6bd000
mmap2(0x6d2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14) = 0x6d2000
mmap2(0x6d4000, 4576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x6d4000
close(3) = 0
open("/lib/libm.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20\344h\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=210324, ...}) = 0
mmap2(0x68b000, 163952, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x68b000
mmap2(0x6b2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26) = 0x6b2000
close(3) = 0
open("/lib/libc.so.6", O_RDONLY) = 3
2009年8月24日 星期一
讓我們一起飛吧 張茂松 2008-06-08 賽40: 27~31
基督徒有
a. 禱告的翅膀
b. 信心的翅膀
c. 屬天的翅膀 (支取上帝的祝福)
d. 屬靈的翅膀
2. 跟雞在一起, 不知道可以飛
3. 因為從來沒用過翅膀, 所以不會飛
4. 因為害怕, 所以不敢飛
5. 因為沒願景, 就隨便飛
6. 沒熱情就懶的飛
7. 因為不在靈風中, 就靠自己飛
2009年8月13日 星期四
匈牙利命名法 (For reference)
變數名稱 = 屬性+類型+描述
屬性
" g_ 全域變數
" c_ 常數
" m_ 成員變數
類型
" n/ui int/unsigned int
" l/ ul long/unsigned long
" sh/us short/unsigned short
" f float
" d double
" ld long double
" ch char
" b boolean
" p pointer
" h handle
" str String
" w/dw WORD/DWORD
" b byte/unsigned char
" bl BOOL
描述
" Custom 自訂
" Src 來源
" Dst 目的
" Tmp 暫時
Other Reference:
| Prefix | Data Type | Prefix | Data Type |
| c | char, TCHAR | bt | TBYTE, BYTE, |
| uc | UCHAR | | |
| s | short | us | USHORT |
| w | WORD | n | int, INT |
| u | UINT | l | LONG, long |
| dw | DWORD | ul | ULONG |
| fl | float | db | double |
| b | BOOL | f | bitwise flag fields |
| sz | ANSI string, terminated with a \0 character. | psz | PSTR |
| h | HANDLE | hmem | HGLOBAL, HLOCAL |
| hwnd | HWND | hfile | HFILE |
| hdc | HDC | hpen | HPEN |
| hfont | HFONT | hbmp | HBITMAP |
| hpal | HPALETTE | hmenu | HMENU |
| hicon | HICON | hinst | HINSTANCE |
| hcur | HCURSOR | hbr | HBRUSH |
| pt | POINT | rc | RECT |
| tm | TEXTMETRIC | lf | LOGFONT |
| bmp | BITMAPINFO | pal | PALETTEENTRY |
| cls | WNDCLASS | msg | MSG |
| rgb | RGBQUAD | clr | COLORREF |
| of | OFSTRUCT | ps | PAINTSTRUCT |
| cb | count of bytes | cx, cy | length in pixels |
| p | added for pointer to any type, e.g., ps, pdw, phicon, pof, ..., etc. | a | added for array of any type, e.g., as, adw, auc, ... |
| C | a big C in front of all C++ class names, the rest of the class name is a mix of big and small letters | m_ | added in front of all C++ class member variables. |
| str | string | | |
| st | structure | | |
2009年8月3日 星期一
張茂松牧師 - 打造一個精品、塑造一個達人
1. 熟記
2. 思想
3. 禱告
4. 遵行
讀聖經時, 常常問為什麼?
如何預備被祝福?(汝矣島純福音教會主任牧師趙鏞基妻子 金聖惠總長)
1. 正向思考
2. 有異象, 異夢
3. 盡力去做
4. 倚靠聖靈
2009年7月14日 星期二
Show the memory usage of specified process id
# in the following examples, the 22405 is the process id
# top -p 22405
# pmap -d 22405
show memory details
# pmap -x 22405
b5fdb000 10240 - - - rw--- [ anon ]
b69db000 4 - - - ----- [ anon ]
b69dc000 10240 - - - rw--- [ anon ]
b73dc000 4 - - - ----- [ anon ]
b73dd000 10240 - - - rw--- [ anon ]
b7ddd000 2048 - - - r---- locale-archive
b7fdd000 8 - - - rw--- [ anon ]
b7fe6000 28 - - - r--s- gconv-modules.cache
b7fed000 16 - - - rw--- [ anon ]
bf972000 268 - - - rw--- [ stack ]
anon is a large size memory? [FIXME]