Beginner [linux] basic commands "ls, cd, pwd, mkdir"

Table of contents

Table of contents:

1. ls command

2. cd command

3. pwd command

4. mkdir command


1. ls command

1. Function: The function of ls is to list the working paths in the directory.

2. Syntax: ls [-a -h -l] Linux path

        (1) When the ls command does not use parameters, it means: list the contents of the current directory .

        (2) When using parameters , the content of the ls command means: specify a working path , that is, list the contents under the specified working path.

3. Practical demonstration

Practical demonstration:

1. Do not use parameters or options.

ls can be used without parameters , which means listing the contents of the current working directory.

For example:

 2. Use parameters

"/" means root. Adding "/" after ls means listing the contents of the "\" directory. (Note that you need to add parameters, that is, the working directory, and add a space in front to separate them )

 3. Use options

(1), "-a" means to display the hidden content in the working directory.

example:

Before using "-a", we can find that there is only content without the "." prefix , but after adding -a, there are a lot more content with the "." prefix, which is the hidden content in the home directory .

(2), "-h" and "-l", these two options are generally used together.

We first switch to the "/" (root) directory and use the cd command, which will be discussed later. Then we only use the "-h" option first, which is no different than before not using it .

Obviously, there is no difference.

Let's use the "-l" option to see what happens.

Do you feel that the change is not just a little bit, but a really big change? The "-l" option displays the contents of the current directory in columns, and the content is displayed in more detail , including the creation time and memory size. etc. This is what the "-l" option is used for.

Let's see what happens  when we use "-l" and "-h" together .

We can find that when "-h" is not added, the file memory size is displayed in bytes, but after "-h" is added, the file memory is displayed in units of k if it is greater than kb and less than mb. If the content is not larger than kb, it will not change. If it is larger than mb and smaller than gb , it will be displayed in the form of mb, and the subsequent memory size units will also be pushed back in sequence.

3. Use parameters, that is, linux path

 We can see that our current working directory is in the home directory ( "~" means home directory ).

And if we want to view the work content under the root directory ("/") , we only need to give the parameter "/".

example:

 The above is the content of the command.


2. cd command ( English name: Change Director )

1. Function: Switch working directory

2. Syntax: cd Linux path

        (1) The cd command does not require options, only parameters, indicating which working directory to switch to.

        (2) The cd command is executed directly, which means switching to the home directory.

3. Practical demonstration

Practical demonstration

 We can see that we were in the home directory at the beginning, and after using the cd / command, we switched to the "/" directory .

When we want to return to the home directory , we can directly enter the cd command, or we can enter the cd ~ command.

Example: Just enter cd

      Enter the cd ~ command:


3. pwd command

1. Function: View the current directory

2. Syntax: pwd

                pwd does not require options or parameters, just enter pwd directly

3. Practical demonstration

Practical demonstration

Enter pwd directly, and you can see that we are in the user tao directory under the home directory under the root directory. 

4. mkdir command (English name: Make Director)

1. Function: Create a new directory (folder)

2. Syntax: mkdir [-p] parameter

                The parameter is required, that is, the path to create the Linux file, both relative and absolute paths are acceptable.

                The option is optional, indicating that there is no parent directory automatically created, which is suitable for creating continuous multi-level directories.

3. Practical demonstration

Practical demonstration

 After entering mkdir test1 , it means that test1 is created in the current directory , and then entering the ls command, we can easily find that there is an extra test1.

We can also enter the absolute path , and the absolute path starts in the root ("/") directory, gradually pushes back to our current directory , and then enters /test2 to create a test2 directory.

 We can also use relative paths. We have already created test2. When we want to create a test in test2, we can directly enter mkdir test2/test and then enter the ls command. We find that the test is created in test2.

We can also use special path characters , "~" represents the user in the home directory, enter mkdir /test3, we can easily find that the test3 directory has been created.

Use of options: When we want to create continuous multi-level directories, we can use the -p option

example:

When we have not created consecutive multi-level directories, there is nothing in the test1 directory.

If we directly create consecutive multi-level directories , we will not be able to create them .

 This is because there is no good directory in front of gmae, and there is no test1 directory in front of the good directory, which means there is no parent directory , so we cannot create continuous multi-level directories.

When we used the -p option , we found:

At this time, it is well created. 


The above is the basic usage of these four commands. If you think the writing is good, remember to give it a like. Thank you everyone!

Guess you like

Origin blog.csdn.net/cool_tao6/article/details/130827841