[Linux] Common basic instructions in Linux operating system 1

Table of contents

Preface

operating system:

concept:

 Classification:

 component:

Common operating systems:

Basic Linux instructions:

pwd command:

ls command:

ls -l:

ls -a:

 cd command:

 touch command:

mkdir command:

tree command:

 rmdir command:

 rm command:


Preface

One of the biggest advantages of the Linux platform is its stability. Unlike Windows, which will not slow down after a few years of use, Linux will not slow down even after a few years of use. Moreover, for each patch and update, Linux does not need to restart the system like Windows, and can be updated directly.

At the same time, the open source nature of Linux also ensures that it has better security and efficiency. Therefore, learning Linux is very necessary.

Before understanding the basic instructions of Linux, let’s first understand what an operating system is: 

operating system:

concept:

Operating System (OS) is a set of interrelated system software programs that control computer operations, use and run hardware and software resources, and provide public services to organize user interaction.

 Classification:

According to the operating environment, operating systems can be divided into desktop operating systems, mobile operating systems, server operating systems, embedded operating systems, etc.

 component:

Kernel, drivers, interfaces, peripherals.

Common operating systems:

Windows operating system, ios operating system, Linux operating system, Unix operating system.

Basic Linux instructions:

pwd command:

Everything under Linux is managed and saved as files, which is somewhat different from Windows. In Windows, directories are folders, but in Linux, even directories are files. That is: everything under Linux is a file.

Syntax : pwd

Function : Display the directory where the user is currently located

Common options : none

We can use this function in Xshell:

 We enter the pwd command in Xshell: it will show us the location of the directory we are currently in.

As shown in the figure: / represents the root directory, root represents the user name, and /root is our home directory, just like the user directory under Windows:

 

 There are generally two types of home directories:

Ordinary user: /home/username

root user:/root

ls command:

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 .

Common options:

-a: List all files in the directory, including implicit files starting with .

-d: Display the directory like a file, rather than displaying the files below it. For example: ls –d specifies the directory

-i: Output the index information of the i node of the file. For example, ls –ai specifies the file

-k: Represents the file size in k bytes. ls –alk specifies the file

-l: List file details .

-n: Use numeric UID or GID instead of name.

-F: Attach a character after each file name to indicate the type of the file. "*" indicates an executable ordinary file; "/" indicates a directory; "@" indicates a symbolic link; "|" indicates FIFOs; " =" means sockets. (Directory type identification)

-r: Sort the directory in reverse order.

-t: Sort by time.

-s: Output the size of the file after l file name. (Size sorting, how to find the largest file in a directory)

-R: List files in all subdirectories. (recursion)

-1: Only output one file per line.

Here is an example:

In our home directory, if we want to see what is in our home directory, we can use our ls command:

 We can find that there are two directories under our home directory. And yum and install are general files.

Here is a supplement, the file type corresponding to the color of the file in Linux:

Blue: Directory.

White: General documents. Such as text files, configuration files, source code files, etc.

Green: executable file.

Yellow: device files.

Red: compressed file.

Gray: other files.

Flashing red: There is a problem with the linked file.

Light blue: linked files.

 The following introduces two commonly used ls commands to use with function options:

ls -l:

If we want to view the detailed information of all files in a directory , we can add the -l option after the ls command to see the detailed information of the files. (such as time and size)

ls -a:

When our ls command is used with the -a function option, we can see all files in the directory (including hidden files). This is used together with the -l command.

 Here. means the current directory.. means the upper-level directory. (ps: Files starting with . are hidden files.)

 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.

 

Syntax: cd directory name

Function: Change the working directory. Change the current working directory to the specified directory.

Example:

cd ..: Return to the upper directory

cd /home/litao/linux/: Absolute path  The absolute path refers to the path to locate the directory starting from the root directory. For example, if we want to enter test.c, we can directly cd /root/study/test.c

cd ../day02/: Relative path A  relative path refers to entering another file from the current path. For example, we are in lib now and we want to enter test.c. We can do this: cd ../../root/study /test.c

cd ~: Enter the user's home directory. (The root user is /root)

cd -: Return to the recently visited directory.

ps: Path separator: / (be careful not to confuse it with Windows, the path separator of Windows is \).

 touch command:

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

Function: The touch command parameters can change the date and time of a document or directory, including access time and change time, or create a new file that does not exist.

Common options:

-a: or --time=atime or --time=access or --time=use only change the access time.

-c: or --no-create does not create any documents.

-d: Use 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 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 date and time instead of the current time.

Currently, I am still learning Linux. The most common use of touch is to create a new file. Generally, I touch the file name directly to create a new file. We will improve it later when we understand other functional options.

Note: touch can also use paths to create files. For example, we want to create an English.txt file in study. We can touch /root/study/English.txt directly.

If we are now in the dev directory, we want to create a tt.txt under study.

It can be created like this: touch ../root/study/tt.txt

mkdir command:

Syntax: mkdir [options] dirname...

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 will automatically create those directories that do not yet exist, that is, multiple directories can be created at one time.

Example: We create a multi-level directory under /root:

 We can see that mkdir can only create one first-level directory at a time. If you want to create a multi-level directory, add the -p function option.

tree command:

Syntax: tree path (default is the current directory)

Function: Display the subdirectories and files in the current directory in a tree shape.

ps: Some users will report when using the tree command 

command not found. That is, the command cannot be found.

This is because you have not installed this command. You only need to enter the following command to install it:

yum install -y tree

Effect display: currently the tree in the root directory

 rmdir command:

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

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.

Above we created a multi-level directory d1 in root. Now let's try to delete it.

 As a result, it cannot be deleted because rmdir can only delete empty directories. But if we want to delete this multi-level directory, we can just add the -p function option. As shown in the picture:

 rm command:

The rm command can delete files or directories 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 (that is, write-protected), it will be deleted directly.

-i: Ask for confirmation one by one before deleting

-r: Delete the directory and all files under it

Note: -f is a forced deletion, which can be deleted even if you don't have permission.

When we deleted the d1 directory above, the system told us that we cannot delete directories that are not empty. Now we can use rm to do it and delete everything in it. For example: delete our ccode directory and its internal files.

 The above is today’s instruction operation learning sharing, I hope it can help everyone.

Guess you like

Origin blog.csdn.net/m0_74459723/article/details/127817052