Linux_ basic knowledge notes 4

1. Linux directory structure

Tree directory structure
Root directory

Insert picture description here

The starting point of all partitions, directories, files, etc. In the
entire tree-shaped directory structure, an independent "/" is used to indicate

Common directory functions:

Insert picture description here

2. cat view file content

  直接显示整个文件的内容
  cat 【选项】 文件名…
  适用于短小文件
[root@localhost /]# cat /etc/sysconfig/network

Common options:

-n Number of rows of all output
-b No number for blank lines
-s Replace all consecutive blank lines with one blank line

-n all output line numbers

[root@localhost ~]# cat -n abc.txt  ####所有输出的行数编号
     1	11
     2	22
     3	33
     4	55
     5	66
     6	
     7	
     8	
     9	
    10	
    11	
    12	99
[root@localhost ~]# 

-b does not number for blank lines

[root@localhost ~]# cat -b abc.txt
     1	11
     2	22
     3	33
     4	55
     5	66






     6	99
[root@localhost ~]# 

-s replace all consecutive blank lines with one blank line

[root@localhost ~]# cat -s abc.txt
11
22
33
55
66

99
[root@localhost ~]# 

Three. more View file content (more content)

Display file content in full screen mode
more [Option] File name...
Interactive operation method:

Press enter Scroll down line by line
Press spacebar Scroll down one screen
Press b Flip up one screen
Press q drop out
Scroll down to the last page will automatically exit
Cannot page up when there is a pipe

Four. less view file content

 与more命令相同,但扩展功能更多
  less 【选项】 文件名…

Interactive operation method:

Page Up Page up
page Dowm Page down
/ Find content
n Next content
N Previous content
Scroll up line by line
Scroll down line by line
Turning down to the last page will not automatically exit
It can be page up when combined with pipeline operation
Five. head, tail view file content
 head命令
 用途:查看文件开头的一部分内容(默认为10行)
 head -n 文件名… //n为行数

  tail命令
 用途:查看文件结尾的少部分内容(默认为10行)
  tail -n 文件名…
 tail -f 文件名 //跟踪文件尾部内容的动态更新

例:tail -f /var/log/messages

  [root@localhost ~]# tail -f /var/log/messages
Feb  3 09:52:40 localhost dbus[586]: [system] Activating service name='org.freedesktop.problems' (using servicehelper)
Feb  3 09:52:40 localhost dbus-daemon: dbus[586]: [system] Activating service name='org.freedesktop.problems' (using servicehelper)
Feb  3 09:52:40 localhost dbus[586]: [system] Successfully activated service 'org.freedesktop.problems'
Feb  3 09:52:40 localhost dbus-daemon: dbus[586]: [system] Successfully activated service 'org.freedesktop.problems'
Feb  3 09:52:47 localhost chronyd[639]: Can't synchronise: no selectable sources
Feb  3 09:52:47 localhost chronyd[639]: Selected source 144.76.76.107
Feb  3 09:52:47 localhost chronyd[639]: System clock wrong by -1.425282 seconds, adjustment started
Feb  3 09:53:51 localhost chronyd[639]: Can't synchronise: no selectable sources
Feb  3 09:53:53 localhost chronyd[639]: Selected source 84.16.73.33
Feb  3 09:54:55 localhost chronyd[639]: Selected source 94.237.64.20
Six. wc statistical file content
统计文件中的单词数量(Word Count)等信息
wc 【选项】… 目标文件…
常用命令选项:
-l Statistics rows
-w Count the number of words
-c Count bytes

Note: The wc command without any options uses the three options -lwc at the same time by default

Insert picture description here

[root@localhost ~]# wc -l abc.txt ########统计行数
12 abc.txt
[root@localhost ~]# wc -w abc.txt     ######统计单词个数
6 abc.txt
[root@localhost ~]# 
[root@localhost ~]# wc -c abc.txt   ###### 统计字节数
24 abc.txt
[root@localhost ~]# 
7. grep to retrieve and filter file content
 在文件中查找并显示包含指定字符串的行
 grep 【选项】… 查找条件 目标文件

Common command options:

-i Not case sensitive when searching
-v Show all lines that do not contain matching text
-c Only output the total number of matched rows
-n Show matching line and line number
-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
-The Exact match, which means "match only"

