Linux directory and file management

Linux directory and file management

1. Linux directory structure

The linux directory structure is a tree-shaped directory structure.
Root directory:
the starting point of all partitions, directories, and files.
In the entire tree-shaped directory structure, an independent "/" is used.

2. The role of common subdirectories

Subdirectory effect
/root Administrator's home directory
/home/xxx Home directory of ordinary users other than the root user
/bin Store binary files, all user-executable commands are actually a soft link, linked to /usr/bin
/sbin Store binary files, only administrator can execute management commands, soft link to /usr/sbin
/boot System kernel, boot file directory
/of the Store device files (CD-ROM, hard disk, etc.)
/etc Store configuration files for 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, soft link to /usr/lib
/usr Store system user tools and programs
/media Removable media mount point, such as U disk, optical drive, etc.
/proc File to store the information of the mapping system
/ mnt Directory for temporarily mounting storage devices
/opt The directory where the third-party application is installed
/tmp Temporary files stored in the system

Three. View the content of the file cat command

Display the content of the entire file directly.
cat [options]
Commonly used options for file names
-n: number all output lines.
-b: No numbering for blank lines.
-s: Replace all consecutive blank lines with one blank line.

Four. View the content of the file more command

The file content is displayed in pages in full screen mode.
more [Option] File name
operation method
Press Enter to scroll line by line.
Press space to page down.
Press b to page up.
Press q to exit.
Scroll down to the last page and exit automatically.
It is not possible to page up when combined with pipe symbol operation.

Five. View the content of the file less command

Same as the more command, but with more extended functions.
less [Options] File name
operation method
Page Up to page up, Page Down to page down.
Press the "/" key to find the content, "n" the next content, "N" the previous content.
You can scroll up and down line by line through the ↑ and ↓ arrow keys.
Other functions are basically similar to the more command.
Going down to the last page will not automatically exit.
Combined with the pipe operation, the page can be turned up.

6. View file content head and tail commands

head command: View part of the content at the beginning of the file (10 lines by default).
head -n file name (n is the number of lines)
tail command: View a small part of the content at the end of the file.
tail -n file name (n is the number of lines)
tail -f file name tracks the dynamic update of the content at the end of the file.

Seven. Statistical file content wc command

Count the number of words in the file and other information
wc [Options]
Commonly used options in the target file
-l: count the number of lines
-w: count the number of words (each space character is separated into a word)
-c: count the number of bytes

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

8. Retrieve and filter file content grep command

Find and display the line containing the specified character string in the file.
grep [Options]
Commonly used options for search condition target files
-i: case insensitive when searching.
-v: Display all lines that do not contain matching text.
-c: Only display the total number of matched rows.
-n: Display matching line and line number.
-e: Realize the matching of multiple search conditions, or the relationship.
-E: Supports the use of extended regular expressions, which is equivalent to the egrep command.
-o: Exact match, which means only match.
Search condition setting
The character string to be searched is enclosed in double quotation marks.
"^..." means beginning with...
"...$" means ending with...

Nine. Compression commands gzip, bzip2 commands

Make a compressed file:
gzip [-9] File name
bzip2 [-9] File name
Unzip the compressed file:
gzip -d file name.gz
bzip2 -d file name.bz2

The default extension of compressed files made by gzip is ".gz", and the original files are no longer retained.
The default extension of compressed files made by bzip2 is ".bz2", and the original files are no longer retained.
The value of the production command can be an integer between 1 (the fastest compression speed and the lowest quality) to 9 (the slowest compression speed and the highest quality). The default is 6, use "-9" to increase the compression ratio.

-d is used to decompress files, which is equivalent to using gunzip and bunzip2 commands.

Ten. Archive command tar command

