[Linux] Basic operations (Part 1)

Table of contents:

What is an operating system? ? ?

Log in to the root account (alt+enter is full screen)

01.pwd display path

02.ls lists directories and files

For example: ls -l: displays more detailed attribute information of files or directories under the current path

For example: ls-al -a means all -l means more detailed editing

 For example: ll (equivalent to ls-l, which means you must know how to display the detailed attributes of all files)

 For example: ls -Rl is a recursive expansion, including files under the directory

03.cd double-click the file

Example: cd

 Example: cd.. 

04.touch creates ordinary files

05.mkdir creates an empty directory

06.rmdir deletes empty directories && rm deletes empty directories and ordinary files

07.man online manual

08.cp copy files or directories


We learned how to set up a cloud server in the previous article. Next, we start to learn the operating instructions.

Then we need to have a simple understanding of what an operating system is

What is an operating system? ? ?

The operating system is between software and hardware and plays a role as a link between the previous and the next.

Right: Provide a good, stable and safe operating environment

Right next: Managing software and hardware resources 

Learning command line instructions is a very important means for us to learn the operating system

In terms of development, we have the keyboard first and then the mouse, which means that the command line style comes first and then the graphical interface style.

Next, let’s log in to Xshell


Log in to the root account (alt+enter is full screen)

                            ssh root@IP地址

 And a password window will pop up

 

In this way, you are logged in, and the not logged in in the lower left corner of Xshell has also changed to root login status. 

Use the whoami statement to check who the current user is.


01.pwd display path

Syntax: pwd

Function: Display the directory where the user is currently located

It is equivalent to the following functions of Windows: Genshin Impact! start up!

 Under Linux,    /  is   used as the path separator.

File: file content data + file attribute data

Why use a path to identify a file? Answer: The path from the root directory to the file is unique

Absolute path: The path + file name is unique, also called an absolute path. I want to find test.c all the way down from /. This is called

make absolute path

Relative path: It is equivalent to the current path where the file is located. It is called a relative path, but ../A/bit/test.c

There is no need to retrieve the root directory. Starting from the middle to find the relative position is called a relative path.

Advantages and Disadvantages:

The absolute path must be correct and cannot be wrong. Relative paths are easy! ! ! (*Although there may be some mistakes sometimes)

Relative paths are used in daily operations, and the application scenarios of absolute paths are more official. eg: a configuration in the configuration file

A file under Linux is a multi-tree:

sudo yum install -y tree

You must first install the tree command before you can use it. You can use tree to intuitively see the subsets and listing relationships of files.


02.ls lists directories and files

Syntax: ls [options][directory or file]


Function: For a directory, this command lists all subdirectories and files in the directory. For files, the file name is listed along with other information

breath

Common options:

-a lists all files in the directory, including implicit files starting with .
-d displays the directory as a file, rather than displaying the files below it. For example: ls –d specifies the directory
-i Outputs the index information of the i node of the file. For example, ls –ai specifies the file
-k represents the size of the file in k bytes. ls –alk specifies the file
-l lists file details.
-nReplace the name with a numeric UID or GID . (Introducing UID , GID )
-F appends a character to each file name to indicate the type of the file. "*" represents an executable ordinary file; "/" represents a directory; "@" represents a symbolic link; "|" represents FIFOs ; "= ” means sockets . (Directory type identification)
-r sorts the directory in reverse order.
-t Sort by time.
-s outputs the size of the file after the l file name . (Size sorting, how to find the largest file in a directory)
-R lists files in all subdirectories. ( recursive )
-1 only outputs one file per line.

For example: ls -l: displays more detailed attribute information of files or directories under the current path

For example: ls-al -a means all -l means more detailed

 And we found that there are files of this type in the picture.

. represents the current path

.. represents the upper-level path, such as the cd that will be discussed later.. is to return to the upper-level path. 

 ls -a: Display all files, including hidden files. That is, ls does not show hidden files

In fact, it is equivalent to viewing hidden files under Windows.

image-20220919160208498

 For example: ll (equivalent to ls-l, it must be able to display the detailed attributes of all files)

 For example: ls -Rl is a recursive expansion, including files under the directory


03.cd double-click the file

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

image-20220919144757803

Similar to a tree structure, it is divided into leaf nodes and road nodes. For leaf nodes, the last layer, there can be ordinary files or empty directories, while road nodes can only be directories.

Syntax: cd directory name
Function: Change the working directory. Change the current working directory to the specified directory.

Common options:

cd .. : Return to the upper directory


cd /home/litao/linux/ : absolute path


