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:
@#¥ & () -, space
And 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
ls
It’s the order itself
-la
Yes options: when there are multiple options, you can write them together. therel
It’s the first option,a
It’s the second option. In fact, the complete writing is as follows:-l -a
But with-la
In this way, it is convenient to write them together
/mnt
Is a parameter, which is the object that the command operates on. Here we operate under the root directorymnt
catalog
Special catalog Description:
.
and..
, the first.
Represents the current directory;..
Represents the parent directory of the current directory
3、ls
Command 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]
-
-l
Details display
-
-a
Show all files (including hidden files)
-
-d
View directory properties
4、ls
Command usage details
4-1. The simplest way to view directory filesls
For 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 -l
After the command is executed, the result contains seven parts. Let’s take a detailed look at the meaning of each part
drwxr-xr-x
Represents the file type and permissions
The first letter
d
Indicates the file type:d
Indicates the directory;-
Represents a binary file;l
Represents a soft link file
rwxr-xr-x
Represents permissions: R – read, W – write, X – execute. takerwxr-xr-x
Every three characters are divided into a grouprwx
Indicates that the owner (U) has all permissions on this file, which is readable, writable and executable;r-x
Indicates the permission of the group (g) to this file, which is only readable and executable;r-x
Represents the permissions of other people (o) on this file. It is only readable and executable.
-
2
Represents the number of hard links -
root
androot
Indicates the owner and group of the file -
6
Represents 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:54
Indicates 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-l
Use, execute:
ls -ld /etc/
ls
The 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 command
man ls
Check 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、cd
Command 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 the
cd /
To switch to the superior directory of the current directory, execute
cd ..
6、pwd
Command 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、mkdir
Command 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 to
mnt
Create a directory namedtest
Direct executionmkdir /mnt/test
If it’s already there
mnt
Directory. You want to create a directory namedtest2
Directory, executemkdir test2
that will do
This chapter describes the most basic Linux file processing commands, which focuses on thels
Command, 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.