A lot of fans to eweiguan message, want to learn Linux information, in fact, pay attention to eweiguan’s public number, the background reply 1024, there are a lot of very good e-books, but there is a problem, many fans are beginners, and this lot of e-books, it is estimated that just one, haven’t finished reading basically began to quit.
How do you get started with Linux?
Because Linux knowledge system is very large, many fields of IT industry need to use Linux, there are operation and maintenance, application development, driver development, system optimization, microcontroller, do system transplantation, do network products and so on.
In a word, a large part of IT practitioners need to master some knowledge of Linux, but because everyone is engaged in different fields, the requirements of Linux are not the same, which directly leads to, there are many kinds of online search learning routes, there are many recommended books are not conducive to beginners.
For example, Linux command learning, a lot of people are pushing “Bird brother’s private house dishes” this book, Yijun in the broadcast room repeatedly stressed that beginners should not read this book, not to say that the book is not good, but, in fact, this book you want to see as a reference book, if your goal is to quickly do some development work based on Linux, The most urgent thing is to quickly master some basic commands, some basic knowledge related to development, rather than learning commands that you may never use in your life.
In order to make beginners better learn Linux, Linux entry, one jun specially organized the Linux entry must master some basic knowledge, master these knowledge points, you can learn the knowledge of C programming, follow up with some unfamiliar commands and configuration, just need to search online can quickly start.
In the future, we will record the video of Getting started with Linux and teach you how to get started with Linux.
Welcome to visit my B station space, “learn Linux driver from 0” is being updated.
Here is the official account of Yikoupeng, welcome you to add my friend [Yikoupeng], pull you into the efficient technology discussion group, and discuss Linux related technology.
Overview of the Linux operating system
1, the development of
1991 Linus Linux version 0.0.1, 8K lines of code. The latest version is 5.12.4. Linux joins GNU, based entirely on the GPL, and allows open source, sharing, distribution, and modification.
Download the kernel from www.kernel.org/
Of 2,
- The kernel kernel:
Core program, used to manage hardware devices, system thread processes, memory, swap space, file system, Sprite process (daemon), etc. It mainly realizes the control and management function between system program and hardware.
- Shell:
The human-computer interface (HCI), wrapped outside the kernel, is used for interaction between the user and the kernel, similar to the Windows CMD. The input commands communicate with the kernel through the Shell so that the kernel can control the hardware and operate correctly.
There are different types of shells, such as Bourne Shell (SH), Korn Shell (KSH), C Shell (CSH), Bourne-Again Shell (bash), and TCSH. The most common of these are CSH and bash.
Ubuntu 16.04 terminal is as follows:
- user application
Linux according to the operation of the program, divided into user space and kernel space, simple to understand is that the common applications run in user space, some involved in the operation of the system core resource programs run in kernel space, such as TCP/IP protocol stack, drive, process scheduling, memory management, file systems are running in the Linux kernel space,
In fact, when some applications need to access system resources, they must copy system resources from kernel space to user space through system calls, through some kernel functions.
- Files System:
File system, manage files and directories.
3. Linux features:
Multi-user, multi-task (process, threading), multi-platform, graphical interface (X-Windows), low-configuration hardware, communication and networking, application support (editors, editing tools, databases, office software, graphics, Internet applications, games).
Install the Linux operating system
1. Choice of Linux
Red Hat: Enterprise, already charging (commercial).
CentOS is a clone of RHEL. RedHat has always provided source code distribution, while CentOS recompiles RedHat source code to a usable binary version. Since the source code for Linux is GNU, it is legal to obtain the source code from RedHat until it is compiled into a new binary. However, RedHat is a trademark, so it must be removed from the new distribution. CentOS is usually used to build the server.
Ubuntu: desktop open source, relatively pure Linux, Android official designated compiled operating system, fast development, has supported the ARM architecture. Ubuntu is so popular among developers that all of Our articles and videos focus on Ubuntu.
2. Install Ubuntu Desktop
Linux installation is a long process. For details, refer to this article: “Linux Environment Setup – Ubuntu16.04 Installation”.
3. Basic operations
CTRL + Alt + F2 To enter the terminal screen CTRL + Alt + F7 To enter the desktop screen CTRL + Alt + T to edit textCopy the code
We usually use the shortcut CTRL + Alt + T to open a terminal, this must be remembered.
Among them:
Peng Current user Ubuntu host name ~ current user home directory, /home/peng, each user will create a directory under /home with the same name as the user name $common userCopy the code
If you switch to administrator
Root administrator /home/peng Current working directoryThe current administrator is the administrator
Copy the code
Linux file system and file base
1. Overview of file systems
In Linux, everything is a file. The file system is a system used to organize the files and data of the computer. It is a system service program encapsulated by the operating system. File systems are classified as follows:
Disk file system: NTFS,EXT3 Flash file system: JFFS2,YAFFS Database file system: BFFS,WINFS Network file system: NFS Virtual file system: VFS (Proc)Copy the code
File system functions: can define the file organization, file structure; Provides an environment for creating and accessing files (directories and files)
2. Linux file systems and files
-
EXT3: a journaling file system. Each file in the system is indexed, and each user operation on the file is recorded in a log to form a task queue.
-
SWAP: a file system that swaps partitions. Similar to the Virtual memory of Windows, SWAP can be implemented in the following ways:
The first is to arrange memory like a memory pool and optimize it; The second is to simulate the space on the hard disk as memory. A Swap is a Linux virtual memory. Set the size to twice that of the physical memory during installation.
- The directory structure
The Linux structure is made up of many file blocks, unlike Windows partitions.
directory | File contents should be placed |
---|---|
/bin | The system has a number of directories to place executables, but /bin is special. Because /bin places instructions that can still be manipulated in single-player maintenance mode. The commands under /bin can be used by root and general accounts, including cat,chmod(modify permissions), chown, date, mv, mkdir, cp, bash, etc. |
/boot | Mainly place the files used by the open machine, including the Linux core file and the open machine menu and boot required configuration files, etc. The common file name of the Linux kernel is vmlinuz. If you use grub as the boot manager, there is also /boot/grub/. |
/dev | On Linux, any devices and peripherals are stored in this directory as files. By accessing a file in this directory, you are accessing a device. The most important files are /dev/null, /dev/zero, /dev/tty, /dev/lp*, /dev/hd *, /dev/sd*, etc |
/etc | The main configuration files of the system are almost all placed in this directory, such as personnel account and password files, the start files of various services and so on. In general, the file properties in this directory are viewable by normal users, but only root has the right to modify them. FHS recommends not putting executables in this directory. More important files are: /etc/inittab, /etc/init.d/, /etc/modprobe.conf, /etc/x11 /, /etc/fstab, /etc/sysconfig/, etc. /etc/init.d/ : this is where the default startup scripts for all services, such as to enable or disable iptables, are stored: /etc/init.d/iptables start, /etc/init.d/iptables stop |
/etc/xinetd.d/ | This is the profile directory for the services managed by the Super Daemon. |
/etc/X11/ | All the configuration files related to X Window are here, especially the xorg.conf or XF86Config X Server configuration files. |
/home | This is the default user home directory. When you add a general user account, the default user home directory will come here. More importantly, home directories have two codenames: ~ : the home directory of the current user, and ~guest: the home directory of the user named guest. |
/lib | There are a lot of libraries in the system, and /lib places libraries that are used when booting up, as well as those called by instructions under /bin or /sbin. What is a function library? You can think of it as a plug-in that some instructions must have in order to complete the execution of the program. Of particular importance is the directory /lib/modules/, because that’s where the core-related modules (drivers) are located. |
/media | Media is the English word for media, and as the name implies, the device placed under this /media is removable. Devices including floppy disks, compact discs, DVDS and so on are temporarily mounted here. Common file names are: /media/floppy, /media/cdrom, etc. |
/mnt | If you want to temporarily mount some additional devices, it is generally recommended that you place them in this directory. In ancient times, this directory was used for the same purpose as /media. However, with /media, this directory is used for temporary mounts. |
/opt | This is a directory for third-party collaboration software. What is third-party collaboration software? For example, the KDE desktop management system is a standalone project, but it can be installed on a Linux system, so it is recommended that the KDE software be placed in this directory. In addition, if you want to install additional software that is not originally provided by Distribution, you can also install your software here. However, on previous Linux systems, we used to place it in /usr/local. |
/root | Home directory of the system administrator (root) We put it here because if you mount only the root directory in single-person maintenance mode, that directory can have root’s home directory, so we want root’s home directory to be in the same partition as the root directory. |
/sbin | Linux has a lot of instructions for setting up the system environment, which only root can use to set up the system, other users can only use to query. Under /sbin is required during the boot process, including the boot, repair, restore the system required instructions. For some server software programs, it is generally placed in /usr/sbin/. The system binary is put into /usr/local/sbin/. Common instructions include: fdisk, FSCK, ifconfig, init, MKFS, etc. |
/srv | SRV is an abbreviation of Service. It is a directory of data that some network services need to access after they are started. Common services such as WWW, FTP and so on. For example, the web page information required by the WWW server can be placed in/SRV/WWW /. Hehe, it seems that the usual code we write should be put here. |
/tmp | This is where ordinary users or executing programs can temporarily place files. This directory is accessible to anyone, so you need to clean it up regularly. Of course, important information cannot be placed in this directory. FHS even suggests deleting all files in/TMP at boot time. |
3. Linux file attributes:
There are 7 types of Linux file attributes:
type | The letter | instructions |
---|---|---|
Common file type | – | The most common file type in Linux, including plain text files (ASCII); Binary; Data format files (data); Various compressed files. The first property is [-]. |
Directory file | d | This is the directory, accessed using the # CD command. The first attribute is [d], for example [DRWXRWXRWX] |
Block device file | b | Block device file: an interface device that stores data for system access. Simply put, it is a hard disk. For example, the code of disk 1 is /dev/hda1. The first attribute is [b] |
Character device | c | Character device files: Devices that interface with serial ports, such as keyboards, mice, and so on. The first attribute is [c] |
Socket file | s | Such files are commonly used for network data connections. You can start a program to listen for requests from the client, and the client can communicate data over the socket. The first attribute is [s], the file type most commonly seen in the /var/run directory |
Pipeline file | p | FIFO is also a special file type. Its main purpose is to solve the problems caused by multiple programs accessing a file at the same time. FIFO stands for first-in-first-out. The first attribute is [p] |
Link to the file | l | Similar to the shortcut below Windows. The first attribute is [l], for example [LRWXRWXRWX] |
1. Common documents
After running the ls -l command,The files in the first column whose first character is “-” are ordinary files.
2. Directory files
A directory in Linux is also a file. A directory file stores information such as the inode number and file name of other files in the directory. Each data item in a directory file is a link pointing to the inode number of a file. The font color of the directory file is blue. Run the ls -l command to view it. The first character is “D” (directory).
Directory file permissions:
- 1) r indicates that the directory file has readable permission, that is, you can use the ls command to view the storage status of the directory.
- 2) w indicates that the file in this directory has write permission, and you can add, modify, and delete files in this directory.
- 3) x indicates that the directory file has an executable file, that is, you can run the CD command to access the directory.
You can use the chmod directive to change file permissions.
3. Link files
A link file is usually a soft link (or symbolic link) of a file. Use the ls -l command to view the file. The first symbol is “L” and the file name is light blue, as follows:Test_softlink = test.txt; test_softlink = test.txt; test_softlink = test.txt; You can use the ln command to create a link file for a file:
1) Soft link Soft link (also known as symbolic link), run the ln -s file file_softlink command to create a softlink file of a file:
ln -s test.txt test_softlink
Copy the code
A soft link creates a shortcut for the original file. If the original file is deleted, the corresponding soft link file will also disappear.
2) Hard link Hard link is equivalent to giving an individual name to the original file. In fact, the two files are the same. If you delete one of the two files, the other one will not disappear. Make a change to either one and the contents of the other will change, because the two are essentially the same file with different names. Using the ls -i command, you can find that the inode numbers of the two hard links are the same.Similarly, you can create a hard link to a file using the ln command:
ln test.txt test_hardlink
Copy the code
4. Equipment files
Hardware devices in Linux, such as hard disks and mice, are also represented as files, that is, device files.
The device files are generally stored in the /dev/directory, and their names are yellow as follows:
There are two types of device files:
- 1) Block device files:
Block device files support access in blocks. In EXT4 file systems, a block is typically 4KB in size, which means it can access 4096 bytes (or an integer multiple of that) of data at a time. Application programs can randomly access data in block device files and determine the location of data by themselves. Hard disks and floppy disks are block devices. Using the ls -l command, the first character of the block device file is “b” (block).
- 2) Character device files:
The character device file is accessed as a byte stream, which is implemented by the character device driver, usually using system calls such as open, close, read, and write. Character terminals, serial ports, and keyboards are character devices. Also, because character device files are accessed as file streams, they can be read sequentially, but random access is generally not supported. Using the ls -l command, the first character of the character device file is “C” (char).
5. Pipeline file (FIFO file)
A pipe file is used for interprocess communication. Run the ls -l command to view the file. The first character is “p” (pipe). You can use the mkfifo command to create a pipe file:
mkfifo fifo_file
Copy the code
In FIFO can be very good to solve the requirements of data exchange between irrelevant processes, FIFO communication mode is similar to the use of files to transfer data in the process, but FIFO type of file at the same time has the characteristics of the pipeline, when reading data, FIFO pipeline at the same time clear data.
Socket files
Socket files, usually domain socket files, are viewed using the ls -l command with the first character “s”.
A domain socket is a method of interprocess communication (IPC). It is a reliable IPC communication. It is a component of the POSIX standard and can only be used for communication between the same host.
This knowledge is required for subsequent study of interprocess communication.
4. File color
Common file colors are as follows:
- Blue: directory files
- Green: executable file
- Light blue: Linked files
- Red: Compressed files
- Yellow: character device
- Grey: other files
4. Linux Operating system command usage
1. Command format
$command[option(s)] [argument(s)] Command name Space Option Space parameterCopy the code
- Command: indicates the name of a command
- [the option (s)] : options
- [argument (s)] : parameters
Note:
- On the command line, each two sections are separated by a space
- A maximum of 256 command characters can be used on each command line
- Commands are case-sensitive
- Use the separator “/” for different command prompts
- There can be multiple arguments/options in a command, and arguments are simply arguments passed to the main function of the command program.
- [] indicates that the value can be omitted, for example, [argument(s)]. You can enter the command without arguments
2. Online help, screen clearing and history command
1) Online help
When encountering some functions and commands, you can use the man command to view the help information.
man ls
man -k keyword
Copy the code
The MAN manual is divided into nine manuals. You can run the following command to view the manuals
man man
Copy the code
Man Category number of a document
1 - Commands (common commands) 2 - system calls 3 - Library calls 4 - Commands (common commands) 5 - File formats and convertions 6 - gamesforLinux (Games and Entertainment) 7-Macro Packages and Conventions 8-System Management Commands 9 - Other (Linux specific, used to store the documentation of kernel routines)Copy the code
With the -k parameter, MAN can search all MAN documents and profiles for commands that match the criteria.
peng@ubuntu:~/test$ man -k bash
bash (1) - GNU Bourne-Again SHell
bash-builtins (7) - bash built-in commands, see bash(1)
bashbug (1) - report a bug in bash
builtins (7) - bash built-in commands, see bash(1)
dh_bash-completion (1) - install bash completions for package
rbash (1) - restricted bash, see bash(1)
Copy the code
Some keywords in the system correspond to more than one manual, use the -f parameter, used to find the manual with the same name:
peng@ubuntu:~/test$ man -f time
time (7) - overview of time and timers
time (1) - run programs and summarize system resource usage
time (2) - get time in seconds
Copy the code
2) Clear the screen
To clear the screen, run the clear command or press CTRL + L
3) History (history-n)
This is a very useful command to use if you want to know all the commands you have typed before.
history: Displays a maximum of 500 commands used recentlyhistoryN: indicates the latest n commands used. N: Run the NTH command. : Run the first command recently. Up key: Run the previous command. Down key: Run the next commandCopy the code
5. Document management
1) View the file directory
Here are some of the most frequently used commands:
The command | instructions |
---|---|
pwd | Displays the current working directory |
CD [Directory to Change] | Change the directory |
ls | Lists the files and subdirectories of the current directory |
file | Identifying file types |
- cd
cd // Go back to the current user home directory
cd ~// Go back to the current user home directoryCD ~[Username]// Go to the specified user home directory
Copy the code
- file
Function description: Identify file type.
Syntax: file [-belvz][-f < name file >][-m < magic number file >... [File or directory...]Copy the code
Parameters:
-b The file name is not displayed when the identification result is listed. -c Displays the detailed command execution process for troubleshooting or analyzing the program execution. -f< name file > specifies a name file whose contents have one or more file names, so that file identifies these files in order, in the format of one file name per column. -l Displays the category of the file to which the symbolic link points. -m< Magic number file > Specifies the magic number file. -v Displays the version information. -z attempts to interpret the contents of the compressed file.Copy the code
Note: With the file directive, we can identify the type of file.
peng@ubuntu:~/test$ file wait.c
wait.c: ASCII text
peng@ubuntu:~/test$ file fifo_file
fifo_file: fifo (named pipe)
Copy the code
2) File path
What is the path to a file? It is the place where files are stored, which can be thought of as the “home” of files.
In Linux, there are absolute and relative paths:
Absolute path:
The path must be written from the root directory /, such as /usr/local/mysql
Relative path:
Paths are not written from the root directory /.
For example, first the user enters /home, then enters peng, and executes the command
#cd /home
#cd peng
Copy the code
In this case, the user path is /home/peng.
The first CD command is followed by /home, followed by a slash, which is the absolute path; The second CD command is followed by peng, which does not have a slash, to find the peng directory in the current directory. Peng is relative to /home, so it is called relative path.
3) Create and delete files and directories
1, create file touch
Function Description:
If the file name does not exist, create a new empty file. If the file name does exist, update the modified access time of the file or directory with the same contents.Copy the code
Grammar:
Touch [- delivered acfm per input horsepower] [-d < date/time >] [-r < > reference file or directory] t < date/time > [-] [-help][-- version][File or directory...] Or touch [- delivered acfm per input horsepower] [-help][-- version][Date time][File or directory...]Copy the code
Supplementary notes:
Use the Touch command to change the date and time of a file or directory, including access time and change time.
Parameters:
-A or time=atime or time=access or time=use Changes only the access time. -c or -no-create Indicates that no file is created. -d< date and time > uses the specified date and time instead of the current time. -f This parameter is ignored and only resolves compatibility problems with the BSD touch command. -m or -- time=mtime or -- time=modify Only changes the time. -r< reference file or directory > Sets the date and time of a specified file or directory to be the same as that of the reference file or directory. -t< date time > uses the specified date time instead of the current time. -helpOnline help. - version Displays the version information.Copy the code
2. Create directory mkdir
Function Description:
Build directoryCopy the code
Grammar:
The mkdir [-p] [-help][-m < directory properties >][directory name]Copy the code
Supplementary notes:
Mkdir You can create a directory and set the permission of the directory.
Parameters:
-m< directory properties > or -mode < directory properties > Sets the directory permission when creating a directory. -p or -parents If the upper level of the directory to be created has not been created, the upper level directory will be created as well. -helpShow help. - verbose Displays detailed information. - version Displays the version information.Copy the code
3. Delete the file rm
Function Description:
Delete a file or directory.Copy the code
Grammar:
The rm [- dfirv] [-help][-- version][File or directory...]Copy the code
Note: You can run the rm command to delete a file or directory. To delete a directory, you must add the parameter “-r”; otherwise, only files will be deleted by default.
Parameters:
-d or -directory Deletes the hard connection data of the directory to be deleted to 0 and deletes the directory. -f or -force Forcibly deletes a file or directory. -i or -interactive Ask the user before deleting an existing file or directory. -r or -r or -recursive processing, processing all files and subdirectories in a specified directory together. -v or - verbose Displays the command execution process. -helpOnline help. - version Displays the version information.Copy the code
4. Delete the directory
rmdir(remove directory)
Delete a directory.
Grammar:
Rmdir [-p] [-help] [- ignore - fail - on - non - empty] [" verbose] [version] directory [...].Copy the code
Note: The rmdir directive can be used when empty directories are to be deleted.
Parameters:
-p or -parents Deletes a specified directory. If the upper directory of the directory becomes empty, the parent directory is deleted. -helpOnline help. - ignore-fail-on-non-empty Ignores error information about a non-empty directory. - verbose Displays the command execution process. - version Displays the version information.Copy the code
3) Display file contents
1. cat
Function:
Connect the file string after passing it to the basic output screen or add > fileName to another fileCopy the code
Permission:
All usersCopy the code
Grammar:
The cat [- AbeEnstTuv] [-help] [version] fileNameCopy the code
Parameters:
-n or -number numbers all output lines starting with 1. -b or -number-nonblank is similar to -n, except that for blank lines it is not numbered. -s or -squeez-blank when there are more than two consecutive blank lines, Replace it with a blank line -v or -- show-nonprintingCopy the code
Example:
Cat -n textFile1 > textFile2 Add the line number to textFile1 and type textFile2 Textfile1 and TextFile2 file contents are appended with line numbers (blank lines are not appended) to TextFile3. TXT // Use the input redirection CRTL+D to end. Run the cat /dev/null > 1. TXT // to clear the output redirectionCopy the code
2. head
Function:
Find the first number of lines in the fileCopy the code
Grammar:
head [-n] filename
Copy the code
3. tail
Function:
The finder does not ask how many linesCopy the code
Grammar:
tail [-n] filename
Copy the code
4. more
Function:
Split screen displayCopy the code
usage
more filename
Copy the code
4) Copy and move file directories
1. cp
Function Description:
Cp Source file Destination file Copies a source file to a destination file or directory.Copy the code
Grammar:
Cp [-abdFilpPrrsuvx][-s < Backup character string >][-v < Backup mode >][-help] [- spares = use < time >] [version] [source file or directory] [the target file or directory] [destination directory]Copy the code
Note: the cp command is used to copy files or directories. If more than two files or directories are specified at the same time and the final destination is an existing directory, all the files or directories specified above will be copied to this directory. If multiple files or directories are specified at the same time and the final destination is not an existing directory, an error message is displayed.
2. mv
Function Description:
Mv [Source file, directory] [Destination file, directory] Moves or renames an existing file or directory.Copy the code
Grammar:
[- bfiuv] [mv -help[-- version][-s < add-on suffix >][-v < method >][Source file or directory][destination file or directory]Copy the code
Note: MV can move a file or directory or change the name of a file or directory.
Parameters:
-b or -backup backup files before overwriting them. -f or -force If the target file or directory is the same as an existing file or directory, the existing file or directory is overwritten directly. -i or -interactive Queries the user before overwriting. -s < appended suffix > or -suffix =< appended suffix > is used with the -b parameter to specify the appended suffix to the backup file. -u or -update When you move or change the file name, if the target file already exists and its date is newer than the source file, the target file is not overwritten. -v or -verbose Displays detailed information. -v =< method > or -version-control =< method > Is used with the -b parameter to specify the backup method. -helpShow help. - version Displays the version informationCopy the code
5) File and directory permissions
1. The permissions
File permissions:
For example, if you run the ls -l command, the first column of the result is in the form of -rwxrwxrwx. The first character “-” indicates that the file is a common file. It can also be other characters. The following string of characters indicates the permissions of the file, where:
-
1) r indicates that the file has readable permission. If the position is “-“, the file is unreadable.
-
2) w indicates that the file has the write permission. If the value is “-“, the file cannot be written.
-
3) x indicates that the file has the executable permission. If the position is “-“, the file does not have the executable permission.
-
4) The first RWX represents the owner’s permission on the file; The second RWX represents the permissions of the file’s owning group on the file; The third RWX represents other users’ permissions on the file.
2. Object to which the permission belongs
File owner: the current owner of a file or directory. The owner has the highest permission and is represented by U. User group to which a file belongs: one or more users in the same group assigned by the system administrator. Other people’s permissions on this file: people other than the owner and user group, denoted by O. Owner: the owner, owning user group, and other users are represented by a
-rwxr(owner) -xr(group) -x(others)Copy the code
3. Modify attribute chmod
Using the chmod command, you can modify the access permission of a file or directory. You must have the operational permission when you modify the permission.
(a) Who (U, G, O, and a) +cp (” = “Setting permission” + “Adding permission” – “deleting permission) + Permission (” R” reading permission “W” writing permission “x” operation permission) Example:
chmod g=wr 1.c;
chmod u+w,g-w,o=wr 1.c
Copy the code
(b) Express permissions in octal numbers
R w x 0 0 0 no permission 1 1 1 yes permission r: 4, w; 2,x:1Copy the code
Such as:
Chmod 777 build grants build permission to owner RWXCopy the code
Note: The default permissions for files created in Ubuntu are 664
4. Chown Changes the file owner and file group
The chown (change owner) command is used to set the owner and associated group of a file.
grammar
chown [-cfhvR] [--help] [--version] user[:group] file...
Copy the code
Parameters:
User: indicates the user ID of the new file owner. Group: indicates the user group of the new file owner. -C: displays information about the changed part. -f: ignores error messages. Handles all files in the specified directory and its subdirectories --help--version: Displays the versionCopy the code
/var/run/httpd.pid = root;
chown root /var/run/httpd.pid
Copy the code
5. CHGRP Changes the owning group of a file or directory
The Linux CHGRP (full: change group) command is used to change the owning group of a file or directory.
Unlike the chown command, CHGRP allows an ordinary user to change the group to which a file belongs, as long as the user is a member of that group.
grammar
chgrp [-cfhRv][--help][--version][Group][File or directory...] Or the CHGRP [- cfhRv] [-help[--reference=< reference file >][--version]Copy the code
Parameter Description:
-c or --changes has similar effects"-v"Parameter, but only the changed part is returned. -f or --quiet or --silent No error information is displayed. -h or --no-dereference only modifies symbolic linked files without changing any other related files. -r or --recursive processing, processing all files and subdirectories in the specified directory at once. -v or --verbose displays the command execution process. --helpOnline help. --reference=< Reference file or directory > Sets the owning group of the specified file or directory to be the same as that of the reference file or directory. --version Displays version information.Copy the code
Chown and chgroup are used infrequently.
6) find
Using the Linux find command, you can find files in a specified directory. Any string before the parameter is treated as the name of the directory you are looking for.
If you use this command without setting any parameters, the find command will find subdirectories and files in the current directory. All subdirectories and files found are displayed.
We sometimes have to look up a file in a vague way, based on the file name extension, when the file was created, the size of the file, etc.
Grammar:
find path -option [ -print] [-exec -ok command ] {} \;
Copy the code
Find determines path and expression according to the following rule, first on the command line – (),! The first part is path and the second part is expression.
If path is an empty string, the current path is used. If expression is an empty string, -print is used as the default expression.
There are 20 or 30 options available in Expression, and only the most commonly used ones are described here.
Parameter Description:
-name name, -iname name: indicates the name of the file. -user according to the user (owner of the file) -size n: the file size is n units, where B represents a block of 512 bytes, C represents a number of bytes, k represents a kilo bytes, and w represents two bits. -mtime Indicates the time when the file was last modified. -atime indicates the time when the file was last accessed. -perm: indicates the file permissiontypeTypen: searches for files of type typen C: character device D: directory C: font device file B: block device file P: named storage column F: general file L: symbolic link s: socketCopy the code
Pay attention to
The use condition of find is that the path to be searched must have read permission. The find option is found by file properties.
Example:
- 1. List all.c files in the current directory and its subdirectories:
# find . -name "*.c"
Copy the code
- 2. List all common files in the current directory and its subdirectories
# find . -type f
Copy the code
- 3. List all files updated in the last 20 days in the current directory and its subdirectories.
# find . -ctime -20
Copy the code
- 4. Find common files in /var/log that changed 7 days ago and ask them before deleting them:
# find /var/log -type f -mtime +7 -ok rm {} \;
Copy the code
- 5. Search for files in the current directory whose owners have read and write permissions, and whose group users and other users have read permissions.
# find . -type f -perm 644 -exec ls -l {} \;
Copy the code
- 6. Find all common files in the system with file length 0 and list their full path:
# find / -type f -size 0 -exec ls -l {} \;
Copy the code
- whereis
The whereis command is used to find a file. The directive looks for files in a specific directory that match the criteria. These files should belong to raw code, binaries, or help files. This command can only be used to locate binary files, source files, and man man pages. You need to use the Locate command to locate common files.
grammar
Whereis [-bfmsu][-b < directory >... [-m < directory >...] [-s < directory >...] [file]...Copy the code
Parameters:
-b Searches only binary files. -b < directory > only looks for binaries in the directory you set. -f Does not display the path name before the file name. -m Searches only description files. -m < directory > looks for description files only in the directory you set. -s finds only the original code file. -s < directory > only looks for raw code files in the directory you set. -u Searches for files that do not contain the specified type.Copy the code
Example:
- 1. Use the command “whereis” to check the location of the command “bash”. Type the following command:
peng@ubuntu:~/test$ whereis bash
bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz
Copy the code
- 2. Locate the stdio.h file in the standard library header
peng@ubuntu:~/test$ whereis stdio.h
stdio: /usr/include/stdio.h /usr/share/man/man3/stdio.3.gz
Copy the code
7) Grep filtering and statistics
Function: find out the result that contains some strings, filter the file or output result, there are certain requirements for case.
Grammar:
grep [option] string filename
Copy the code
Supplementary notes:
The grep command is used to find the file containing the specified template style. If the content of a file is found to conform to the specified template style, the default grep command will display the column containing the template style. If no file name is specified, or if a file name “-” is given, the grep command reads data from the standard input device.
-a < number of lines displayed > : displays the contents after the line except the one that matches pattern. -b < Number of lines displayed > : displays the contents before the line except the one that matches pattern. -c < Number of lines displayed > : -c: Counts the number of matched lines. -e: matches multiple patterns at the same time. -I: ignores the case of characters. The line that does not match pattern is displayed. -w: Matches the entire wordCopy the code
For example:
1. In the current directory, find the file with the suffix file that contains the string test and print out the lines of the string. In this case, run the following command:
grep test *file
Copy the code
2. Find the files that meet the criteria recursively. For example, find all files under the specified directory /etc/acpi and its subdirectories (if any) that contain the string “update” and print out the contents of the string on the line using the command:
grep -r update /etc/acpi
Copy the code
3. Reverse lookup. The previous examples find and print the qualified lines. The “-v” argument prints the unqualified lines.
To find the line that does not contain test in the file whose file name contains test, run the following command:
grep -v test *test*
Copy the code
Grep is frequently used and is often used with regular expressions. The common regular expressions are:
. : any single character * : any character [] : many times specified range, such as [0-9], [a-z], [a-z], [0-9 a zA - z] ^ : the beginning of a line of $: end-of-line ^ $: blank linesCopy the code
For example, assume the following file:
9) WC count
Run the Linux WC command to count words. Using the WC directive, we can count the Byte count, word count, or column count of a file. If the file name is not specified, or the given file name is “-“, the WC directive reads data from the standard input device.
Wc [option] File name
- L count how many rows
- W Count how many words
- C Count the number of characters
grammar
wc [-clw][--help] [-- version] [file...Copy the code
Parameters:
-c or --bytes or --chars displays only the number of bytes. -l or --lines displays the number of lines. -wor --words displays only the word count. --helpOnline help. --version Displays version information.Copy the code
The instance
By default, WC will count the number of lines, words, and bytes of a given file. The following command is used:
wc testfile
Copy the code
8) Decompress the tar file
The tar command creates files for Linux files and directories. Using tar, you can package a large number of files and directories into a single file, which is useful for backing up files or combining several files into a single file for easy network transfer.
grammar
Tar [required parameters][Select parameters][file]Copy the code
Common command parameters:
-a Add A compressed file to an existing compressed file -b Set block size -c Create A new compressed file -d Record file differences -r Add A file to A compressed file -u add A changed and existing file to an existing compressed file -x Extract A file from A compressed file -t display the contents of A compressed file -z Supports the gzip decompression. -j Supports the bzip2 decompression. -z Supports the compress decompression. -v Displays the operation processCopy the code
Common decompression/compression command tar
Unpack: tar XVF filename. tar Package: tar CVF filename. tar DirNameCopy the code
.gz
Gz: gunzip filename. gz: gzip -d filename. gz: gzip FileNameCopy the code
. Tar. Gz and. TGZ
Gz Zip: tar ZCVF filename.tar. gz DirNameCopy the code
.bz2
Bz2: bunzip2 filename. bz2: bunzip2 filename. bz2: bzip2-z FileNameCopy the code
.tar.bz2
Bz2: tar JXVF filename.tar. bz2: tar JCVF filename.tar. bz2 DirNameCopy the code
.bz
Decompress 1: bzip2 -d filename. bz Decompress 2: bunzip2 filename. bz: unknownCopy the code
.tar.bz
Extract: tar JXVF filename.tar. bz Extract: unknownCopy the code
.Z
Compress: uncompress filename. Z Compress: compress FileNameCopy the code
.tar.Z
Z DirName: tar Zcvf filename.tar. Z DirNameCopy the code
.zip
Decompress: unzip filename. zip Zip filename. zip DirNameCopy the code
.rar
Rar compressed: rar a filename. rar DirNameCopy the code
For example:
Example 1: Package the log2021 file as a tar package
Command:
Tar -cvf log.tar log2021.log package only, not compressed! Tar -zcvf log.tar.gz Log2021. log is packed and compressed using gzip. Tar -jcvf log.tar.bz2 log2021.log is packed and compressed using bzip2Copy the code
Example 2: See what files are in the tar package above
Description:
Since we use gzip compressed log.tar.gz, we need to add z to view the files in the log.tar.gz package.
Example 3: Decompress the tar package
Command:
tar -zxvf /opt/soft/test/log.tar.gz
Copy the code
Shell special characters
1) Wildcard *?
* : Wildcard contains zero or more characters *? : Wildcard Any single character * [s] : wildcard any character in a rangeCopy the code
For example:
2) Execute multiple commands in a row
Run multiple commands in one line: Use semicolons (;) between commands. separated
cd ; ls
Copy the code
3) Output redirection: >,>>
> : Puts the output of a command into a file. >> : Redirects the output but does not overwrite the source file. Appends it to the end of the source fileCopy the code
For example, output the ls output to test.txt
- The current directory has no operation permission
cd .. Go back to the previous directory2. Modify folder permissions For convenience, we will open all permissions of Test
The following output is displayed with > :
Then use “>>” to test the result as follows
4) Input redirection: <
Implement the following input redirection:
5) pipe: |
Pipeline operators “|” : a process of output as the input of another process
Enter the command:
ls -l /etc | cat
Copy the code
The results are shown in the figure above.
6) Others: %, $,~
% : job control, prompt, etc. $: fetching a column value, fetching a variable value, etcCopy the code
7. Users and processes
1. View the date and time process
A) date: displays the date and time
B) CAL: Displays the calendar
2. Query the PS process
The ps (process status) command is used to display the status of the current process, similar to the task manager in Windows.
grammar
ps [options] [--help]
Copy the code
Ps has a lot of parameters. Here, just a few commonly used parameters are listed and their meanings are briefly introduced:
-a lists all the processes. -w Displays wider information. -au displays more detailed information. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND USER: itinerary owner PID: PID %CPU: occupied CPU usage %MEM: occupied memory usage VSZ: TTY: Indicates the minor device number of TTY. STAT: indicates the status of the trip. D: indicates the sleep state that cannot be interrupted (common I/O processes). Static state T: suspend execution Z: does not exist but cannot be eliminated temporarily W: does not have enough memory pages to allocate <: A high-priority trip N: A low-priority trip L: has memory pages allocated and locked in memory (real-time system or next to A I/O) START: TIME at which the trip starts Execution time COMMAND: Indicates the COMMAND that is executedCopy the code
The instance
- Displays all process information, along with the command line
- Find the specified process init:
3. The specified user information is displayed
3. Sudo user management
The rightmost character of the terminal command line
$Common User# admin user
Copy the code
There are many commands that require administrator permission to use. You can add sudo before entering a command, or you can directly switch to the administrator to execute the command.
Switch to administrator root
Switch the user
Su user name: Switch accountsCopy the code
4. Power management
a) shutdown
Safely shut down or restart the Linux system, which prompts all logged-in users on the system with a warning message before shutting down. The command also allows the user to specify a time parameter, either an exact time or a period of time from now. The exact time is in hh: mm format. The time range is + and the number of minutes. After this command is executed, the system automatically synchronizes data.
System shutdown command.
Syntax: shutdown [-effhKNr][-t number of seconds][time][warning]Copy the code
Supplementary notes:
The shutdown command can shutdown all programs, and restart or shutdown as required by the user.
Parameters:
-c When the shutdown -h 11:50 command is executed, press + to interrupt the shutdown command. -f Does not run FSCK during the restart. -f Runs FSCK during the restart. -h Shuts down the system. -k just sends messages to all users, but does not actually shut down. -n Does not call the init program for shutdown, but shutdown itself. -r Restarts after shutdown. -t< seconds > The delay between sending a warning message and deleting a message. [Time] Set the time after the shutdown command is executed. [Warning message] Information to be sent to all login users.Copy the code
b) reboot
Function description: Restart.
Grammar:
dreboot [-dfinw]
Copy the code
Supplementary notes:
Run the reboot command to stop and restart the system.
Parameters:
-d Data is not written to the record file /var/tmp/wtmp during the restart. This parameter has the effect of the "-n" parameter. -f Forcibly restarts the system without invoking the shutdown command. -i Close all network interfaces before restarting the system. -n Does not check whether unfinished programs exist before restarting. -w is a test. It does not actually restart the system, but writes the data to /var/logWTMP record file in directory.Copy the code
c) halt
Shut down the system.
Grammar:
halt [-dfinpw]
Copy the code
Supplementary notes:
Halt checks the system’s runlevel first. If runlevel is 0 or 6, the system is shutdown, otherwise shutdown is called to shutdown the system.
Parameters:
-d Do not record in WTMP. -f if shutdown is not called, the system is forcibly shutdown regardless of the current runlevel. -I Before halt, close all network interfaces. -n No need to run sync before halt. -p After halt, execute poweroff. -w records only in WTMP and does not actually end the system.Copy the code
4. Supplementary user management
(1) User password requirements
The password must contain 6 to 8 characters, including at least two letters, one digit, or special characters. The password must be different from the user name and must be different from the previous password by at least three characters.
(2) passwd Command to change the password
Enter the passwd command. Enter the old password ****. Enter the new password to confirm the new passwordCopy the code
Note: the machine does not do anything during password input
(3) Search for users
id
View the user ID (user name) and its owning group ID (group name)Copy the code
user
View users that have logged in to the current system. Only user names are displayed.Copy the code
who
View user detailsCopy the code
who am i
View information about the current userCopy the code
whoanmi
View the current user's own usernameCopy the code
8. Relevant information inquiry
View disk information
1. du
Displays disk usage summary information
Du is displayed in blocks. -k is displayed in k bytes. -m is displayed in m bytes. -s Displays the total disk space occupied by the contents of the current directoryCopy the code
2. df
Displays the disk usage of the entire file system
-k Displays the value in K bytesCopy the code
Network configuration
1, ping
Check the connection between the current host and another host. Ping host name or HOST IP address: Sends data packets to the host following the ping. If the host responds, it is connected.
Grammar:
Ping [- dfnqrRv] [-c < complete number >] [-i number > < seconds] [-i < > network interface] [-l < pre > loaded] [-p < style > model] [-s < > packet size] [-t numerical > < live] [host name or IP address]Copy the code
Note: The PING command uses the ICMP transmission protocol to send a message requesting a response. If the remote host is running properly, the ping command responds to the message, indicating that the host is running properly.
Parameters:
-d Uses the SO_DEBUG function of the Socket. -c< Completion Times > Sets the number of times for completing the request response. -f Limit detection. -i< Interval seconds > Specifies the interval for sending and receiving messages. -i < network interface > Sends packets using the specified network interface. -l< preload > sets the packet to be sent before the requested message is sent. -n Outputs only numeric values. -p< Template style > Sets the template style for filled packets. -q Displays no command execution process except the beginning and end information. -r Directly sends the packets to the remote host, ignoring the common Routing Table. -r Records the routing process. -s< Packet size > Sets the packet size. -t< TTL value > Sets the TTL value. -v Displays the detailed command execution process.Copy the code
2, ifconfig
View and configure network parameters of the current machine
Grammar:
Ifconfig [network device][down up-allmulti-ARP - promisc] [add < address >] [del < address >] [< hw < network device type > < > hardware address] [io_addr < > I/O address] [irq > < irq address] [media type > < network media] [mem_start < > memory address] [metric < number >] [m Tu byte < >] [netmask < subnet mask >] [tunnel < address >] [- broadcast < address >] [- pointopoint < address >] [IP address]Copy the code
Note: Ifconfig can set the status of the network device, or display the current Settings.
Parameters:
Add < Address > Sets the IPv6 IP address of the network device. Del < address > Deletes the IPv6 IP address of the network device. Down Disables the specified network device. < hW < Network device Type >< Hardware Address > Sets the type and hardware address of the network device. Io_addr <I/O Address > Sets the I/O address of the network device. Irq <IRQ Address > Sets the IRQ of the network device. Media < Network Media Type > Sets the media type of the network device. Mem_start < memory address > Sets the start address that the network device occupies in the main memory. Metric < number > Specifies the number to be added to calculate the number of times packets are forwarded. Mtu < bytes > Sets the MTU of the network device. Netmask < Subnet mask > Sets the subnet mask of the network device. Tunnel < address > Establishes the communication address of the tunnel between IPv4 and IPv6. Up Starts the specified network device. -broadcast< address > The packets to be sent to the specified address are treated as broadcast packets. -pointopoint< address > Establishes a direct connection with the specified network device. This mode is confidential. -promisc Disables or enables the promiscuous mode of specified network devices. [IP Address] Specifies the IP address of the network device. [Network Device] Specifies the name of the network device.Copy the code
For example,
Ifconfig -a // Displays network information such as the IP address, Netmask, and Gateway of the current machine. Ifconfig eth0 up(down) // Activates or disables a network adapter [address] // Set the IP address and subnet maskCopy the code
Linux application installation and uninstallation basis
1. Linux installation package
Linux installation packages are usually in tar format, but also support your own format. The software installation package format is usually RPM in Redhat and deb in Ubuntu
2. General naming rules for installation packages
The common naming format in Linux is:
Software Name Version - Modified version architecture. extensionCopy the code
3. Offline installation and uninstallation of the installation package
DPKG DPKG -i Installs DPKG -p uninstalls DPKGCopy the code
Source file installation process:
Configure >> compile make >> Install make InstallCopy the code
4, online installation and uninstall
Installation:
apt-get install
Copy the code
Uninstall:
apt-get remove -purge
Copy the code
VIM compiler
Vim is a text editor developed from VI. Code completion, compilation, error jump and other convenient programming functions are particularly rich, widely used in programmers.
In a nutshell, VI is an old-fashioned word processor, but it has a lot of features, but there is still room for improvement. Vim is a great tool for developers.
Even the vim website (www.vim.org) itself says that Vim is a development tool, not a word processor.
1. Vim advantages:
- A) All Unix Like systems have a built-in VI text editor, and other text editors may not exist;
- B) The editing interface of many software actively calls vi
- C) VI has the ability of program editing and can actively identify the correctness of grammar by font color, which is convenient for program design;
- D) The program is simple and fast in editing.
2. Vi Mode:
Basically, VI/VIM can be divided into three modes, namely Command mode, Insert mode and Last line mode. The functions of these three modes are as follows:
1) Command mode:
The user enters the command mode just after starting vi/vim.
Keystrokes in this state are recognized by Vim as commands rather than input characters. For example, when we press I, instead of typing a character, I is treated as a command.
Here are some common commands:
I switches to input mode to enter characters. X Deletes the character at the current cursor position. : Switches to bottom line command mode to enter commands on the bottom line.Copy the code
To edit text: Start Vim and enter command mode. Press I to switch to input mode.
Command mode has only the most basic commands, so you still rely on bottom-line command mode to enter more commands.
2) Input mode
Press I in command mode to enter input mode.
In input mode, the following keys can be used:
Character key and Shift combination to enter characters
BACK SPACE, delete a character before the cursor DEL, delete a character after the cursor Arrow, move the cursor in the text HOME/END, move the cursor to the beginning /END of the line Page Up/Page Down, Page Up/Page Down Insert, Switch the cursor to Input/replace mode, the cursor will change to vertical line/underscore ESC, exit input mode, and switch to command modeCopy the code
3) Bottom line command mode
Press (colon) in command mode to enter baseline command mode.
The bottom-line command mode allows you to enter single or multiple character commands, and there are many available commands.
In baseline command mode, the basic commands are (colon omitted) :
Q Exit the program w Save the file Press ESC to exit the bottom line command mode at any time.Copy the code
In simple terms, we can think of these three patterns as ICONS below:
3. vim cheat sheet
The following is the famous Vim Cheat Sheet, which contains most of the commonly used Vim commands and is recommended to be saved
4. For example
If you want to create a file called peng.c using vim, type the following command:
peng@ubuntu:~$ vim peng.c
Copy the code
Press I to enter input mode (also known as edit mode) and start editing text
In normal mode, just press the I, O, A character to enter the input mode!
In edit mode, you can see the word INSERT- in the lower left corner of the status bar, which is an indication that you can enter any character.
At this point, the other keys on the keyboard, except for Esc, are considered normal input buttons, so you can do any editing.
Press the ESC button to return to normal mode
Ok, assuming I have finished editing it in the style above, how should I exit? Yes! That’s right! Just press the Esc button! Immediately you’ll notice that the INSERT in the lower left corner of the screen is gone! In general mode, press :wq to save the configuration and exit vi
OK, we are going to save, save and leave the command is very simple, enter :wq to save and leave!
OK! So we have successfully created a peng.c file.
5. Shortcut keys
Method to move the cursor
operation | meaning |
---|---|
H or left arrow key (←) | The cursor moves one character to the left |
J or down arrow key (↓) | Move the cursor down one character |
K or up arrow key (↑) | The cursor moves up one character |
L or right arrow key (→) | The cursor moves one character to the right |
If you place your right hand on the keyboard, you’ll notice that HJKL is lined up, so you can use these four buttons to move the cursor. If you want to move more than once, for example, move down 30 lines, you can use the combination of “30J” or “30↓” keys, that is, add the desired number (number), then press the action!
shortcuts | meaning |
---|---|
[Ctrl] + [f] | Move the screen “Down” one Page, equivalent to the [Page Down] button (The commonly used) |
[Ctrl] + [b] | The screen moves one Page “Up”, equivalent to the [Page Up] button (The commonly used) |
[Ctrl] + [d] | The screen moves half a page “down” |
[Ctrl] + [u] | The screen moves “up” half a page |
+ | The cursor moves to the next line that is not a space character |
– | The cursor moves to the line above the non-space character |
n | The n stands for “number”, such as 20. Pressing the number followed by the space bar moves the cursor n characters to the right of the line. For example, if 20, the cursor moves back 20 characters. |
0 or function key [Home] | This is the number “0” : move to the first character on the line (The commonly used) |
$or function key [End] | Move to the last character of the line (The commonly used) |
H | The cursor moves to the first character in the top line of the screen |
M | The cursor moves to the first character of the line in the center of the screen |
L | The cursor moves to the first character in the bottom line of the screen |
G | Move to the last line of the file (The commonly used) |
nG | N is a number. Move to line N of this file. For example, 20G will be moved to line 20 of the file. |
gg | Move to the first line of this file, equivalent to 1G! (The commonly used) |
n | N is a number. Move the cursor down n linesThe commonly used) |
The search to replace
shortcuts | meaning |
---|---|
/word | Look under the cursor for a string named word. For example, to search for the string vbird in the file, type /vbird! (The commonly used) |
? word | Look for a string named word above the cursor. |
n | This N is the English button. Represents the action of repeating the previous search. For example, if we had just executed /vbird to search down for the string vbird, pressing n would search down for the next string named vbird. If it’s execution? For vbird, pressing n will continue searching up for the string named vbird! |
N | This N is the English button. The opposite of n, the previous search action is performed for “reverse”. For example, after /vbird, press N to search “up” for vbird. |
Using /word with n and N is very helpful! This allows you to repeatedly find some of your search keywords!
shortcuts | meaning |
---|---|
:n1,n2s/word1/word2/g | N1 and n2 are numbers. Look for the string word1 between lines N1 and n2 and replace it with word2! For example, to search for vbird between lines 100 and 200 and replace it with vbird: “:100,200s/vbird/ vbird/ g”. (The commonly used) |
: 1, $s/word1 word2 / g or: % s/word1 word2 / g | Find the word1 string from the first to the last line and replace it with word2! (The commonly used) |
: 1, $s/word1 word2 / gc or: % s/word1 word2 / gc | Find the word1 string from the first to the last line and replace it with word2! And display prompt characters to the user before replacing (confirm) whether to replace! (The commonly used) |
Delete, copy and paste
shortcuts | meaning |
---|---|
x, X | In a line, x is a character removed backward (equivalent to the [del] key), x is a character removed forward (equivalent to the [backspace] key) (The commonly used) |
nx | N is a number, and n characters are deleted consecutively backward. For example, I want to delete 10 characters in a row, “10x”. |
dd | Delete the entire row where the cursor is located (The commonly used) |
ndd | N is a number. Delete n lines down from the cursor, for example 20dd deletes 20 lines (The commonly used) |
d1G | Deletes all data up to the first row where the cursor is located |
dG | Deletes all data up to the last line where the cursor is |
d$ | Delete the cursor to the last character of the line |
d0 | That’s the numeric 0, delete the cursor to the first character on the line |
yy | Copy the row where the cursor is (The commonly used) |
nyy | N is a number. Copy n lines down from the cursor, for example 20yy is 20 lines (The commonly used) |
y1G | Copy all data from the cursor row to the first row |
yG | Copies all data from the cursor row up to the last row |
y0 | Copy all data from the character where the cursor is located to the beginning of the line |
y$ | Copy all data from the character where the cursor is located to the end of the line |
p, P | P is to paste the copied data on the line below the cursor, p is to paste the data on the line above the cursor! For example, I’m currently at line 20 and have copied 10 rows of data. After pressing P, the 10 lines will be pasted after the original 20 lines, i.e., starting from line 21. But what if you press P? So line 20 will be pushed to line 30. (The commonly used) |
J | Combine the cursor row with the data on the next row |
c | Delete multiple rows, such as down 10 rows, [10cj] |
u | Undo the previous action. (The commonly used) |
. | Repeat the meaning of the previous action. If you want to de-duplicate, re-paste, etc., press the decimal point “. It is good! (The commonly used) |
[Ctrl]+r | Repeat the last action. (The commonly used) |
This u and [Ctrl]+ R are very common instructions! One is to undo, the other is to redo ~ use these two function buttons, your edit, hey hey! Very happy!
Description of available buttons to switch from General mode to Edit mode
Enter input or replace edit mode
shortcuts | meaning |
---|---|
i, I | Insert mode: I indicates “enter from where the cursor is now”, I indicates “enter from the first non-space character on the current line”. (The commonly used) |
a, A | Enter Insert mode: A indicates “start from the next character where the cursor is”, a indicates “start from the last character in the line where the cursor is”. (The commonly used) |
o, O | Enter Insert mode: This is the case of the letter O. O to enter a new line next to the current cursor; O Enter a new line at the line above the current cursor! (The commonly used) |
r, R | In Replace mode, r replaces the cursor character only once; R replaces the text at the cursor until ESC is pressed; (The commonly used) |
[Esc] | Exit edit mode and return to general mode (The commonly used) |
In each of these buttons, the words “–INSERT–” or “–REPLACE–” appear in the lower left corner of the VI screen. Know the action by the name!! In particular, as we mentioned above, when you want to type a character into a file, you must see INSERT or REPLACE in the lower left corner.
Description of available buttons to switch from general mode to command line mode
Instruction line store, leave, etc
shortcuts | meaning |
---|---|
:w | Write the edited data to the hard disk file (The commonly used) |
:w! | If the file property is Read-only, the file is forcibly written to. Nevertheless, after all can write, still be concerned with you to the archives authority of this archives! |
:q | Leave the vi (The commonly used) |
:q! | If you have modified the file and do not want to save it, use it! Do not store files for forced leave. |
:wq | Save and leave, if :wq! Is forced store and leave (The commonly used) |
ZZ | It’s a capital Z! If so, save the current file and exit! Effect equivalent to (Save and exit) |
ZQ | If no, forcibly exit. The effect is equivalent to: Q! . |
:w [filename] | Save the edited data into another file (similar to saving a new file) |
:r [filename] | In the edited data, read data from another file. Also append the file content “filename” to the end of the cursor line |
:n1,n2 w [filename] | Store the contents of n1 through n2 into filename. |
:! command | Temporarily leave vi and run command in command line mode. For example, if :! Ls /home is displayed on the vi interface, you can view the file information output as ls under /home. |
Changes to the VIM environment
shortcuts | meaning |
---|---|
:set nu | Displays the line number. When set, the prefix of each line is displayed.The commonly used) |
:set nonu | In contrast to set nu, cancel line number! |
After learning these basic knowledge, you can enter the next step, learning Linux C program development! Want to learn Linux, quickly follow a Linux official number!