linux catalog program
- Linux directory
- Second, the command
-
- 1. View the content of the file --------cat
- 2. View the content of the file-------more
- 3. View the content of the file-------less
- 4. View the content of the file-----head, tail
- 5. The content of the statistical file--------wc
- 6. Retrieve and filter file content --------grep
- 7. Compression command--------gzip, bzip2
- 8. Archive command-------tar
- 9. File editor-------vi
Linux directory
1. Linux is the root of the tree directory
-The starting point of all partitions, directories, files, etc.
-In the entire tree-shaped directory structure, a separate "/" is used to indicate common subdirectories-
/root; /bin; /boot; /dev; /etc-
/home; /var; /usr; /sbin
Linux directory | effect |
---|---|
/root | Administrator's host (home) directory |
/home/xxx | Home directory of ordinary users |
/bin | Command file directory, store all user executable commands |
/sbin | Administrator operation directory, storing management commands that only administrators can execute |
/boot | System kernel, startup file directory |
/dev | Store device files (CD-ROM, hard disk, etc.) |
/etc | Store configuration files of system programs and most applications (rpm/yum installation) |
/where | Store files that can be changed, including various log files |
/lib | Store the dynamic link shared library file of the system program (similar to the DLL file in windows) |
/usr | Store system user tools and programs |
/media | Removable media attachment point, such as U disk, CD-ROM, etc. |
/proc | File to store the mapping system information |
/ mnt | Directory for temporarily mounting storage devices |
/opt | The directory where the third-party application is installed |
/tmp | Temporary files stored in the system |
Second, the command
1. View the content of the file --------cat
Format: cat [options] filename
Function: directly display the content of the entire file
Options | effect |
---|---|
-n | Number all output lines |
-b | Do not number blank lines |
-s | Replace all consecutive blank lines with one blank line |
2. View the content of the file-------more
Format: more [option] file name
Function: Full-screen display of file content in pages
Operation method | effect |
---|---|
Enter | Scroll down line by line |
space bar | Scroll down one screen |
b | Flip up one screen |
q | drop out |
3. View the content of the file-------less
Format: less [option] file name
Function: Less is the same as the more command, but less has more extended functions
Operation method | effect |
---|---|
Page Up | Page up |
Page Down | Page down/find content |
n | Next content |
N | Previous content |
↑ | Scroll up |
↓ | Scroll down |
Enter | Scroll down line by line |
space bar | Scroll down one screen |
b | Flip up one screen |
q | drop out |
4. View the content of the file-----head, tail
·head
Format: head -n file name (n is the number of lines)
Role: View part of the content at the beginning of the file (default is 10 lines)
·tail
Format:
tail -n file name
tail -f file name (tracking the dynamic update of the tail content of the file)
Role: View a small part of the content at the end of the file (10 lines by default)
5. The content of the statistical file--------wc
Function: Count the number of words in the file (word count) and other information
Format: wc [option] target file
Options | effect |
---|---|
-l | Statistics rows |
-w | Count the number of words |
-c | Count bytes |
If you enter the wc command without any options, the three options -lwc are used by default
6. Retrieve and filter file content --------grep
Format: grep [Options] Search condition target file
Function: Find and display the line including the specified string in the file
Options | effect |
---|---|
-i | Not case sensitive when searching |
-v | Display all lines that do not contain matching text (reverse query, reverse match) |
-n | Show matching line and line number |
-c | Only output the total number of matched rows (not the number of matched rows) |
-e | Realize the matching of multiple search conditions, logical or relationship |
-E | Support the use of extended regular expressions, which is equivalent to using the egrep command |
Search condition setting
– The string to be searched is enclosed in double quotation marks
– “^……” means it starts with…, “…$” means it ends with…
– “^$” means a blank line
7. Compression command--------gzip, bzip2
作用:制作压缩文件、解开压缩文件
压缩格式:
gzip [-9] 文件名
bzip2 [-9] 文件名
解压缩格式:
gzip -d .gz格式的压缩文件 等同于 gunzip 文件名.gz
bzip2 -d .bz2格式的压缩文件 等同于 bunzip2 文件名.bz2
8、归档命令-------tar
作用:制作归档文档、释放归档文件(就是用来制作备份的)
格式:
tar [选项] 归档文件名 源文件或目录
tar [选项] 归档文件名 [-C 目标目录]
选项 | 作用 |
---|---|
-c | 创建.tar格式的包文件 |
-x | 解开.tar格式的包文件 |
-C | 解压时指定释放的自标文件夹 |
-f | 表示使用归档文件 |
-p | 打包时保留文件及目录的权限 |
-P | 打包时保留文件及目录的绝对路径 |
-t | 列表查看包内的文件 |
-v | 输出详细信息、(Verbose ) |
-j | 调用bzip2程序进行压缩或解压 |
-z | 调用gzip 程序进行压缩或解压 |
9、文件编辑器-------vi
1)作用:创建或修改文本文件;维护Linux系统中的各种配置文件
2)linux中最常用的文本编辑器有两个:
vi:类似UNIX操作系统的默认文本编辑器
vim:vim是vi文本编辑器的增强版
3)工作模式
vi编辑器由三种工作模式:命令模式、输入模式、末行模式。
命令转输入
按键 | 作用 |
---|---|
a | 在当前光标位置之后插入内容 |
i | 在当前光标位置之前插入内容 |
o | 在光标所在行之下插入一个新行内容 |
O | 在光标所在行之上插入一个新行内容 |
A | 在所在行的行尾插入内容 |
I | 在所在行的行首插入内容 |
输入模式
操作类型 | 操作键 | 功能 |
---|---|---|
翻页移动 | Page Down健或Ctrl+F | 向下翻动一整页内容 |
Page Up键或Ctrl+B | 向上翻动一整页内容 | |
行内快速跳转 | Home键或^键、数字0键 | 跳转到本行的行首 |
End键或$键 | 跳转到本行的行尾 | |
行间快速跳转 | 1G或gg | 转到文件内容的第1行 |
G | 跳转到文件的最后一行 | |
#G | 跳转到文件中的第#行(其中"#”号用具体数字替换) | |
M | 跳转至当前页的中间位置 | |
显示行号 | : set nu | 在编辑器中显示行号 |
: set nonu | 取消行号 | |
显示删除 | x或Delete键 | 删除光标处的单个字符 |
dd | 删除当前光标所在行(有剪切功能) | |
#dd | 删除从光标处开始的#行内容 | |
d^ | 删除当前光标之前到行首的所有字符 | |
d$ | 删除当前光标处到行尾的所有字符 | |
dw | 删除光标处的整个单词替换字符 | |
R或Shift+r | 替换当前光标处字符 | |
复制 | yy | 复制当前行整行的内容到剪贴板 |
#yy | 复制从光标处开始的#行内容 | |
粘贴 | P | 粘贴到光标所在行之下 |
p | 粘贴到光标所在行之上 | |
查找 | / word | 从当前光标处开始向后进行查找字符串"word" |
?word | 从当前光标处开始向前进行查找 | |
n | 定位下一个匹配的被查找字符串 | |
N | 定位上一个匹配的被查找字符串 | |
撤销 | u | 按一次取消最近的一次操作; |
重复u键, | 恢复多步操作 | |
U | 用于取消对当前行所做的所有编辑保存退出 | |
: w | 保存修改的内容 | |
:w 新文件名 | 另存为其它文件 | |
:q:q! | 放弃对文件内容的修改并退出 | |
ZZ或:wq、:x | 保存当前的文件内容并退出vi编辑器 | |
打开新文件 | :e | 其它文件名打开新的文件进行编辑读入文件内容 |
:r | 其它文件名在当前文件中读入其他文件内容 | |
文件内容替换 | :s /old/ new | 将当前行中查找到的第一个字符串"old”串替换为"new" |
:s /old/ new/ g | 将当前行中查找到的所有字符串 “old”替换为"new” | |
:#,# s/old/ new/ g | 在行号"#,#”范围内替换所有的字符串 “old"为"new” | |
:% s/old/ new / g | 在整个文件范围内替换所有的字符串"old"为"new" | |
:s /old/new/ c | 在替换命令末尾加入c命令,将对每个替换动作提示用户进行确认 |