[Linux] Instruction Learning

Linux learning record

😄 Life goes on, writing goes on
🔥 Continue on the road of learning and share notes as you learn
👊 One day I will be like you guys
🏆 a dreamer @Blooming Dede
🌝Share your learning experience, welcome corrections, let's learn and grow together!

1. Virtual machine network card configuration

After the server restarts, we can query the IP address of the Linux system through the linux command ip addr. The specific information is as follows:

From the figure, we can see that the IP address of the linux system has not been obtained. Why is this? This is caused by the failure to initialize the IP address because the network card is not loaded when the server is started. Then we need to modify the network initialization configuration and set the network card to initialize when the system starts.
Specific modification steps:

1). Modify the configuration items of the network card

cd /				enter the root directory
cd etc				Enter etc Table of contents
cd sysconfig		Enter sysconfig Table of contents
cd network-scripts	Enter network-scripts
vi ifcfg-ens33		edit ifcfg-ens33 document

After entering the file do the following:
①. Press i key to enter the editing state
②. Press the ↑↓ key to move the cursor, delete no, and enter yes
③. Press ESC
④. Input :wq
⑤. Press ENTER to save and exit

Remarks: The relevant instructions in Linux are used in the above operations. At present, you don't need to delve into them. We will explain them in detail later. At present, you only need to change the value of the configuration item ONBOOT in this file from no to yes.

2). Restart the virtual machine

After restarting, enter the root user name and password again, log in to the Linux system, and use the command ip addr to check the IP address.

2. Linux directory structure

After logging in to the Linux system, we need to familiarize ourselves with the directory structure of Linux. In the existing Linux system, the concept of Table of contents also exists, but there are many differences between the Table of contents structure of Linux and that of Windows. In Windows Under contents, the directory is to a certain drive letter A directory in a Linux system has the following characteristics:
A. / is the vertex of all directories
B. The directory structure is like an upside-down tree
The role and meaning of each directory under the root directory/:

3, Linux common commands

4, Linux command format

command [-options] [parameter]
	command: 	 command name
	[-options]:  Options, which can be used to control the command or omitted
	[parameter]: Arguments passed to the command, which can be zero, one, or more
	[] 	 represents optional
	The command name, options, and parameters are separated by spaces

5. File directory operation commands


effect: Display the contents of the specified directory
 grammar: ls [-al] [dir]
	-a Show all files and directories (. Hidden files at the beginning are also listed)
	-l In addition to the file name, also set the file type(d represents a directory,-representation file),Permissions, owner, file size and other information are listed in detail
	Since we use ls It is often necessary to join the command-l option, so Linux for ls -l Command provides a shorthand way of ll
Common usage: 
	ls -al 	View all files and directory details in the current directory
	ls -al /etc   Check/etc All files and directory details in the directory
	ll  	View detailed information about files and directories in the current directory 


effect: Used to switch the current working directory, that is, enter the specified directory
 grammar: cd [dirName]
Special Instructions: 
	~	represents the user's home Table of contents
	. 	Indicates the current directory
	.. 	Indicates the parent directory of the current directory location
	cd 	..		Switch to the parent directory of the current directory
	cd 	~		switch to user's home catalogue
	cd 	/usr/local	switch to/usr/local catalogue

user's home directory
root user /root
other users /home/xxx


effect: Used to display file content
 grammar: cat [-n] fileName

	-n: Number all output lines starting from 1

	cat /etc/profile		Check/etc under the directory profile document content

The cat command will view all the contents of the file at one time. If the file has a lot of content, it is not very convenient to view it at this time. At this time, we can pass a new command more.


effect: Display file contents in paginated form
 grammar: more fileName

    enter 	scroll down one line
    space bar 	scroll down one screen
    b 		Return to previous screen
    q or Ctrl+C	quit more
	more /etc/profile		Display in pagination/etc under the directory profile document content

When we are viewing some relatively large files, we may need to frequently query the data information at the end of the file. At this time, if the file is very large, we have to turn down the page until the last page to see the newly added data. This method is more cumbersome. At this time, we can use the tail command.


