Directory and file management
linux directory structure
Tree directory structure
Root directory
Position all the partitions, directories, files, and so the starting point
The entire directory tree structure, using a separate "/" represents
Common subdirectories
/ Root administrator's home directory (home directory)
/ Home general user's home directory (home directory)
/ Bin for all users executable command file directory
/ Sbin administrator can perform administrative command file directory
/ Boot system kernel, boot partition file (grub boot menu, the compressed kernel etc.)
/ Usr application directory
/ Etc directory profile
/ Var variable length file directory (for example: the log file, etc.)
/ Dev directory device files (disk / CD-ROM, etc.)
/ Tmp Temporary files
/ Proc Hardware information (CPU, memory)
/ Lib file management services (systemctl)
media multimedia files
View the file contents cat command
The cat command
Purpose: To display the contents of a file
cat [选项] 文件名...
Example:
[root@localhost ~]#cat /etc/hosts
[root@localhost ~]#cat /etc/sysconfig/network
[root@localhost ~]#cat /etc/sysconfig/network /etc/hosts
Short board: only see the last page content
Look at the file more command
more command
Uses: full screen page display file contents
more [options] filename ...
Interactive methods of operation:
Press Enter to scroll down line by line
Press the spacebar to turn down a
Press B to turn back
Press the Q key to exit
Short board: back to the last page can not be turned back
View the contents of the file less command
less command
Purpose: the more command the same, but more extensions
less [options] filename ...
Interactive method of operation
Use the Page Up and Page Down keys to flip
Press the "/" key to find the content, the next content on a content "n", "N"
Other features and more similar to the basic command
centos7 each command:
init 0 shutdown
(Used to maintain the system, to crack the code available) init 1 Single user mode character interface
init 2 Multi-User mode without network interface characters
init 3 Multi-User mode there is a network interface characters **
init 4 Reserved
init 5 multi-user mode graphical interface **
init 6 reboot (restart may reboot)
View the contents of the file head, tail command
head command
Uses: part of the beginning of the view files (the default is 10 lines)
head -n 文件名 (n行数)
tail command
Purpose: see the end of a small part of the file contents (default 10 lines)
tail -n 文件名...
or
tail -f 文件名
New users will be added to the end, so users can view the new file name directly tail -2
Statistical wc command file contents
wc command
Uses: The number of words in the file statistics (Word Count) and other information
wc [选项]… 目标文件…
Common command options
-l: count the number of rows
-w: count the number of words
-c: count the number of bytes
The difference with du
du statistical capacity is
wc statistics is content
** search and filter file content grep command
grep command (filtered)
Purpose: Finds and displays the line containing the specified string in the file
grep [选项]... 查找文件 目标文件
Common command options
-i: ignore case when searching
-v: reverse lookup, output does not match the search criteria row
Find the conditions set
To find the string in double quotes
"^ ......" indicates that begin with ...... "...... $" represents the end to ......
"^ $" Denotes an empty line
Filtering example:
reverse filtering example:
Ctrl + r prime search command
to find and count the number of files row to bash as the end of the (statistical number of users in the current system can not be logged on shell terminal)
Compression command gzip, bzip2 command
gzip command, the command bzip2 (zip can also be used, auxiliary)
Purpose: to make the compressed file, extract the zipped files
gzip [-9] 文件名...
bzip2 [-9] 文件名...
gzip -d .gz格式的压缩文件
bzip2 -d .bz2格式的压缩文件
Common command options
-9 indicates a high compression ratio of small files (source files after archiving directly attributed to the archive)
-d decompression (after decompressing the compressed packets directly did not, turn into a file)
gunzip command
gunzip equivalent to gzip -d
gunzip mkfile.gz
or
gzip -d mkfile.gz
bunzip2 command
bzip2 command and usage bunzip2 with gzip, gunzip command is basically the same
Archive command tar command
tar command
Purpose: Create archive files, archive files released
tar [选项]... 归档文件名 源文件或目录
or
tar [选项]... 归档文件名 [-C 目标目录]
Common command options:
-c create a compressed package
-x decompression
-v Displays detailed process
-f that the implementation of
-p preserving permits
-t View archive content
-C path is decompressed to go to sister
-z gzip format
-j bzip2 format
Example: a plurality of simultaneously compressed into a packet, the source file is also
extracted to Home, still compressed source
Vi text editor, command
The role of the text editor
Create or modify text files
Maintaining Linux systems in a variety of configuration files
Linux is the most common text editor
vi: UNIX-like operating system's default text editor
vim: vim is an enhanced version of the vi text editor (generally referred to as the vi editor) of
vi editing mode of operation
Three operating modes
Command mode: initial entry page
Input mode:
a (insert at the cursor position)
i (insert before the cursor position)
o (the next line is inserted at the cursor position)
O (in the row is inserted at the cursor position)
Esc to return to command mode
: Enter the last line mode
Line mode ":" (replaced, save and exit)
You need to go through the mode switching command as a transit mode
These different modes switching member
Move the cursor
: Set nu! Cancel also display line numbers
Copy, paste, delete (practical)
dw (delete world) to delete the word
Alternatively shift + r
Paste:
P (a large p) affixed to the cursor
p (small p) attached to the cursor
Uplink and downlink exchange: ddp
Find the file contents
Undo mark and save and exit
zz may be lowercase (equivalent to WQ)
The basic operation of the line mode
Save the file and exit the vi editor
Open a new file or read other file content
Replace the contents of the file
to sum up
- Using the cat, more, less, head, tail command to view the file
- Use wc, grep command statistics, retrieve file contents
- Using gzip, bzip2 command can create and release the compressed file, use the tar command can create or release archive, with "-z" "- j" option can also automatically call a compression tool