Today I learned the understanding of Linux commands and the basic commands for managing files and directories in a Linux system.
In Linux systems, a command is required to implement a function, and the execution of a Linux command relies on the shell command interpreter. The shell is a special program that runs on a Linux system, where the shell interpreter sits between the user and the kernel, the shell receives the user's commands and interprets them, and then passes the actions that need to be performed to the kernel to execute. Based on the relationship between the Linux command and the shell program, it is divided into internal commands and external commands.
Linux commands are case sensitive, format: command word [options] [parameters]
The following secondary operations can improve input efficiency:
TAB key: Auto-complete command, can uniquely locate a command word or file, directory name, otherwise you can press two times tab key;
Ctrl+u: Deletes all content before the current cursor;
Ctrl+k: Deletes all content from the current cursor to the end of the line;
Ctrl+l: Clears the contents of the current screen;
CTRL + C: Cancel the editing of the current command line, switch to a new command prompt;
------>u\k\l\c here should be lowercase (Linux is case-sensitive) <------
CTRL + A: Back to the front of the command line where the cursor is located
Ctrl+e: Return to the end of the command line where the cursor is located
(i) Help commands in Linux
Built-in commands in Help:shell, you can use "--help" as an option
Man: manual page, press Q or Q to exit the reading environment
Save the Man command's manual information as a text file
[[email protected] ~]# Man Mans | Col-b > Man.txt
Col: Removal of formatting control characters from the manual page
| : Pipeline, previous output as action object for subsequent commands
">": Redirect output, the previous command succeeds, save the result to the file after >
">>": Append redirect, continue writing in specified file, append to end of file
3.info: Similar to man, more detailed
(ii) directory Operations Command
PWD View current working directory
[Email protected] ~]# Pwd/root
2.CD Switch Working directory
Switch to the/home directory
[Email protected] ~]# cd/home [[email protected] home]#
Absolute path: Start with "/"
Relative path: Start with the current working directory, and use the directory name or file name directly to "." Start with a clear starting point with the current working directory, with ".." Beginning with the first level of the current directory as the starting point, "~ User name" starts with the specified user's host directory as the starting point
-----> Use ~ for the host directory switch, do not have to add a user name, you can directly use CD ~ to enter the corresponding user's host directory <-----
3.ls Displaying directory contents
-L: Display the contents of the/home directory in a long format
[Email protected] ~]# ls-l/Home
-A: Displays all directory and file information, including "." Hidden files at the beginning
[Email protected] ~]# ls-a/Home
-R: Recursively displays all contents of the specified directory and subdirectories
-H: Displays the size of the directory or file
4.mkdir Creating a new directory
-P: Recursive creation of multi-level catalogs
[Email protected] ~]# mkdir-p/media/cdrom
[Email protected] ~]# ls-r/media
/media:
CDRom
/media/cdrom:
5.du of statistical space occupancy
(iii) file operation commands
Touch to create a new file
Create two new files File1.txt and File2.doc
[email protected] ~]# Touch file1.txt File2.doc
2.file view file types, file extension no absolute relationship to type
View/etc/resolv.conf file types
[Email protected] ~]# file/etc/resolv.conf
3.CP Copying files or directories
-F Do not alert, force copy
-I Reminders
-R recursively copy all files and subdirectories
Copy the directory/boot/grub//etc/httpd/conf/to the current directory for backup
[Email protected] ~]# cp-r/boot/grub//etc/httpd/conf/.
4.RM Deleting files or directories
Corresponds to the CP command
Delete the Conf tree that was copied to the current directory without alerting the user
[Email protected] ~]# RM-RF./conf/
5.MV Moving files or directories
To transfer the GRUB directory in the current directory to the public_html directory
[Email protected]ocalhost ~]# MV Grub public_html
6.which find command files and where they are located
[[email protected] ~]# which LS
7.find Finding files or directories
-name Search by name, allow wildcard "*"? ”
[Email protected] ~]# find/etc-name "resol*.conf"
-user Search by Owner
[Email protected] ~]# find/var/log-user BBY
-type Find By Type
[Email protected] ~]# Find/boot-type D
Ordinary file F; directory D; block device file B; character device file C;
Use-A or-O (and, or) between expressions when using multiple find conditions at the same time
----->find command can be searched by time <----
8.ln Establishing links (symbolic links, hard links) cannot establish hard links to directories
-S creating Symbolic links
Create a symbolic link file for the file/etc/httpd/conf/httpd.conf and save it in the/etc directory
[Email protected] ~]# ln-s/etc/httpd/conf/httpd.conf/etc/
--->etc it seems to add a file name to ...<---
Configure a script file for the NIC/usr/sbin/sysconfig-config-network establish a hard-link file named Mynetconfig so that the network card parameters can also be configured through the Mynetconfig file
[Email protected] ~]# Ln/usr/sbin/sysconfig-config-network/sbin/mynetconfig
(iv) File content Operations Command
Cat Display file contents
View network card configuration information
[Email protected] ~]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0
More and less paging view
Head and tail View the beginning and end of a file
-n Specifies the number of rows
---->-f is real-time view <----
WC statistics Number of words
-C Statistics byte number
-L count rows
-W statistical number of words
grep filters the contents of a file to find a string directly or to use a conditional expression
-I ignores case
-V invert, the output does not match the search criteria
(v) Archiving and compression
Gzip and bzip2 compression and decompression
-9 Increased compression ratio
-D Decompression
Unzip the compressed file tfile.exe.gz using the gzip command
[Email protected] ~]# gzip-d tfile.exe.gz
Use bzip2 to compress the Tfile.exe in the current directory
[[email protected] ~]# bzip2-9 tfile.exe----> Specify the source file <----
Tar archive file
-C Create a. tar format package file
-X unpack the. tar format package file
-C Release to specified folder when unpacking
-F Using an archive file
-j using bzip2
-Z Using gzip
Compress the entire/etc Directory tree archive into a package file etc.tar.gz
[Email protected] ~]# tar zcvf etc.tar.gz/etc
Unzip and release the etc.tar.gz file into the/tmp directory
[Email protected] ~]# tar zxvf etc.tar.gz-c/tmp
★ (VI.) VI text Editor
Working mode
A. Command mode
Cursor movement, string lookup, and delete copy and paste file contents. Through a, I, O enter the input mode, through: Enter the last line mode
B. Input mode
Enter the contents of the file, modify the text file, and add new content. Enter Command mode with ESC
C. Last-line mode.
Set up the VI editing environment, save the environment, exit the editor, and find and replace the contents of the file. Enter Command mode with ESC
Command mode basic operation
A, I, O switch to input mode while determining the insertion point position
A: Insert after current cursor position
A: Insert at the end of the line where the cursor
I: Insert before current cursor position
I: Insert the line at the beginning of the cursor
o: Insert a new row after the cursor line
O: Insert a new line before the end of the cursor row
Ctrl+f PAGE DOWN ctrl+b page up
In-line jump "^" "0" cursor jumps to the beginning of the line "$" jump to the end of the row
Row jump "1G" "GG" jump to the first line of the file "G" jump to the last line of the file "#G" jump to the file # line
Copy "yy" to copy the entire line "#yy" copy the # line content starting from the cursor
Paste P
Delete "dd" Delete entire line "#dd" delete the # line content starting from the cursor
"d^" deletes the character before the current cursor to the beginning of the line
"D$" deletes the character at the end of the line at the current cursor
File content Lookup "/" after input string n, n select from search results
Undo Edit U: Cancel last u: Cancels all edits made to the current line
Need to save current content and exit ZZ
Last-line mode basic operation
A.:w Save (Save as: W file name/path)
B.:wq Save and exit (: X or by ZZ)
C.:q exit
d.:q! Do not save exit
E.:e opening a new file in the current file
F.:R read the new file and copy it to the current file
G.: [Scope] Sub/old content/new content [/g] file content substitution
Range:% replace entire file contents
N,m in the range of rows
/g: Replace all matching results on each line
H.:set nu Display line number: Set Nonu cancel line number
Permanent display line number, configure vim file [[email protected] ~]# VI ~/.VIMRC
Add set Nu to File
Linux basic commands-manage files and directories