目录
1浏览及搜索文件系统
1、which
2、whereis
根据文件名搜索二进制文件、手册页文件或源代码文件。
格式: whereis [-bms] filename [...]
常用选项:
-b 只找二进制文件
-m 只找手册页文件
-s 只找源文件
示例
3、locate
在保存文档和目录名称的系统数据库(/var/lib/mlocate/mlocate.db)内查找文件名符合指定模式的文件。数据库中的条目一般每天自动更新一次。
2、阅读文本文件
1、cat
创建新文件
cat命令不带文件名参数时,接受标准输入作为其输出内容。
2、more & less
less
和more命令基本一样, 但功能更强。
基本操作按键
空格 向前翻页
b 向后翻页
k or ↑ 向上滚动一行
j or ↓ 向下滚动一行
/<word> 搜索<word>
q 退出
3、head & tail
tail
在屏幕上显示指定文件的开头若干行,默认10行。
option
-<num> 显示<num>行
3、编辑文本文件
1、vi
move cursor(command mode) | |
[NUM]h or Left Arrow(←) | move left(注:[NUM] is an optional digit,denotes the repetition times of the command。e.g., 10h means 10 characters to the left) |
[NUM]j or Down Arrow(↓) | move down |
[NUM]k or Up Arrow(↑) | move up |
[NUM]l or Right Arrow(→) | move right |
[Ctrl] + [f] or [PgDn] | scroll down one page |
[Ctrl] + [b] or [PgUp] | scroll up one page |
[Ctrl] + [d] | scroll down half a page |
[Ctrl] + [u] | scroll up half a page |
0 or [Home] | to the first character of the line |
$ or [End] | to the end of the line |
^ | to the first non-blank character of the line |
H | To the top line of window |
M | To middle line of window |
L | To bottom line of window |
G | to the last line of the document |
[NUM]G | to the NUMth line of the document |
gg | to the first line of the document. Equivalent to 1G. |
[NUM]<Enter> | Num lines down |
w | to next word |
b | to previous word |
find & replace(command mode) | |
/word | search forward for <word> from the cursor position. |
?word | search backward for <word> from the cursor position |
n | repeat the last searching. |
N | repeat the last searching, but in the opposite direction. |
find & replace(last line mode) | |
:n1,n2s/word1/word2/g | n1 and n2 are digit. n2 can be ‘$’ which denotes the last line. replace all word1 between line n1and line n2 to word2。 e.g., :20,30s/If/if/g |
: n1,n2s/word1/word2/gc | same as above. c means confirmation is required before replacing. Enter ‘y’ or ‘n’ to agree or deny the replacement. |
delete、copy & paste | |
[NUM]x或 [Delete] | delete <num> character under and after the cursor |
[NUM]X或 [Backspace] | delete <num> character before the cursor |
[NUM]dd | delete <num> line under and after the cursor |
dgg | delete all lines from the first line to the line under cursor. |
dG | delete all lines from the cursor to the last line |
d$ | delete all characters from cursor to the end of the line |
d0 | delete all characters from curosr to the first character of the line |
[NUM]yy | copy <num> line under and after the cursor |
ygg | copy all lines from the first line to the line under cursor |
yG | copy all lines from the cursor to the last line. |
y$ | copy all characters from cursor to the end of the line |
y0 | copy all characters from cursor to the first character of the line |
p | paste what copied to position after cursor or the line after cursor |
P | paste what copied to position before cursor or the line before cursor |
J | join the line under cursor and the line after cursor |
u | cancel the last operation. |
[Ctrl]+r | redo the operation canceled. |
. | redo the last operation. |
other commands (last line mode) | |
:w | |
:w! | |
:w [filename] | |
:r [filename] | |
:n1,n2 w [filename] | |
:! command | |
:set nu | |
:set nonu | |
:set ic | |
:set noic |
2、文本编辑器(gedit)
4、文件内容操作命令
1、grep
示例
2、sort
3、diff
tosort.txt
tosort2.txt
4、wc
5、文件的复制、移动、链接和归档
1、cp
或 cp [OPTION]... SOURCE... DIRECTORY
或 cp [OPTION]... -t DIRECTORY SOURCE...
或 cp [OPTION]... –r SOURCE_DIR DEST_DIR
或 cp [OPTION]... –a SOURCE_DIR DEST_DIR
2.mv
或 cp [OPTION]... SOURCE... DIRECTORY
或 cp [OPTION]... -t DIRECTORY SOURCE...
3、ln
4、tar
示例