Explanation of LS, CD, PWD, MKDIR commands in Linux


Ls command is one of the most commonly used commands in Linux, and it is also a very old command. Before learning linux commands, I would like to give you a suggestion:

Many students may just start to learn Linux, and then buy some textbooks to learn. The textbooks may collect thousands or even thousands of Linux commands and configuration options, and then type all the commands in the books one by one, which is meaningless. In fact, we only need to learn to remember dozens of commonly used commands and options.

1. File naming rules

  • Case sensitive
  • The / symbol cannot be used. All other symbols are legal. because/It means “root” in Linux
  • Special symbols should not be used as much as possible, such as:@#¥ & () -, spaceAnd so on. Because in the Linux command operation, some commands for file operation need to take command parameters. There may be spaces or other symbols between parameters and commands. In this way, the command conflicts with the file name, and the system does not know how to deal with it.
  • Avoid using.The symbol is used as the beginning of a normal file name because it is used in Linux.The beginning is hidden

2. Linux command format

Command formats: command options parameters

For example:

ls -la /mnt

lsIt’s the order itself

-laYes options: when there are multiple options, you can write them together. therelIt’s the first option,aIt’s the second option. In fact, the complete writing is as follows:-l -aBut with-laIn this way, it is convenient to write them together

/mntIs a parameter, which is the object that the command operates on. Here we operate under the root directorymntcatalog

Special catalog Description:.and.., the first.Represents the current directory;..Represents the parent directory of the current directory

3、lsCommand interpretation

  • Command name:ls
  • Full English name of the order:list
  • Command path:/bin/ls
  • Execution permission: all users
  • Command function: display directory file / directory
  • Syntax explanation: LS common options [- lad] [file or directory]
    • -lDetails display
    • -aShow all files (including hidden files)
    • -dView directory properties

4、lsCommand usage details

4-1. The simplest way to view directory fileslsFor example, we need to check which files are in the root directory

ls /root/


4-2. View all the files under the root directory and execute:

ls -a /root/


As you can see, it’s better than executionls /root/Of the results, there are many more.The beginning of the hidden file.

4-3. View the file details under the root directory and execute the following steps:

ls -l /root/


ls -lAfter the command is executed, the result contains seven parts. Let’s take a detailed look at the meaning of each part

  • drwxr-xr-xRepresents the file type and permissions

The first letterdIndicates the file type:dIndicates the directory;-Represents a binary file;lRepresents a soft link file

rwxr-xr-xRepresents permissions: R – read, W – write, X – execute. takerwxr-xr-xEvery three characters are divided into a grouprwxIndicates that the owner (U) has all permissions on this file, which is readable, writable and executable;r-xIndicates the permission of the group (g) to this file, which is only readable and executable;r-xRepresents the permissions of other people (o) on this file. It is only readable and executable.

  • 2Represents the number of hard links

  • rootandrootIndicates the owner and group of the file

  • 6Represents the file size. But the size of the statistics here is not complete, so you don’t have to care about this data

  • Jun 6 00:54Indicates when the file was created or last modified

  • The last column represents the name of the file or directory

4-4. View the details of etc directory under the root directory, and cooperate with-lUse, execute:

ls -ld /etc/


lsThe command parameters are not only l, a and D, but also p, t, R, s and H
-p: Add to directory only/

-t: Sort by modification time

--Time style = long ISO: LS - L -- time style = long ISO display friendly long format time

-r: Reverse sort

-S: Sort by file size

The LS command has many other parameters that are not commonly used. You can enter the commandman lsCheck the official instructions of the system. There are many official instructions. Press the space bar to turn the page and press the Q key to exit.

5、cdCommand interpretation

  • Command name:cd
  • Full English name of the order:change directory
  • Command path: shell built-in command
  • Execution permission: all users
  • Command function: switch to the specified directory
  • Grammar explanation:CD [table of contents]

give an example

For example, to switch to the system root directory, execute thecd /

To switch to the superior directory of the current directory, executecd ..

6、pwdCommand interpretation

  • Command name:pwd
  • Full English name of the order:print working directory
  • Command path:/bin/pwd
  • Execution permission: all users
  • Command function: display the current directory
  • Grammar explanation:pwd

7、mkdirCommand interpretation

  • Command name:mkdir
  • Full English name of the order:make directories
  • Command path:/bin/mkdir
  • Execution permission: all users
  • Command function: create a new directory
  • Grammar explanation:MKDIR [directory name]

give an example

For example, we are going tomntCreate a directory namedtestDirect executionmkdir /mnt/test

If it’s already theremntDirectory. You want to create a directory namedtest2Directory, executemkdir test2that will do


This chapter describes the most basic Linux file processing commands, which focuses on thelsCommand, because it is also the one we use most in the future. In the next chapter, we will continue to explain other common file processing commands in Linux.


Recommended Today

asp.net Application of regular expression

1. Balanced group / recursive matching (?’ Group ‘), which is called the corresponding content of group, and counts it on the stack;(?’- Group ‘), and count the corresponding content named group out of the stack(?!) Zero width negative look ahead assertion. Since there is no suffix expression, attempts to match always failRegular example:,{0,1}”5″:\[[^\[\]]*(((?’Open’\[)[^\[\]]*)+((?’-Open’\])[^\[\]]*)+)*(?(Open)(?!))\],{0,1} Test […]