Linux directory and file management
First, the Linux command base
Order category
Internal command: Refers to some unique instructions integrated in the Shell interpreter program, the internal command is part of the shell, there is no separate corresponding system files, as long as the shell is running, internal instructions automatically re-enter the memory, the user can be used directly, no need to read files from the hard disk, the execution of high efficiency.
External command: Refers to the Linux system to complete a specific function of the script file or binary program, each external command corresponding to a file, a command outside the shell interpreter, the Linux system must know the external command corresponding to the file location to be loaded and executed by the shell.
1.1 Shortcut keys
Tab:tab key is a common shortcut key, it is the function of the full file name or path. For example, enter "Cd/ho" in the Click Tab key, the terminal will show "Cd/home". If your folder, there are two names at the beginning of the same file, such as "Picture001.bmp" and "Picture002.bmp" two files, enter "rm pic" After pressing the TAB key, will be complete into "rm picture", You can then enter the remaining names. The use of tab completion also supports recognition of extensions, such as "Th2ad_chs.exe Files and Th2ad_chs.ini files" in your folder, when you enter "Wine TH" and then press TAB, will be completed "Wine Th2ad_chs.exe" Instead of filling out the. ini file because the wine and. exe files are associated.
CTRL + C: This key forces the end of the current process
Ctrl + C: Clear screen
Ctrl + A: Moves the cursor to the beginning of the command line.
Ctrl+e: Moves the cursor to the end of the life merriness.
Ctrl+u: Deletes the characters from the beginning of the line to the cursor.
Ctrl +k: Remove all characters from the cursor to the end of the line
CTRL + Z: Sends the current process to the background processing.
CTRL+ALT+F1: Switch to the first text terminal. You can have as many as six different terminals under Linux.
CTRL+ALT+F7: Switch to the first graphical user interface (generally X-window in the seventh terminal).
~:~ can't seem to be a shortcut, right? The role is to replace your home folder, such as your username is user, then "/home/user/desktop" and "~/desktop" is equivalent.
1.2 Linux command format
command word [options] [parameters]
Command word: The command name, the most critical part of the entire command
Options: Specific functions for adjusting commands
"-" To boot short format options (single character), such as "-L"
"--" to boot long format options (multiple characters), such as "--color"
Multiple short format options can be written together with only one "-" boot, such as "-al"
Parameters: Objects that command actions, such as files, directory names, and so on
1.3 Getting Help
The simplest and quickest way to use the command's online help function is to access books, manuals, and Internet queries for the specific format of the commands.
Use the Help command: View the helper information for each shell internal command. When used, only the name of the internal directive needs to be added as a parameter. Example: Help CD
Use the-help option: For most Linux external commands, you can use a common command option, "--help", to display helpful information such as the format and options of the corresponding command word. Example: CP--help
Use Man manual page: is a common form of online help, most of the external software at the time of installation for the execution of programs, configuration files provide a detailed help manual, the information in these manuals organized in a specific format, through a unified manual page browsing program man for review. Example: Man ls
Section 1.4 Common Commands
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/8C/3F/wKioL1hmfjyBcBuxAAPui5HmxDY010.jpg "title=" 18.jpg "alt=" Wkiol1hmfjybcbuxaapui5hmxdy010.jpg "/>
650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/8C/43/wKiom1hmflGBEsl-AAN6UjT22rA738.jpg "title=" 19.jpg "alt=" Wkiom1hmflgbesl-aan6ujt22ra738.jpg "/>
II. Management of directories and documents
1.1 Viewing and retrieving files
1.1.1 Viewing the contents of a file
Cat command: Display and connect the contents of a file
For example, view network card information:
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/8C/3F/wKioL1hmfsTiZzh1AAB3F4A_Vus249.jpg "title=" 1.jpg " alt= "Wkiol1hmfstizzh1aab3f4a_vus249.jpg"/>
1.1.2 More and less command ———— paging through the contents of a file
For example, view the contents of a httpd file
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/8C/43/wKiom1hmfy3jSvmxAAGAPUz2lkA849.jpg "title=" 2.jpg " alt= "Wkiom1hmfy3jsvmxaagapuz2lka849.jpg"/>
1.1.3 Head and tial command ——— view the beginning or end of a file
Head to see what's at the beginning of the file
Tail viewing the contents of a file can be combined with the-n option (n is the number of rows)
For example, view the/etc/passwd file after 5 lines (e.g.)
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/8C/3F/wKioL1hmf2GhUL_2AACMHW3G29g489.jpg "title=" 3.jpg " alt= "Wkiol1hmf2ghul_2aacmhw3g29g489.jpg"/>
Statistics and retrieval of file contents
WC command--statistics on the number of words in the file content, number of lines, etc.
-C: Statistics the number of bytes in the file contents
-L: Statistics the number of rows in the file contents
-W: Count the number of words in the file contents
For example, view the number of lines in a file/etc/passwd
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/8C/43/wKiom1hmhZ-hf9yoAAA3fEKDM7Y054.jpg "title=" 4.jpg " alt= "Wkiom1hmhz-hf9yoaaa3fekdm7y054.jpg"/>
grep command--Retrieve and filter file contents
Used to find and display lines in a file that contain a set of strings. You can specify a key string as a lookup condition, or you can use a responsible conditional expression (for example: "^word" means that word begins with "word$" means end with Word, "^$" represents a blank line).
Command format: grep [options] ... Find a conditional target file
Common options:-I ignores case when finding content.
-V Reverses the lookup, which outputs rows that do not match the lookup criteria.
For example, view text account information
650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/8C/3F/wKioL1hmhdnA6qbiAABOzU6p8KA687.jpg "title=" 5.jpg " alt= "Wkiol1hmhdna6qbiaabozu6p8ka687.jpg"/>
For example, filter out the comment information and blank lines that begin with "#" in the httpd file
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/8C/43/wKiom1hmhe-itRd0AACeeqfeCy0532.jpg "title=" 6.jpg " alt= "Wkiom1hmhe-itrd0aaceeqfecy0532.jpg"/>
Iii. Backup and Recovery documentation
3.1 Using the compression and decompression tool
Gzip and bzip2 when using the most two compression tools in the Linux system, both of these commands can compress the specified file, or the compressed files are uncompressed, the two algorithms are different, the use of the format is basically similar, generally speaking, GZIP2 compression efficiency is better.
3.1.1 Gzip and Gunzip commands
Gzip-made compressed files The default extension is ". Gz". When making compressed files, use the "9" option to increase the compression ratio. The original file will disappear.
For example, compress the Rhel-sourece.repo and view the size. After the decompression with gzip-d or using "gzip file name" to extract
650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/8C/3F/wKioL1hmhhjjV5MrAAEVWFhbNIY846.jpg "title=" 7.jpg " alt= "Wkiol1hmhhjjv5mraaevwfhbniy846.jpg"/>
3.1.2 bZIP and BUNZIP2 commands
The command usage is basically the same as the gzip, Gunzip command, with the bZIP compressed file with the default extension of ". bz2"
For example, compress the Rhel-sourece.repo and view the size. It is then decompressed with bzip2-d or by using "Bzip2 file name"
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/8C/43/wKiom1hmhjzR09g0AAEFWbQYetk344.jpg "title=" 8.jpg " alt= "Wkiom1hmhjzr09g0aaefwbqyetk344.jpg"/>
3.2 Using the TAR archive and release tools
The 3.2.1 Tar command is primarily used to archive directories and files, and in the actual backup effort, files are usually compressed (before the gzip or BZIP2 commands need to be called). When using the tar command, the "-" before the option can be omitted.
Common options:-C: Create a package file in. tar format
-C: Specify the target folder to release when extracting
-F: Indicates the use of an archive file
-P: Call BZIP2 Program for compression or decompression
-P: Preserve the absolute path of files and directories while packaging
-T: List view files in package
-V: Output details
-X: Unpack package files in. tar format
-Z: Call the gzip program for compression or decompression
The basic suitability of the TAR command is as follows
tar [options] Archive and compress file names source files or directories that need to be archived
For example, archive and compress package (backup) files.
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/8C/3F/wKioL1hmhm6gXiTjAADpWJ2f8kQ800.jpg "title=" 9.jpg " alt= "Wkiol1hmhm6gxitjaadpwj2f8kq800.jpg"/>
3.2.2 Recovering data from an archive file
When extracting and releasing (recovering) archive package files, the TAR command format is as follows
Tar command format tar [options] Archive and compress file names [-C target directory]
For example, archive compressed package after decompression
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/8C/3F/wKioL1hmhp-TBh9cAACuRxw__gM162.jpg "title=" 10.jpg "alt=" Wkiol1hmhp-tbh9caacurxw__gm162.jpg "/>
3.3 Using the VI text Editor
VI: Default text editor in Unix-like systems
The enhanced version of the Vim:vi editor, also known as the VI
Working mode of the 3.3.1 VI editor
Command mode: Launch VI editor default into command mode, mainly complete such as cursor movement, string lookup, and delete, copy, paste the contents of the file and other related operations
Input mode: The main operation is to enter the contents of the file, modify the text file or add new content.
Last-line mode: You can set the VI editor environment, save the file, exit the editor, and the contents of the file to find, replace and other operations. When in this mode, the last line of the editor appears with the colon ":" Prompt.
Basic operations in the 3.3.2 Command mode
Mode switch: In command mode, using A,i,o, the button can quickly switch to input mode.
When you return to command mode, press the ESC key.
A few common mode toggle keys and their functions
A: Inserts the content after the current cursor position.
A: Inserts the content at the end of the line (at the end of the line) of the cursor.
I: Insert content before the current cursor position.
I: Inserts the content at the beginning of the line where the cursor is located (at the beginning).
o: Insert a new line after the cursor line.
O: Insert a new line in front of the line where the cursor is located.
To move the cursor:
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/8C/43/wKiom1hmhvSCU9oFAADXVZ8XPi0434.jpg "title=" 11.jpg "alt=" Wkiom1hmhvscu9ofaadxvz8xpi0434.jpg "/>
Copy, paste, delete
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/8C/43/wKiom1hmhvSB7UGPAADGDrHKHBg866.jpg "title=" 12.jpg "alt=" Wkiom1hmhvsb7ugpaadgdrhkhbg866.jpg "/>
File Content Lookup
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/8C/3F/wKioL1hmhvXQZP8_AABuoBIKlJw628.jpg "title=" 13.jpg "alt=" Wkiol1hmhvxqzp8_aabuobikljw628.jpg "/>
Undo Edit and Save
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/8C/43/wKiom1hmhvWSPhrmAABxZuKm0jk585.jpg "title=" 14.jpg "alt=" Wkiom1hmhvwsphrmaabxzukm0jk585.jpg "/>
Save file and Exit VI Editor
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/8C/3F/wKioL1hmhvWSPhAhAACG-BP-niA785.jpg "title=" 15.jpg "alt=" Wkiol1hmhvwsphahaacg-bp-nia785.jpg "/>
Open a new file or read into another file
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/8C/3F/wKioL1hmhvXBT86SAABSA1cprKk006.jpg "title=" 16.jpg "alt=" Wkiol1hmhvxbt86saabsa1cprkk006.jpg "/>
File content Substitution
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/8C/43/wKiom1hmhvaS5aOdAAC0CinQgNU335.jpg "title=" 17.jpg "alt=" Wkiom1hmhvas5aodaac0cinqgnu335.jpg "/>
This article is from the "Jehau" blog, please be sure to keep this source http://daijiehao.blog.51cto.com/11959163/1887859
Linux directory and file management