effect: See what's at the end of the file
 grammar: tail [-f] fileName

	-f : Dynamically read the content at the end of the file and display it, usually used for the content output of the log file
tail /etc/profile		show/etc under the directory profile The contents of the last 10 lines of the file
tail -20 /etc/profile	show/etc under the directory profile 20 lines at the end of the file
tail -f /itcast/my.log	dynamic read/itcast under the directory my.log content at the end of the file and display


effect: Create a directory
 grammar: mkdir [-p] dirName

	-p: Make sure the directory name exists, create one if it doesn't exist. With this option, multiple directories can be created at the same time

    mkdir itcast  In the current directory, create a file named itcast subdirectory of
    mkdir -p itcast/test   in the working directory itcast Create a directory named test subdirectories of , if itcast directory does not exist, create one


effect: delete empty directory
 grammar: rmdir [-p] dirName

	-p: When the subdirectory is deleted and the parent directory is empty, delete it together

    rmdir itcast   delete named itcast empty directory
    rmdir -p itcast/test   delete itcast directory named test subdirectories of , if test After directory deletion itcast directory becomes empty, it is also deleted
    rmdir itcast*   remove the name to itcast empty directory to start with

: is a wildcard, representing any character;
rmdir itcast : remove directories starting with itcast
rmdir *itcast : remove directories ending with itcast


effect: delete file or directory
 grammar: rm [-rf] name

    -r: Delete the directory and all files (directories) in the directory one by one, that is, recursively delete
    -f: Delete without confirmation
    rm -r itcast/     delete named itcast The directory and all files in the directory must be confirmed before deletion
    rm -rf itcast/    No need to confirm, just delete the name itcast directory and all files in the directory
    rm -f hello.txt   Delete without confirmation hello.txt document

Note: For commands such as rm -rf xxx, you must be careful when executing them, and delete them after confirming that they are correct to avoid accidental deletion.

6. Copy and move commands