cd ../day02/ : relative path


cd ~: Enter the user's home directory


cd -: Return to the recently visited directory

Example: cd

 Example: cd.. 

Keep going back to the root directory 


04.touch creates ordinary files

touch is the command used to create ordinary files

Syntax: touch[options]...file...

Function: The touch command parameter can change the date and time of a document or directory, including access time and change time, or create a new one with different parameters.

File exists.

Common options: 

-a    or --time=atime or --time=access or --time=use only changes the access time.
-c    or --no-create  do not create any documents.
-d  uses the specified date and time instead of the current time.
-f  This parameter will be ignored and will not be processed. It is only responsible for solving the compatibility problem of the BSD version of the touch command.
-m    or --time=mtime or --time=modify  only changes the change time.
-r  sets the date and time of the specified document or directory to be the same as the date and time of the reference document or directory.
-t  uses the specified date and time instead of the current time.

In addition, we can also check the file time 

stat 文件名字

We can use touch to update the time

Use touch-m to find that the time is different from before


05.mkdir creates an empty directory

Syntax: mkdir [options] directory name

Function: Create a directory named "dirname" in 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
Directories that do not yet exist will be automatically created, that is, multiple directories can be created at one time

This is also recursive, but what is written after it is -p, not -r. The only special one must not be mistaken.

mkdir –p test/test1 : 递归建立多个目录

Non-recursive:

recursion:

After inspection, it was found that it is indeed a recursive structure:


06.rmdir deletes empty directories && rm deletes empty directories and ordinary files

rmdir is a command corresponding to mkdir. mkdir is to create a directory, and rmdir is a delete command. So rmdir is used to delete

Empty directory.

Syntax: rmdir [-p][dirName]

Applicable objects: All users with permission to operate the current directory

Function: Delete empty directories

Common options:

-p When the subdirectory is deleted, if the parent directory also becomes an empty directory, the parent directory will be deleted together. The rm command can be used with

Delete a file or directory when


rm can delete directories and commands at the same time

Syntax: rm [-firv][dirName/dir]

Applicable to : All users

Function: Delete files or directories

Common options:

  • -f Even if the file attribute is read-only (i.e. write-protected), delete it directly (forced)
  • -i Ask for confirmation one by one before deleting
  • -r deletes the directory and all files under it ( recursive deletion )

Delete the database and run the graph: (If you do this, the cloud server will hang) rm-rf /

for example:


 

07.man online manual

Linux commands have many parameters, and it is impossible for us to remember them all. We can get help by checking the online manual. Access Linux Hands
The command for the album is man
Syntax: man[options] command 
Common options:
-k Search online help based on keywords
num is only found in chapter num
-a displays all chapters. For example, man printf starts searching from the first chapter by default and stops when it knows it. Use the a option. When pressing q to exit, it will continue to search until all chapters are searched. .
man man can explain the manual

I learned that the manual is divided into nine chapters and we generally only use the first three chapters.

The first three chapters:

  • Chapter 1: It’s an ordinary command
  • Chapter 2: System calls, such as open, write, etc. (Through this, you can at least easily find out what header files need to be added to call this function) Compatible with c Not compatible with high-level languages ​​such as python and c++
  • Chapter 3: It is a library function, such as printf, fread4 is a special file, that is, various device files under /dev

And you can use the man n (Arabic numerals) function to specifically search for the information in Chapter 3 (you need to download sudo for this)


08.cp copy files or directories

Syntax: cp[options] source file or directory (src) destination file or directory (dest)

Function: copy files or directories (not mv)

Note: If two or more files or directories are specified at the same time, and the final destination is an existing directory , it will replace the previous

All files or directories specified are copied to this directory. If multiple files or directories are specified at the same time, and the final destination is not an already

If the directory exists , an error message will appear (that is, cp does not have the creation function)

Common options:

-f or --force  forcibly copies a file or directory, regardless of whether the destination file or directory already exists
-i or --interactive ask user before overwriting files
-r recursively processes files and subdirectories in the specified directory together. If the form of the source file or directory does not belong to the directory
or symbolic links, they will all be treated as ordinary files.
-R or --recursive recursive processing, processing files and subdirectories in the specified directory together

This error is reported because dirfile is a directory and requires recursion to cp.

The error in the picture above is because I wrote cp-r, but it actually means cp space-r.

If you write the spaces and syntax well, you won't make any mistakes.

It’s already 12:25. My eldest sister is going home today. It doesn’t matter if I stay up late hahh

Guess you like

Origin blog.csdn.net/weixin_62985813/article/details/131956729