[Linux] Linux study notes

Linux study notes

Chapter 1: Getting to Know Linux

1.1 Hardware, software and operating system

  1. Hardware: the general term for various physical devices composed of electronics, machinery, and optoelectronic components in a computer system;
  2. Software: It is the interface and bridge between the user and the computer hardware. The user communicates with the computer through software, and the operating system is a type of software;
  3. Operating system: A type of computer software. As a bridge between users and computer hardware, schedule and manage computer hardware for work;

Common operating systems:

  • PC: Windows,Linux,Mac Os;
  • Mobile terminal: Android, ios, Hongmeng;

1.2 Linux components

The Linux system consists of the following two parts:

  • Linux system kernel;
  • system-level applications;

The kernel provides the most core functions, such as scheduling cpu, scheduling memory, scheduling file system, scheduling network communication, scheduling IO and other system-level applications, which can be understood as factory-built programs for users to quickly get started with the operating system; the Linux system kernel
is Open source, reasoning from its components, which means that manufacturers only need to integrate their own system-level applications to launch their own Linux distributions. Common Linux systems such as Ubuntu, CentOS, etc. are released in this way;

1.3 Linux system installation

Please install the linux operating system you want by yourself.

1.4 WSL

windows subsystem for Linux.
It is a Linux subsystem used in the windows system. You can obtain the Linux system environment in the Linux system above the windows system, and directly connect to the computer hardware, directly use the physical hardware of the host computer, and build a Linux operating system. system, and will not affect the operation of the windows system. WSL is a built-in function of windows, which needs to be enabled and does not need to be downloaded.
WSL deployment method: Deploy WSL

1.5 Virtual machine snapshot

During the learning phase, it is very likely that the current system will be damaged due to misoperation. The state of the current virtual machine can be saved through a snapshot, and the saved state of the virtual machine can be restored through the snapshot in the future. This operation is more efficient in saving snapshots in the shutdown state.
How to use Linux system snapshot

Chapter 2: Linux Basic Commands

2.1 Linux directory structure

Like windows, the directory structure of Linux is a tree structure. The windows system can have multiple drive letters, but there is no concept of drive letters in linux. There is only one root directory: /, and all files are under it. That is to say, there can be multiple drive letters in windows, and then there can be many trees, but there is only one tree in the linux system.

2.2 The description method of Linux system path

  • The hierarchical relationship between paths in the Linux system is represented by: /; the beginning / is the root directory, and the following / is the hierarchical relationship.
  • The hierarchical relationship between paths in the windows system is represented by: \;

2.3 Command line and commands

  • Command line: that is, the Linux terminal, which is a command prompt interface. The operating system is operated in the form of pure characters, and various characterized commands can be used to generate operating instructions for the system;
  • Command: It is a Linux program. A command is a Linux program. The command has no graphical interface and can provide character feedback in the command line terminal;

2.4 Basics of Linux commands

Linux command basic format:

command [-options] [-parameters]

  • command : the command itself;
  • options : Optional options, you can control the behavior details of the command through options;
  • parameter : Optional parameters, most of which are used to point to the target of the command, etc.;

Example:

ls -l /home/user

Display the contents of the /home/user directory in the form of a list;

cp -r test1 test2

Copy the folder test1 to become test2

ls command

Function: List the contents of the directory.

ls [-a -l -h] [linux路径]

-a -l -h are optional parameters

  • -a : all, list all files, including hidden files and folders; those starting with . are hidden files and folders of the Linux system.
  • -l : list displays the content in a vertical list and displays more information;
  • -h : list the size of the file in a readable way, this option must be used with -l

[linux path] is an optional parameter for this command. If you do not use options and parameters, use the ls command body directly, which means: list the contents of the current working directory in a tiled form

Home directory and current working directory

  • Home directory: The personal account directory of each Linux operation user in the Linux system, the path is in /home/username.
  • Current working directory: The Linux command line terminal will load the Home directory of the currently logged in user as the current working directory by default when it starts, so the ls command lists the contents of the Home directory

cd command

Function: switch directory. change directory

cd [Linux路径]

The cd command does not need options, only parameters, indicating which directory to switch to;
the cd command is executed directly, without parameters, which means returning to the user's Home directory;

pwd command

Function: View the current working directory. print work directory
has no options and no parameters;
relative path, absolute path and special path symbols
Absolute path: start from the root directory, describe the general way of writing the path, path description starts with /;
relative path: start from the current directory, describe the path A way of writing, the mujing description does not need to start with /;
special path symbols:

  • .: Indicates the current directory;
  • ...: Indicates the upper level directory;
  • ~: Indicates the Home directory;

mkdir command

**Function:** A new directory can be created through the mkdir command. Make Directory

mkdir [-p] linux路径

