Linux: Getting Started Learning Knowledge and Common Instructions

Getting Started

operating system concept

The operating system (Operating System) is software, and the existence of the operating system is to make the computer easier to use, which is the fundamental essence of the operating system

In the computer, it can be divided roughly like this:

insert image description here
An operating system is a piece of software that manages hardware and software resources. How do you understand this sentence?

The first program we write in C language learning is generally:

printf("hello world!");

Judging from the final effect, the printf function prints the sentence hello world on the display screen. We can see this sentence through the display screen. In fact, from this program to the final printing on the display screen, it needs to be processed. Some complicated processes, why can the programs we write finally access the hardware? This must be inseparable from the ability of the operating system

Use of Linux machines

Here I use the XShell machine, and the subsequent learning will also use XShell for learning

login command

Enter the Linux interface, enter

ssh [email protected](ip地址)

Instructions on Linux

For those of us who are used to Windows, one of the things we are not used to when switching to Linux is the various commands of Linux. In simple terms, you can use the mouse and keyboard to complete a series of tasks on Windows, such as entering a directory to find a file, Copy and paste files... and all other operations, and these operations are done with the keyboard and mouse, and the big difference on Linux is that all these are replaced with instructions, but one thing we need to know is the graphical interface and the command line The essence of the operation is the same, both directly or indirectly operate the operating system

The instructions we use are essentially written by executable programs. Instructions, tools, executable programs... are all executable programs in essence.

Then after introducing these, you can officially start learning Linux and open the door to the new world


In the introduction of linux instructions, for the instructions that I have not fully learned, I only write what I have learned, and I will supplement the follow-up if I have not learned

Complementary to file knowledge

Definition of a file and some implications

ls is an instruction to view directories and files, so before doing this, you must first have some basic understanding of the stored files

Create a new file, does this file take up space?
The answer is to occupy! The name of the file, the size of the file, the modification date of the file...these will occupy a certain amount of space in the computer memory, because these are descriptions of file attributes , and files can be expressed as content plus attributes. From the perspective of data, The content of the file and the attributes of the file are both data, and they all have to leave their own place in the disk hard disk, and the ls command we will talk about below is the operation on the attributes of the file

What are the files at the beginning of . and the parent directory of this level directory?

In Linux, files starting with . are hidden files

In the Windows graphical interface, if you want to return to the upper-level directory, you only need to choose to return, but in the Linux command-level interface, you need to use the current-level directory and the upper-level directory:

.      表示的是本级目录,也叫做当前所在目录
..     表示的是上级目录,后面讲的cd指令就是去特定的目录所用的

.The function of this level directory: used to execute a program, if there is a program a.out, and now I want to execute it, I should use the following command

正确的方式:
./a.out
不正确的方式:
a.out

And the meaning of this ./ is to find this program and run it

Storage of files and directories

In the Linux system, the files and directories on the disk are formed into a directory tree, and each node is a directory and a file. Specifically, it can be expressed as follows:

insert image description here
It can be compared to the concept of the Windows system. In the Windows system, there are many files and folders under the C drive, and there are many files and folders in the folders... The same is true in Linux. The root directory has user, dev, There are many files and folders such as home, and folders may have more branches, so the root directory is actually a multi-fork tree structure

Why is such a structure adopted in the Linux system?

There must be a file with the same name in the system, and only in this way can the unique identification file of the file be found, because for any node, it has and only one parent node

Absolute and Relative Paths

When describing the location of a file in the system, there are two representations, namely absolute path and relative path. The absolute path refers to the distance from the root directory to the file, while the relative path refers to the Relative to where you are, for example, now to indicate the path of the bin file in the above figure, the directory I am currently in is under the lib path

用绝对路径来表示就是
/root/user/bin
用相对路径来表示就是
../bin/a.txt

ls command

Basic syntax: ls project directory or file
Function: For a directory, use this command to list all subdirectories and files under the directory; for a file, list the file name and other information Commonly used
commands

-a: List all files in the directory, including hidden files at the beginning of .
-l: View detailed information in the directory and display more information about the file

ls -l and ls -a can be used together to show both hidden files and more information
insert image description here
insert image description here

pwd command

Syntax: pwd
Function: Display the directory where the user is currently located

This is a very simple command to see which directory we are currently in

cd command

Syntax: cd directory name
Function: change the working directory, transfer the current working directory to the specified directory
For example:

cd … : Return to the parent directory
cd /root/litao/linux/ : Absolute path
cd …/user/ : Relative path
cd ~: Enter the user’s home directory
cd -: Return to the most recently accessed directory

touch command

Syntax: touch option file
Function: The touch command parameter can change the date and time of the document or directory, including access time and change time, or create a file that does not exist.
Common options:

mkdir command

Syntax: mkdir option dirname
Function: Create a directory named dirname under the current directory
Common options:

