First understanding of operating system and Linux common commands (Part 1)

Table of contents

1: Introduction to the operating system

Two: Introduction to Linux

what is linux

The role of Linux

non-graphical Linux interface

Building a Linux environment

Three: File structure under Linux

⭐The structure of the Linux organization file is a multi-fork tree

file path 

Hidden files under Linux

Four: Linux basic instructions 

create user related

View and jump to the working directory

Create and delete files and directories

copy and rename


1: Introduction to the operating system

       An operating system is software that manages a computer's hardware and software resources and provides an environment that enables users and programs to interact effectively . The main functions of an operating system include managing the system's memory, processors, and devices, providing a file system to store and access data, and managing permissions and security for users and applications .

An operating system typically includes the following components:

  1. Kernel: As the core part of the operating system, it is responsible for managing and allocating system resources such as memory and processor. It provides an interface to interact with the hardware and handles low-level tasks such as process scheduling and device drivers.
  2. File System: This is the component of the operating system responsible for managing files and directories. It provides a way to organize and access files, enabling users and applications to store and retrieve data.
  3. User Interface: An operating system provides a way for a user to interact with a computer. Common user interfaces include command line interface and graphical user interface . A command line interface interacts with the system through command line input and output, while a graphical user interface uses input devices such as graphics and a mouse to interact.

The operating system is the core software of a computer, which manages and coordinates various resources of the computer, and provides a user-friendly interface, so that the computer can run efficiently and applications can run smoothly. ( The most important thing is user-friendly )


Two: Introduction to Linux

what is linux

Linux is an open source operating system that is secure and free.