Search condition setting
The string to be searched is enclosed in double quotation marks.
1. "^……" means beginning with..., "...$" means ending with...

2. "^$" means blank line

8. gzip, bzip2-compression commands
制作压缩文件、解开压缩文件
gzip 【-9】文件名…
#gzip制作的压缩文件默认的扩展名为“.gz”,原始文件不再保留
bzip2 【-9】文件名… 
#bzip2 制作的压缩文件默认的扩展名为“.bz2”,原始文件不再保留

Use the "-9" option to increase the compression ratio
-d: used for decompression and compressed files, equivalent to using the gunzip, bunzip2 command
gunzip file name.gz
gzip -d file name.gz
bunzip2 file name.bz2
bzip2- d file name.bz2

Compressed file:

[root@localhost ~]# cd /data
[root@localhost data]# ls
123.txt  abc.txt
[root@localhost data]# gzip 123.txt
[root@localhost data]# ls
123.txt.gz  abc.txt
[root@localhost data]# bzip2 abc.txt
[root@localhost data]# ls
123.txt.gz  abc.txt.bz2
[root@localhost data]# 

unzip:

[root@localhost data]# ls
123.txt.gz  abc.txt.bz2
[root@localhost data]# gzip -d 123.txt   ###解压缩gzip文件
[root@localhost data]# ls
123.txt  abc.txt.bz2
[root@localhost data]# bzip2 -d abc.txt.bz2   #### 解压缩bzip2 文件
[root@localhost data]# ls
123.txt  abc.txt
[root@localhost data]# 
Nine. tar archive command
 制定归档文件、释放归档文件
tar 【选项】…归档文件名 源文件或目录
tar 【选项】…归档文件名【-C目标目录】

Common options:

-c Create a package file in .tar format
-x Unpack the package file in .tar format
-C Specify the target folder to be released when decompressing
-f Indicates the use of archive files
-P Preserve file and directory permissions when packaging
-p Keep the absolute path of files and directories when packaging
-t List the files in the package
-v Output detailed information
-j Call bzip2 program to compress or decompress
-with Call gzip program to compress or decompress

例:cd /etc/
tar -jcvf usershow.tar.bz2 passwd shadow
tar jxvf usershow.tar.bz2 -C /opt/

gzip compressed file: tar zcvf
decompressed file: tar zxvf

Gzip compressed file:
tar zxvf abc.tar .gz abc 123.txt

[root@localhost data]# ls
123.txt  abc.txt
[root@localhost data]# tar zcvf abc.tar.gz 123 abc.txt
[root@localhost data]# ls
123.txt  abc.tar.gz  abc.txt
[root@localhost data]# 

gzip to decompress the file:
[root@localhost data]# tar zxvf abc.tar.gz -C /opt

[root@localhost data]# tar zxvf abc.tar.gz -C /opt
[root@localhost data]# cd /opt/
[root@localhost opt]# ls
abc.txt  rh

bzip2 compressed file: tar jcvf
uncompressed file: tar jxvf

Nine. vi text editor
文本编辑器的作用:
  1. Create or modify text files
    2. Maintain various configuration files in the Linux system
linux中最常用的文本编辑器有两个:
  1. vi: The default text editor similar to the UNIX operating system
  2. vim: vim is an enhanced version of the vi text editor

The working mode of the Vi editor:
three working modes: command mode, input mode, and last line mode
. Switching between different modes:
Insert picture description here
command mode: the command mode is entered by default after starting the vi editor. This mode mainly completes such as cursor movement, String search, and related operations such as deleting, copying, and pasting file content

Input mode: The main operation in this mode is to input file content, and you can modify the text file body or add new content. When in input mode, the last line of the vi editor will show the status prompt message "-- INSERT --"

Last line mode: In this mode, you can set the vi editing environment, save the file, exit the editor, and perform operations such as searching and replacing the file content. When in the last line mode, a colon ":" prompt appears on the last line of the vi editor

Switch command mode to input mode:

a Insert content after the current cursor position
i Insert content before the current cursor position
The Insert a new line below the line where the cursor is
THE Insert a new line above the line where the cursor is
A Insert content at the end of the line
I Insert content at the beginning of the line

The command mode operation is as follows:

Insert picture description here

Guess you like

Origin blog.csdn.net/Wsxyi/article/details/113578177