-p, --parents can be a path name. At this time, if some directories in the path do not exist yet, after adding this option, the system will automatically create
those directories that do not exist, that is, multiple directories can be created at one time

rmdir command

rmdir is an instruction corresponding to mkdir, mkdir is used to create a directory, and rmdir is used to delete commands
Syntax: rmdir -p dirname
Function: Delete empty directories
Common options

-p When the subdirectory is deleted, if the parent directory also becomes an empty directory, delete the parent directory together

rm command

Syntax: rm option dirname
Function: Delete files and directories
Common options

-f Even if the file attribute is read-only (that is, write-protected), delete it directly
-i ask for confirmation one by one before
deleting -r delete the directory and all files under it

man command

This command is similar to a help document. When we encounter commands that we are not familiar with in Linux, we can use this help document to solve the problem for us: Syntax: man option command
Function
: Help us find the meaning of some commands

cp command

Syntax: cp option source file or directory target file or directory
Function: copy file or directory
Description: cp command is used to copy files or directories, if more than two files or directories are specified, and the destination of the last one is an existing one directory, all previous files or directories will be copied to this directory. If multiple files or directories are specified and the last destination does not exist, an error will be reported. Common options
:

-f or --force forcibly copy files or directories, regardless of whether the destination file or directory already exists
-i or --interactive ask the user before overwriting files
-r recursive processing, and process the files and subdirectories in the specified directory together. If the form of the source file or directory does not belong to a directory or a symbolic link
, it will be treated as an ordinary file
. -R or --recursive recursive processing, and the files and subdirectories in the specified directory will be processed together

mv command

The mv command means move, which can be used to move files or change the name of files. This is a commonly used command under Linux to back up files or directories
Syntax: mv option source file or directory target file or directory
Function:

  1. Depending on the type of the second parameter in the mv command (whether it is a target file or a target directory), the mv command renames the file or moves it to a new directory.
  2. When the second parameter type is a file, the mv command completes the file renaming. At this time, there can only be one source file (it can also be the source directory name), and it will rename the given source file or directory to the given target filename.
  3. When the second parameter is an existing directory name, there can be more than one source file or directory parameter, and the mv command will move the source files specified by each parameter to the target directory.
    Common options:

-f: force means to force, if the target file already exists, it will not ask but directly overwrite
-i: if the target file (destination) already exists, it will ask whether to overwrite!

cat command

Syntax: cat option file
Function: view the content of the target file
Common options:

-b number non-empty output lines
-n number all output lines
-s do not output multiple empty lines

more command

Syntax: more option file
Function: similar to cat
common options:

-n number all lines of output
q exit more

echo command

Echo is followed by the content. By default, the content will be printed to the display screen, and the content can be printed to a file by outputting redirection commands.

insert image description here

output redirection

First of all, we must have an intuitive understanding of Linux. Everything under Linux is a file. Whether it is written from the monitor or from the keyboard, we can regard this process as a file operation. The concept of output redirection is introduced below.

So how to understand the concept that everything is a file? Here echo is to output the content to the display screen. We can regard the operation of echo writing to the display screen as writing content to a file called the display screen, and output redirection is to output this section to the display file. The content is output to other files, so something like the following can be done

insert image description here
So what is an append redirect? How is it different from output redirection?
The append redirection and output redirection here are essentially the same as a and w in the file operation.
Append redirection will not overwrite the original file, but will only increase on the basis of the original file, while output redirection will overwrite the original file. rewrite

insert image description here

less instruction

Here is an introduction to the functions and functions of the less command

First create a file in nano, which contains the hello linux
insert image description here
less tool command is a tool for paging display of files or other output, which is very powerful in Linux

Syntax:
less parameter file
Function: less is similar to more, but you can use less to browse files at will, while more can only move forward, but not backward, and less will not load the entire file before viewing.
Common options:

-i ignore case when searching
-N show line number for each line
/ string: function to search down "string
"
? or ? related)
N: Repeat previous search in reverse (related to / or ?)
q:quit

find command

The find command under Linux searches for files in the directory structure and performs specified operations.
The find command under Linux provides quite a lot of search conditions, and the function is very powerful.
Syntax: find pathname -options
Function: Used to find files in the file tree and make corresponding processing (may access disk)
Common options:
-name Find files by file name

grep command

Syntax: grep [options] Search for string files
Function: Search for strings in the file and print out the found lines
Common options:
-i: Ignore the difference in case, so the case is treated as the same
-n: Output the line number by the way
-v: Reverse selection, that is, display the line without the content of the 'search string'

zip/unzip command

Syntax: zip compressed file.zip directory or file
Function: Compress directory or file into zip format
Common options:
-r recursive processing, process all files and subdirectories under the specified directory together


Linux instructions are just some basic operations to master

Guess you like

Origin blog.csdn.net/qq_73899585/article/details/131888122