Linux system use (super detailed)

Table of contents

Introduction to Linux Operating System

The difference between Linux and Windows

Linux common commands

Linux directory structure

Linux command prompt

 Common commands

ls 

cd 

 pwd

 touch

 cat 

echo

mkdir

rm 

cp 

 mv 

vim

Basic use of vim

grep 

netstat

Linux interview questions


Introduction to Linux Operating System

The Linux operating system is parallel to the Windows operating system. It's just that the characteristics of the two operating systems are different.

The difference between Linux and Windows

  1. Open source VS closed source: Linux is an open source system. Its kernel and most of the software codes are public, and anyone can modify and view them. The windows operating system is a closed-source commercial operating system, and its source code is not open to the public, and only Microsoft can perform operations such as modification.
  2. Release mode: Linux is released in the form of releases, such as Ubuntu, CentOS, etc. Each release has its own characteristics and target user groups, while windows is released in a single official version, but users can Choose the version you want, such as windows10, windows11, etc.
  3. User interface: Windows operating system uses a graphical interface as the main interaction method, which provides intuitive operation and good user experience. Linux also provides a variety of desktop environments, but Linux is still lagging behind windows in terms of graphics a little.
  4. Apps and Compatibility: Windows has a huge app ecosystem, with many business software and games developed specifically for Windows. Although Linux also has many excellent open source and free software, it has relatively little support for commercial software and some specific application areas. In addition, Windows is more extensive in terms of hardware and driver compatibility, because most hardware vendors prefer to provide drivers for Windows.
  5. Security and Stability: Due to its open-source nature, the Linux operating system is widely reviewed and contributed, and has good security and stability. In contrast, Windows, due to its broad user base and closed-source nature, is more commonly attacked by malware and may face some security and stability challenges.
  6. Deployment and management: Linux is widely used in the server field because of its stability and flexibility. It is generally considered more suitable for technical professionals and system administrators, requiring some command line operation and configuration knowledge. Windows, on the other hand, dominates the desktop and home user space, offering a more simplified and easy-to-use interface and tools.

Generally speaking, Windows and Linux are two different operating systems, each with its own advantages and applicable scenarios. Which operating system to choose depends on the user's needs, technical background, and usage scenarios.

Linux common commands

Linux directory structure

Windows directory structure:

 

The windows directory structure is generally as shown in the figure above.

In the directory structure of Linux, there is no concept of a drive letter, and some are just a root directory / , and some specific files are stored in the root directory. In Linux, some hardware devices are abstracted into files and stored in On the hard disk, so there is such a sentence in the Linux system, everything is a file.

Linux command prompt

 

 

 Common commands

ls 

ls  list 

 The function of ls list is to list the files or directories in the current directory/specified directory. Double-click a directory in Windows to see what's in it.

The blue ones are directories, and the white ones are ordinary files.

Add a specified path after ls to view the content under the specified path.

 / Root directory, for this computer in Windows.

Any file in Linux exists in the / root directory.

 You can see that the effect here is the same as typing ls directly, which is the default directory where we log in as root.

/root is the home directory of the root user.

Use ls -l to view the specific information

 

 This operation is compared to the detailed information displayed in windows.

 Linux provides the ll command. This command is equivalent to ls -l 

 

The above options are also called command line parameters.

Note: Between the parameters of the command line, a space is required to separate them.

cd 

cd change directory switch directory

In the Linux system, the files and directories on the disk are organized into a directory tree, and each node is a directory or a file.

 It is equivalent to double-clicking a certain directory in the resource management in windows.

Follow the cd with the path you want to switch directories. The path here can use a relative path or an absolute path.

As the cd progresses, the location of the directory changes.

 Directly switch directory to follow directory.

 Use absolute paths to switch directories

 

 Use relative paths to switch directories.

 

Without any option after cd, it will directly jump to the current user's home directory.

 cd and ls are among the commands we use most often.

 pwd

This command is a command to prevent users from getting lost. This command is to display our current full path.

This command points the mouse in windows to the address bar of this computer:

 It can be seen that when the mouse is on the top point, the complete path will be displayed.

In Linux, pwd does this.

 touch

touch creates a blank file

 

It can be seen that after we executed the touch abc.txt command, Linux did not give me any feedback.

In fact, we don't have to panic. In Linux, no news is the best news. Our command was executed successfully.

 

 cat 

cat reads the contents of a file

 Note: If this command reads short files, it is fine. If you use this command to read very large files, cat is very inconvenient.

The cat command does two things:

1: Read the file on the hard disk.

2: Display all the files in the terminal.

Then if the file is very large, we read all the large files at one time, and then display all the information in the file on the terminal. The time consumed at this time is relatively large.