The parameter is required, indicating the Linux path
-p is optional, indicating that the parent directory that does not exist is automatically created, and is suitable for creating continuous multi-level directories;

file operation command

touch command

Role: create a file

touch Linux路径/文件

The touch command has no options, and the parameter is required, indicating the file path to be created. Relative, absolute, and special path symbols can be used;

cat command

Function: view the content of the file

cat Linux路径/文件

cat also has no options, only required parameters, the parameters indicate: the file path to be viewed, relative, absolute, special path, etc. can be used;

more command

Function: view the content of the file.
The difference from cat is that cat displays all the content directly, and more supports page turning. If the file content is too much, it can be displayed page by page; space to turn pages, q to exit;

more Linux路径

There are also no options, only required parameters, and the parameters indicate: the file path to be viewed, relative, absolute, special paths, etc. can be used;

cp command

Function: copy files or folders, cp comes from the English word copy

cp [-r] 参数1,参数2

The -r option, optional, is used to copy folders, indicating recursion;
parameter 1, the Linux path, indicates the copied file or folder;
parameter 2, the Linux path, indicates the place to be copied;

mv command

Function: move files or folders, mv comes from the English word move

mv 参数1,参数2

Parameter 1, Linux path, indicates the file or folder to be moved;
Parameter 2, Linux path, indicates the place to be moved;
if the file names of parameter 2 and parameter 1 are inconsistent, it indicates moving and renaming;

rm command

Delete files or folders, rm comes from the English word remove

rm [-r -f] 参数1,参数2...参数n

-r is used to delete the folder
-f force, force deletion without prompting. [Ordinary users will not be prompted to delete content, only root users will be prompted to delete content; so ordinary users do not use the -f option. The permissions of ordinary users here are actually set in advance, that is, the default is safe, but the permissions of the root user are too high, and it is easy to misuse, so there will be a prompt when the root user deletes the file] The parameter indicates the one to be
deleted Files or folders, separated by spaces;
the rm command supports wildcards *

  • test*: indicates any content beginning with test;
  • *test: indicates any content ending with test;
  • test : Indicates any content containing test;

su - root temporarily switch users;
exit command returns to normal users;

find command

which command

Function: Find the location of the command, only for the command;
the essence of all the commands mentioned above is actually a linux program, so how to find the location of these programs? which can be used here

which 要查找的命令
find command to search by name

Search for the specified file

find 起始路径 -name "被查找文件名“

find / -name “test”

find command to search by file size
find 起始路径 -size +|-[kMG]
  • +,-: means greater than less than;
  • n: Indicates the size of the number
  • kMG means size unit, k (lowercase) means kb, M means MB, and G means GB;

Example:

  1. Find files smaller than 10kb: find / -size-10k
  2. Find files larger than 100M: find / -size+100M
  3. Find files larger than 1G: find / -size+1G
grep command

Role: filter file lines from the file by keyword

grep [-n] 关键字 文件路径

option -n, optional, indicates to display the line number of the matching line in the result.
Parameter keyword, required, indicates the filtered keyword, with spaces or other special symbols, it is recommended to use " " to surround the keyword;
parameter file path, required, indicates the file path of the content to be filtered, which can be output as content port;

wc command

Function: Quantity statistics, you can count the number of lines and words in the file through the wc command;

wc [-c -m -l -w ] 文件路径

-c: Count the number of bytes
-m: Count the number of characters
-l: Count the number of lines
-w: Count the number of words
File path: the file to be counted, which can be used as a content input port;

pipe character |

Use the result of the command on the left of the pipe symbol as the input of the command on the right
ls | grep test
ls -l /usr/bin | wc -l

echo command
echo 要输出的内容

It is recommended to enclose it in double quotes.
The function of '' is: the content enclosed by it will be executed as a command;
echo 'pwd'
outputs the content of pwd after execution;

redirect symbol

>, write the result of the command on the left to the file specified on the right side of the symbol;
>>, write the result of the command on the left side to the file specified on the right side of the symbol;

  • echo “Welcome” >> haha.txt;
  • echo "Welcome1" > haha.txt;//Execute again, overwrite the new content
  • echo "Welcom2" >> haha.txt;//Execute again, add new content
tail command

**Function: **View the content at the end of the file and track the latest changes of the file;

tail [-f -num] Linux路径

-f, means continuous tracking;
-num, means to see how many lines at the tail, the default is 10 lines;
here -f means continuous tracking:
tail -f -10 1.txt
If -f is used, the 1.txt file will be output here The last 10 lines of , but it will not stop. If you open another terminal and modify the content of 1.txt, at this time, the data in the last 10 lines will change, that is, the continuous tracking effect. Terminate tracing with ctrl c.

Guess you like

Origin blog.csdn.net/weixin_43717839/article/details/131982705