effect: for copying files or directories
 grammar: cp [-r] source dest

	-r: If you need to use this option when copying a directory, all subdirectories and files in the directory will be copied at this time.

    cp hello.txt itcast/            Will hello.txt copy to itcast in the directory
    cp hello.txt ./hi.txt           Will hello.txt Copy to the current directory and rename it hi.txt
    cp -r itcast/ ./itheima/    	Will itcast Copy the directory and all files under the directory to itheima Under contents
    cp -r itcast/* ./itheima/ 	 	Will itcast Copy all files in the directory to itheima Contents


effect: Rename a file or directory, or move a file or directory to another location
 grammar: mv source dest

    mv hello.txt hi.txt                 Will hello.txt rename to hi.txt
    mv hi.txt itheima/                  put the file hi.txt move to itheima in the directory
    mv hi.txt itheima/hello.txt   		Will hi.txt move to itheima directory, and renamed hello.txt
    mv itcast/ itheima/                 if itheima directory does not exist, will itcast directory renamed itheima
    mv itcast/ itheima/                 if itheima directory exists, will itcast directory moved to itheima in the directory

7. Pack and compress commands

effect: Pack, unpack, compress, decompress files
 grammar: tar  [-zcxvf]  fileName  [files]
    The package file suffix is.tar Indicates that the packaging is only completed, and there is no compression
    The package file suffix is.tar.gz Indicates that the package is also compressed

    -z: z represents gzip,pass gzip command to process files, gzip Compress or decompress files
    -c: c represents create,i.e. create new package file
    -x: x represents extract,Implement restoring files from package files
    -v: v represents verbose,show the execution of the command
    -f: f represents file,Used to specify the name of the package file

        tar -cvf hello.tar ./*		  		Package all files in the current directory, and the packaged file name is hello.tar
        tar -zcvf hello.tar.gz ./*		  	Package and compress all files in the current directory, and the packaged file name is hello.tar.gz
        tar -xvf hello.tar		  			Will hello.tar Unpack the file and place the unpacked file in the current directory
        tar -zxvf hello.tar.gz		  		Will hello.tar.gz Unzip the file and place the unzipped file in the current directory
        tar -zxvf hello.tar.gz -C /usr/local     Will hello.tar.gz Unzip the file, and put the unzipped file in/usr/local catalogue

8. Text editing commands

8.1 Introduction to vi&vim

 vi The command is Linux A text editing tool provided by the system, which can edit the content of the file, similar to Windows notepad in
 grammar: vi fileName
 1). vim From vi A more powerful text editing tool developed, which can color the text content when editing the file, which is convenient for us to edit the file, so in actual work vim more commonly used.  
2). need to use vim command, we need to complete the installation ourselves. Installation can be done with the following command: yum install vim

8.2 vim installation

Command: yum install vim

8.3 Using vim

effect: Edit the contents of the file, vim It's actually a text editor syntax: 
vim fileName illustrate: 	
	1). In use vim When the command edits a file, if the specified file exists, the file is opened directly. Creates a new file if the specified file does not exist.	
	2). vim There are three modes in text editing, namely the command mode ( Command mode),Insert mode ( Insert mode)and bottom row mode ( Last line mode). 
You can switch between these three modes. we are using vim We must pay attention to which mode we are currently in.

Three modes: - Command mode
A. In command mode, you can view the file content and move the cursor (up, down, left and right arrows, gg, G)
B. After opening the file through the vim command, it enters the command mode by default
C. The other two modes need to first enter the command mode before entering each other

  | Command Mode Instructions | meaning                              |
  | ------------ | --------------------------------- |
  | gg           | Position to the first line of text content            |
  | G            | Position to the last line of text content          |
  | dd           | Delete the data of the row where the cursor is located              |
  | ndd          | Delete the line where the current cursor is located and after n row data |
  | u            | undo operation                          |
  | shift+zz     | save and exit                        |
  | i or a or o  | enter insert mode                      |
  • insert mode
    A. The content of the file can be edited in insert mode
    B. Press any one of [i,a,o] in command mode to enter insert mode. After entering the insert mode, the word [insert] will appear below
    C. Press the ESC key in insert mode to return to command mode
  • bottom row mode
    A. In the bottom line mode, you can use commands to search the file content, display the line number, exit, etc.
    B. Press any one of [:,/] in command mode to enter bottom line mode
    C. After entering the bottom line mode through the / method, you can search the file content
    D. After entering the bottom line mode through the : method, you can enter wq (save and exit), q! (exit without saving), set nu (display line number)

9. Find command

9.1 find

effect: Find files in the specified directory
 grammar: find dirName -option fileName
    find  .  –name "*.java"         Find in the current directory and its subdirectories.java end file
    find  /itcast  -name "*.java"   stay/itcast directory and its subdirectories.java end of file

9.2 grep

effect: Find the specified text content from the specified file
 grammar: grep word fileName
    grep Hello HelloWorld.java  find HelloWorld.java appearing in the file Hello the position of the string
    grep hello *.java           Find all in the current directory.java The file at the end contains hello the position of the string

10. Installation instructions

# install a file
sudo apt install document 
yum -y install

11. View port command


  • a (all) display all options, the default does not display LISTEN related
  • t (tcp) only shows tcp related options
  • u (udp) only displays udp related options
  • n Refuse to display aliases, can display all the numbers into numbers.
  • l Only list the service status that is in Listen (listen)
  • p Displays the program name that created the associated link
  • r Display routing information, routing table
  • e Display extended information, such as uid, etc.
  • s Statistics by protocol
  • c Every fixed time, execute the netstat command.

Tip: The status of LISTEN and LISTENING can only be seen with -a or -l

11.1 List all ports

netstat -a

11.2 List all listening Sockets

win not found -l

# Only show listening ports
netstat -l

This is the note I recorded in Youdao Cloud Notes before. Since the format is different from that of csdn, it is too troublesome to turn the table, so I use screenshots.
The learning of linux is still continuing, and the follow-up sequence will continue to be recorded in the column.
👍 Creating is not easy, please correct me if there are any mistakes, thanks for watching! Remember to like it! 👍

Tags: Linux

Posted by mike97gt on Mon, 26 Sep 2022 01:40:32 +0930