Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the ls command

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces you how to understand the ls command, the content is very detailed, interested friends can refer to, hope to be helpful to you.

01 daily command

Learning of ls command

Introduction to 02 command

Ls is an acronym for list, which is used to list files and is implemented in Unix and Unix-like systems. Equivalent to the dir command in Windows.

03 order detailed explanation

Grammar

Ls [options] [File]

The above is the syntax of the ls command, which is relatively simple. In fact, this is the syntax format for most Linux commands.

Command name [option] [parameter]

There is a question: how do I know the syntax of the ls command? Here I would like to introduce you to the "--help" option. This option is available for all Linux commands to print help for the command.

When we don't know what the command is for, or when we forget the command syntax / option, we can use this option to get help for the command.

The above is the help for the ls command. Introduced: the use of the ls command, that is, syntax; the purpose of the ls command-to list information about files (the default is the current directory); and options for the ls command.

Option

There are many options for ls commands, so let's pick some common options to introduce them.

Ls

When running without adding any options and parameters, the ls command defaults to listing all files and directories except hidden files in the current directory. (name only)

The current directory is the root directory "/", so the names of all files and directories except hidden files in that directory are listed.

It is important to note that Linux is strictly case sensitive. So if you capitalize the command, the system will not recognize it.

By default, only non-hidden files and directories are listed. Is there a way to list all files and directories, including hidden files and directories?

Of course, there is a way, just add the "- a" option after the ls command.

Ls-a

Note that there are spaces between commands and options, between options and parameters, and never write the three together.

As you can see, there are many dots in the listed files and directories. " The files and directories at the beginning. In Linux, with dots. The first files and directories are hidden by default, as well as in Windows.

Have you noticed that there are "." in the files and directories listed. And "..". In Linux, this represents the current directory and parent directory, respectively, so you may often see commands in the following format:

. / document

This command means to execute the file in the current directory. If you download a scripting tool and want to run it for vulnerability detection. You can first enter the directory where the script is located, and then type ". / script name" to run the script.

If you do not want to print these two directories, you can use the "- A" option, which has the same effect as the "- a" option, except that it is not listed. " And ".." That's all. Again, Linux is strictly case-sensitive.

Does it feel uncomfortable to have so many files and directories listed? To teach you a trick, use the "- l" option to list information about files and directories in a long format.

Ls-l

It looks more or less comfortable this way. But why do you have some other information? This is because the "- l" option prints out the properties of files and directories, such as file types, permissions, and so on. It is equivalent to the right-> attribute in Windows.

There are a lot of knowledge points in each field in the long format. I will talk about it in a later article. Here we will focus on the study of commands.

In the information listed in the "- l" option, column 5 represents the size of the file / directory, the default units are bytes, and you can use the "- h" option to convert units into people-friendly units (K, M, G).

Ls-hl

Commands can use multiple options at the same time, and multiple options can be written together. This command means to print non-hidden files and directories in the current directory in a long format and display the size as people-friendly units.

Here I would like to mention that the options of commands generally have simplified form and complete form, no matter which form of option is used, it can achieve the same effect.

Using the simplified mode "- h" of the "--help" option, I still successfully printed out the help information for the command. However, some commands do not necessarily have the "- h" option, or "- h" is not a simplification of "--help". Such as the ls command, the "- h" option does not print help.

So when viewing help information, individuals recommend using the full option "--help". As for the other options, of course, a simplified form is used to make it easier to use and remember.

Parameters.

The command can add parameters as well as options. The arguments to the ls command are the file name and directory name.

Ls 0

After adding the parameter, we can list the information of the file / directory specified by the parameter.

Here I list the 0 files in the current directory, or I can set the parameter to the specified directory. This lists the files in the specified directory.

If you just want to look at the directory itself and don't want to list the files in the directory, we can use the "- d" option.

Like options, you can add multiple parameters at the same time. Notice that there are spaces between the parameters.

Of course, commands can also be used with options and parameters.

These are the syntax, common options, and parameters of the ls command.

04 knowledge summary

The following is a summary of the knowledge of this article.

Syntax: ls [options] [File] purpose: lists information about files (only names are listed by default) if you take the directory name as a parameter, the files in that directory will be listed. Option:-a-list all files and directories (including hidden files and directories)-A-list except the current directory. And the superior directory ".." All files and directories outside (including hidden files and directories)-l-list the attributes of files and directories in long format-h-display the size of files and directories in human-friendly units-d-list only the directory itself Do not list the file parameters under the directory: file name / directory name other: "--help" option to get the help information of the command Linux strictly case-sensitive command can use multiple options at the same time, multiple options can be written together the command can also specify multiple files and directories as parameters, ls will list all the specified files and directories in the file name. On how to understand the ls command to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report