Make archive file:
tar [option] archive file name source file or directory
release archive file
tar [option] archive file name-C target directory (specify decompression to the target directory)
Common commands
-c: create a package file in .tar format
-x :
Unzip the package file in .tar format -C: Specify the target folder to be released when decompressing
-f: Use archive files
-p: Keep the permissions of
files and directories when packaging -P: Keep the absolute paths of files and directories when packaging
-t: view the files in the package in a list
-v: output detailed information
-j: call the bzip2 program to compress or decompress
-z: call the gzip program to compress or decompress

11. Text editor vi commands

The role of the text editor: create or modify text files, maintain various configuration files in the Linux system.
The most commonly used text editor
vi in linux : the default text editor for UNIX-like operating systems.
vim: An enhanced version of the vi text editor.

Three working modes

Command mode, input mode, last line mode.
Command mode: After
starting the vi editor, it enters the command mode by default. This mode mainly completes related operations such as cursor movement, string search, and deletion, copying, and pasting of file content.
Input mode:
The main operation in this mode is to record the content of the file, and you can modify the text of the file or add new content. When in the input mode, the last line of the vi editor will appear "–INSERT–" status prompt message. Last
line mode: In
this mode, you can set the vi editing environment, save the file, exit the editor, and search for the contents of the file. Replace and other operations. When in the last line mode, a colon ":" prompt appears on the last line of the vi editor.
Schematic diagram of three working modes
Insert picture description here

Command mode to switch to input mode

a: Insert content after the current cursor position
i: Insert content before the current cursor position
o: Insert a new line content below the line
where the cursor is O: Insert a new line content above the line where the cursor is
A: Insert content in the line where the cursor is Insert content
at the end of the line I: Insert content at the beginning of the line

Operation and function in command mode

Page up and move:
Page Down key or Ctrl + F:
scroll down a whole page of content
Page Up key or Ctrl + B:
scroll up a whole page of content
to quickly jump within the line:
home key or ^ key, number 0 key:
jump the Bank's first trip to
the End key or $
jump to the Bank's end of the line
to quickly jump between the lines
1G or gg
first line of the file content Jump to the
G
to jump to the first line of the file contents
#G
Jump to Line # of the file (where "#" is replaced with a specific number)
M
Jump to the middle of the current page to
display the line number:
set nu displays the line number
in the editor
set nonu
cancels the line number displays
delete
x or Delete key
deletes the cursor a single character at
dd
delete the current cursor line (shear function)
#dd
delete rows beginning with # from point
d ^
deleted before the current cursor to the beginning of the content
d $
delete the current point to the end of the line content
dw
Delete the entire word replacement character at the cursor

R or shift + r
replace the character at the current cursor
copy
yy
copy the entire line of the current line to the clipboard
#yy
copy the content of the # line starting from the cursor,
paste
P
paste under the line where the cursor is located
p
paste above the line where the cursor is located
Find
/word
paste under the line where the cursor is located
? word
from the current cursor at the beginning of the forward lookup
n
lower locating a search string match
N
search string matching positioning a
revocation
u
press cancel most recent operation; u key repeat, multiple restore operations
U
with To cancel all edits made to the current line,
save and exit
: w
save the modified content
: w new file name
save the modified content
: q
exit
: q!
abandon the modification of the file content and exit
zz or: wq,: x
save the current the contents of the file and exit the vi editor to
open a new file
: e different file name
to open a new file for editing
Read file content :
r
Read other file content in the current file
File content replacement
: s /old/new
Change the first string "o1d" found in the current line to "new"
: s /old/new /g
Replace all the string "old" found in the current line with "new"
: #,# s/old/new/g
replace all the string "old" in the range of line number "#,#" with "new"
:% s/old/new/g
replaces all the strings "old" with "new" in the entire file
: s /old/new/c
adds the c command at the end of the replacement command, and it will replace each The action prompts the user to confirm the
cut
: 8,11 m 4
Cut the contents of lines 8-11 to the 4th line and
copy below
: 8,11 co 4
Copy the contents of the 8-11 lines to the 4th line below
Tips
shift 3 + key combination
to highlight all the strings in the script file

Guess you like

Origin blog.csdn.net/Desire_cure_/article/details/113093685