We use the cat command to read the effect of a file in the /etc directory.

 Adding the command line parameter -n means that we add an upline number to the content of the file we read.

echo

echo This command is used to write files

 

 In the above command, we use echo to write hello into the abc.txt file.

At this point we use the cat command again to view:

 You can see that hello is already in the abc.txt file.

At that time, every time we executed the echo command, the original content would be cleared.

 It can be seen that hello has been cleared, and only the world of ehco is left.

Note: Commands such as echo and cat are only suitable for operating simple files. If the file is relatively large and complex, echo and cat are not suitable.

mkdir

mkdir creates a directory

This command corresponds to the right button in Windows to create a new folder. 

 

 

 After we execute mkdir ddd, a directory has been created.

We can add the command line parameter -p When we add the command number parameter -p, the system will automatically create directories recursively for us.

 This command is to create the aaa directory under the current directory, create the bbb directory under the aaa directory, and create the ccc directory under the bbb directory.

 

rm 

rm remove removes files/directories

 

 When we execute rm, after specifying the file to be deleted, the system will let us determine whether to delete it.

We can use the command line parameter /r for recursive deletion

 When this command deletes a directory, it needs to delete all files and subdirectories at the same time.

The command line parameter -rf here is to force delete without asking.

 Note: In Linux, there is no concept of recycle bin. If it is deleted, it is completely deleted.

The root directory / is the top node in our Linux. If this directory is forced to be deleted without asking, then this Linux system is considered useless. Completely useless. Use with caution 

 

cp 

cp copy copy

 cp is used to copy files or directories.

There is an a.txt file in the current directory, we copy this a.txt file and rename it to a1.txt.

 There are two parameters after cp, one is the source file, and the other is where to copy it.

Here is to copy a.txt and rename it to a1.txt.

cp can not only copy files, but also copy directories. It should be noted that when copying the directory, the command line parameter -r must be added

 We now copy the hello.txt file in the aa directory and the aa directory to the bb directory.

You can see that we copied the entire aa directory to the bb directory.

 mv 

mv cuts a file or directory

The mv command can be used to set the name of the target file when moving (moving and changing the name once).

It can be seen that if the source and target to be moved are in the same directory, it is simply a name change at this time.

 We are in the process of moving to rename operations.

The above operation is that we cut the a.txt file in the current directory to the aa directory and rename it to a3.txt.

vim

vim to edit files

 Vim is a text editor that comes with Linux, which is equivalent to Notepad on Windows.

Basic use of vim

  • open a file
  • edit file
  • save and exit

The operation of the above three vim is the most basic use.

1: open the file 

Use vim filename/filepath

 When we execute the above command, the system uses vim to open this file.

 At this time, since there is nothing in this file, it is blank here.

2: Edit the file

Before editing files, we need to know the three modes of vim.

  • normal mode
  • insert mode
  • command line mode

The interface of the file we are opening is the normal mode. In this mode, we cannot insert data.

To write data, you must switch to insert mode.

To switch insert mode is actually very simple, just press the i key on the keyboard.

It can be seen that when we press the i key, the following changes to install. At this point is the insert mode, we can write data.

 At this point when we write the data, it's time to save and exit.

To save and exit, you need to enter the command line mode.

Entering the command line mode is actually very simple, just press the esc key on the keyboard to enter the normal mode. Then enter normally:

 

 Now enter the command line mode.

Then we are typing wq. wq means write and exit. Then the file is successfully written and saved.

Then at this time we are looking at the contents of this file:

 You can see the data we wrote.

grep 

grep string match

 grep quickly searches a file for a matching character string.

 It can be seen that when we search for the string "hello" in the file a2.txt, the file will be searched, and then the successful match will be displayed. When we add a command line parameter -n, the line number will be added in front.

grep can also search multiple files.

 

 ps

ps view process

 

 But the content of ps view is very limited, we can add some fixed options.

Use ps aux to list all processes on the system.

 

 It can be seen that there are many results, not just those shown in the above figure.

But many times, we don't care about all the processes on the operating system, we just want to see our own processes. You can use it with the grep command.

For example, we want to query the process of mysql.

 The | here is a pipe character, and its function is to use the output of the previous command as the input of the next command.

netstat

netstat -anp query network status. Including ports etc.

 

It can be seen that there is a lot of information at the same time, and we are only part of it here.

This command is also usually used with grep.

For example, if we want to query the port number of mysql, we can use the netstat command plus grep to query.

 

Both ps and netstat commands are usually used with grep.

Use ps to query the pid of a process

Use netstat to query a certain port number

Linux interview questions

1: How to give a process name and query the pid of the corresponding process

 For example: Tomcat 

2: How to give the process name and query the port number for binding

For example: MySQL

 

Guess you like

Origin blog.csdn.net/qq_63525426/article/details/131698585