1.
Following are the built-in shell variables and their descriptions:
- # : Specifies the number of arguments allocated to the current process.
- : Shows the option specified to the shell when it is invoked.
- ? : Shows the exit status of a specified command.
- $: Shows the process ID of a shell process.
- !: Shows the process ID of the last background command.
- CDPATH: Shows the list of directories to search the cd command.
- COLUMNS: Shows the width of the display in columns and lets you edit modes.
- EDITOR: Lets you edit modes.
- ERRNO: Shows the error number of a failed system call.
- ENV: Shows the name of the file run as an environment file.
- FCEDITL: Shows the default editor for the fc command.
- FPATH: Let's you search a path for an automated function.
- Internal Field Separator (IFS): Shows the list of symbols that act as word delimiters, such as space, tab, or a new line.
- HISTFILE: Shows the name of the command history file.
- OLDPWD: Shows the previous working directory.
2.
Input Mode Commands for the vi Editor
Command Key Combination | Command Name | Description |
I | Insert mode | Inserts text before the current cursor position. |
a | Append mode | Inserts text after the current cursor position. |
r | Replace mode | Replaces the character at the cursor, one character at a time. |
s | Replace and insert mode | Deletes the character on which the cursor is placed and overwrites it. |
I | Beginning line | Inserts text at the beginning of the line pointed by the cursor. |
A | Ending line | Inserts text at the end of the line pointed by the cursor. |
R | Overwrite | Overwrites the existing text. |
O | Blank line below | Inserts a single blank line below the line on which the cursor is currently placed. Enters the insert mode. |
O | Blank line up | Inserts a single blank line above the line on which the cursor is currently placed. Enters the insert mode. |
Commands to Control the Cursor in vi Editor
Command Key | Command Name | Description |
h | Move left | Moves the cursor one character left. |
l | Move right | Moves the cursor one character right. |
e | Move word | Moves the cursor to the end of the current word. |
w | Move word | Moves the cursor to the beginning of the next word towards the right. |
b | Move word | Moves the cursor to the beginning of the previous word towards the left. |
k | Move up | Moves the cursor to the previous line, one line at a time. |
j | Move down | Moves the cursor to the next line, one line at a time. |
0 | Move beginning | Moves the cursor to the beginning of the line. |
^ | Move beginning | Moves the cursor to the beginning of the first word of the line. |
$ | Move end | Moves the cursor to end of the current line. |
1G | Move first line | Moves the cursor to the beginning of the first line. |
NG | Move line | Moves the cursor to line n. |
G | Move last line | Moves the cursor to the beginning of the last line. |
{ | Scroll up | Scrolls up half the page. |
} | Scroll down | Scrolls down half the page. |
Scrolling Commands in vi Editor
Command Key Combination | Description |
Ctrl + f | Scrolls through the contents of the file one page up. |
Ctrl + b | Scrolls through the contents of the file one page down. |
Ctrl + u | Scrolls through the contents of the file half page up. |
Ctrl + d | Scrolls through the contents of the file half page down. |
Deletion Commands for vi Editor
Command Key Combination | Description |
dh | Deletes previous character, one character at a time. Enters the input mode after deletion. |
dl | Deletes next character, one character at a time. Enters the input mode. |
db | Deletes previous word, one word at a time. Enters the input mode. |
dw | Deletes next word, one word at a time. Enters the input mode. |
dd | Deletes entire line, one line at a time. This line is stored in the buffer and you can place it at the cursor position by the copy command. Enters the input mode. |
ndd | Deletes n lines. N numbers of lines are deleted. Enters the input mode. |
d$ | Deletes characters from the current cursor position until the end of line. Enters the input mode. |
d0 | Deletes characters form the current cursor position until the beginning of the line. Enters the input mode. |
Undo and Redo commands in vi Editor
Command Key combination | Description |
u | Undoes all the previous changes in the line. |
U | Undoes a single previous change in the line. |
. (period) | Redoes last change at current cursor position. |
y | Copies the text in the line on which the cursor is placed. |
p | Copies the line selected by the copy command after the cursor. |
P | Copies the line selected by the copy command before the cursor. |
Commands for Searching Text in the vi Editor
Command key Combination | Description |
?string | Matches the string with the text in the file, in back direction from the current cursor position. You need to place the string to match with the contents of the file after the question mark (?). |
/string | Matches the string with the text in the file, in forward direction from the current cursor position. You need to place the string to match with the contents of the file after the back slash (/). |
n | Repeats the search in the same direction as that of the previous search. |
N | Repeats the search in the opposite direction as that of the previous search. |
3.
In the Korn shell, an array variable is also called an indexed array. The Korn shell does not perform array-bound checks, which implies that an array can hold more array variables as the size of an array increases. Unlike other programming languages, such as C and C++, the Korn shell does not hold any junk value for an un-initialized array variable.
An index number represents each element of an array. The index number of the first element in an array is zero (0). The upper limit of the index is the total number of elements that an array variable can hold.
$ typeset -u number[6]
$ number[0]=70
$ echo ${number[0]}
$ firstname[0]="John"
$ echo ${firstname[0]}
Another method to assign values to an array is to assign all the values in a single statement. The syntax to assign values to multiple elements of an array in a single statement is:
$ set -A firstname "John" "Paul" "Smith"
You can access more than one value from an array in a single statement. The syntax to access multiple values from an array in a single statement is:
${variablename[*]}
The command to access the elements of an array is:
$ echo ${firstname[*]}
ksh histroy 列出所有历史命令
然后,r 命令号 即可执行选定的历史命令
Esc+k 列出上一条 Esc+\ 补齐
for username in $(cat $PASSWORD_FILE | cut -f1 -d:)
do
print $username
done
查看Solaris CPU个数:
prtdiag -v (还可看内存 top)
psrinfo -v
uname -X
sed -e '/^#/d' /etc/services | more
sed -e 's/foo/bar/g' myfile.txt
vi
w b 单词往前/后移动
{ } 句子往前/后移动
向前重复搜索,按 n 键。要向后搜索,按 N 键
输入 :w filename.txt 便可另存为 filename.txt
J 命令将下一行接到当前行行末。现在,将光标移到一个字符并敲 r,然后输入新字符;您将看到原字符被替换掉
3dd dw 4J
O (大写)在当前行上面生成一空行
d3w 将删除光标后 3 个单词,d2j 将删除当前行和下两行
对于 Korn Shell 用户,文件名完成取决于 EDITOR 变量的值。如果 EDITOR 设置为 vi,那么您键入部分名称,然后按 Esc 键,后跟反斜杠 (\) 字符。如果 EDITOR 设置为 emacs,那么您键入部分名称,然后按两次 Esc 键以完成文件名。
怎么拼? how do you spell?
查看操作系统是64位还是32位 isainfo -kv
No comments:
Post a Comment