(Linux official website: https://www.kernel.org/ )

The role of Linux

  • Linux plays an important role in the server world . Many Internet companies use Linux as a server operating system because it is stable, secure and efficient . At the same time, Linux also supports multitasking and multi-user access, which allows it to handle multiple user requests at the same time and maintain system stability.

  • In addition, Linux is also widely used in embedded systems , such as smart phones, TVs, routers, etc. This is because Linux is highly customizable and flexible and can be configured and optimized according to needs. At the same time, many developers and communities also provide a large number of software and tools for Linux, making it widely used in embedded systems.

non-graphical Linux interface

Linux can support command line interface and graphical interface at the same time, but the graphical interface is basically not used in actual development .

The reasons are as follows:

  1. Under the command line interface, users can use some shortcut keys and commands to perform various tasks, which can complete the work more quickly. For some tasks that require frequent operations and batch processing, the command line interface may be more convenient than the graphical interface .
  2. The command line interface is better for remote management in some cases. Through remote login tools such as SSH, users can perform command line operations without physical contact. This is very important for remote servers and supercomputers .
  3. Compared with the graphical interface, the command line interface occupies less system resources and is more beneficial to the stability and efficiency of the system. This is especially important for certain configuration-constrained devices and resource-constrained environments.

Building a Linux environment

Three ways to build a Linux environment:

  1. Buy a cloud server (simple operation, need meters, but Linux supports multi-user operation, you can find someone to share)
  2. Install a virtual machine (installation is more troublesome, and it is not easy to adjust if it is wrong)
  3. Install Linux directly, dual system (not recommended, very dangerous)

Here we mainly talk about the first method

Step 1: First purchase a cloud server (Tencent Cloud, Huawei Cloud, etc., you only need to buy the cheapest one from a learning perspective), then make sure that the cloud server is running, and record the public network IP (note that it is a public network, generally click the console You can see the relevant information), reset the password (this is very critical).

Step 2: Install XShell ( XShell is a remote terminal software )

XShell official website (just install the home version): https://www.xshell.com/zh/free-for-home-school/

Step 3: Use XShell to log in to the host

Copy-paste under XShell is a bit different:

Copy: ctrl + insert

Paste: shift + insert

The shortcut key can be set here, Tools->Options->Keyboard and Mouse->Edit

You can search for the specific modification and the other two ways to build the Linux environment


Three: File structure under Linux

⭐The structure of the Linux organization file is a multi-fork tree

file path 

(1) Absolute path

The absolute path of a file refers to the complete path starting from the root directory, which is used to accurately locate the location of the file in the file system. In the Linux system, the absolute path of a file starts with a slash (/).

(2) Relative path

A relative path to a file is a path that determines the location of the file relative to the current working directory or the directory in which the current file resides. A relative path does not contain the full file system path, but instead specifies the location of the file based on its current location.

Hidden files under Linux

Files starting with . under Linux are called hidden files

Hidden files in every directory 

There will be two hidden files. and .. in every directory of Linux

where . represents the current path

.. represents the path of the parent directory

. and .. play an important role, as you will understand later


Four: Linux basic instructions 

⭐Note : Generally, if no path is added, the current directory is the default, and the file is the same. Options can be combined, for example, -l -i can be combined into -li.

create user related

  1. adduser username (add user)
  2. passwd username (set user password, knocking will not display, press Enter to complete the setting)
  3. whoami (check the current user)
  4. userdel username (delete user)
  5. cat /etc/passwd |cut -f 1 -d : (view all users)

Adding users and setting passwords are all done under the root user

Now log in to the aaa user again 

 


View and jump to the working directory

pwd command (view current path)


ls command (view subdirectories and files in the current directory)

Syntax: ls [option] [directory or file]

Common options:

  • -l display detailed information about the file
  • -a list all files (including hidden)
  • -i Displays the inode number of a file or directory. An inode is a data structure in a file system that stores file or directory attributes and associated metadata. Each file or directory corresponds to a unique inode number, and the corresponding file or directory can be found through the inode number
  • -d only look at the names of the directories themselves and not their contents  
  • -t sort by time
  • -s displays the size of the file directory
  • -R list files in all subdirectories


clear command (clears the screen) 


 cd command (change directory)

Some commonly used operations (.. represents the parent directory):

  • cd .. (return to parent directory)
  • cd /home/litao/linux/ (absolute path)
  • cd ../day02/ ( relative path)
  • cd ~ (enter user directory)
  • cd - (returns the most recently visited directory)

Create and delete files and directories

touch command (create file, change date of document and directory)

Syntax: touch [options] [filename]

Options (rarely used):

  • -a or --time=atime or --time=access or --time=use only change the access time
  • -c or --no-create do not create any documentation
  • -d use the specified datetime instead of the current time
  • -f This parameter will be ignored and not processed, it is only responsible for solving the compatibility problem of the BSD version touch command
  • -m or --time=mtime or --time=modify only change the change time
  • -r Set 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 use the specified datetime instead of the current time


mkdir command (create new directory)

Options: -p (create multiple directories recursively, mkdir -p bbb/kkk/LLL/mmm)


 rmdir command (delete empty directory)

Option: -p ( When the subdirectory is deleted, if the parent directory also becomes an empty directory, the parent directory will be deleted together )

rm command (remove files and directories)

Common options:

  • -f Even if the file attribute is read-only (that is, write-protected), delete it directly
  • -r deletes the directory and all files under it, if not added, only the empty directory can be deleted
  • -i Ask for confirmation one by one before deleting


copy and rename

cp command (copy files and directories)

Syntax: cp [options] source file or directory target file or directory

Explanation: The cp command is used to copy files or directories. If more than two files or directories are specified at the same time, and the final destination is an existing directory, it will copy all the previously specified files or directories to this directory. . If multiple files or directories are specified at the same time, and the final destination is not an existing directory, an error message will appear

options:

  • -f Forcefully copy a file or directory, regardless of whether the destination file or directory already exists
  • -i ask user before overwriting files
  • -r Process 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


mv command (move file or directory, rename) 

Syntax: mv [options] source file or directory target file or directory

options:

  • -f If the target file already exists, it will be overwritten without asking
  • i If the target file (destination) already exists, it will ask whether to overwrite

Guess you like

Origin blog.csdn.net/2301_76269963/article/details/131488580