In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "examples of the use of linux ls commands". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
One of the basic commands in Linux is ls. Without this command, we would have difficulty browsing the directory entries. This command must be known to everyone who studies Linux.
What is ls?
The ls command lists files and directories. By default, he lists the contents of the current directory. With the parameters, we can do more with ls. Here are some examples of ls usage used in daily operations.
1. Run ls with no parameters
Running ls without parameters lists only files or directories. You don't see any other information output. Sometimes you find that the ls command with no parameters is different from the one described here, which may be the ls alias that your ls command actually takes parameters.
$ls
two。 Use long list mode
Using the-l character (lowercase L character) displays a long list of the contents of the current directory. In the next example, we will combine the-l parameter (which is often used) to get better results.
$ls-l
Here is how to read the output:
Column 1
The first letter d means that the content is a directory or file. In the screenshot above, Desktop, Documents, Downloads, and lynis-1.3.8 are directories. If it is a'-'(minus sign), it means that its content is a file. When it is l (lowercase l character), it means that the content is a linked file. The following nine characters are about file permissions. The first three rwx characters are the permissions of the owner of the file, the second set of 3rwx is the permissions of all groups of the file, and the last rwx is the permission for others to access the file.
The second column tells us how many links there are to this file.
The third column tells us who is the owner of this file / folder.
Column 4 tells us who is all the groups in this file / folder.
The fifth column tells us the size of the file / folder in bytes. The size of the directory is always 4096 bytes.
Column 6 tells us when the file was last modified.
Column 7 tells us the name of the file or directory.
3. Show file size
It may be inconvenient to look at the size in bytes. 6.5m is easier to read than 6727680 bytes. To do this, we can use the parameter that combines-h with-l. The-h parameter means it is easy for people to identify.
$ls-lh
Another parameter that can do this is-- si. This parameter is similar to the-h parameter, but-si is in units of 1000 and-h is in units of 1024.
$ls-si
4. Sort file size
After we can display the file size, we want to sort by file size. We can do this using the-S parameter. This list will be sorted from university to school.
$ls-lhS
5. Measure the size
Ls can be resized by using-block-size=SIZE. The SIZE here is:
K = KilobyteM = MegabyteG = GigabyteT = TerabyteP = PetabyteE = ExabyteZ = ZettabyteY = Yottabyte
For example, we want to use MB as the unit size. So the grammar would look like this:
$ls-l-block-size=M
6. Show hidden files
In Linux, with "." The file at the beginning of (period) is a hidden file. To display it in the ls command, we can use the-an option.
$ls-a
7. List only directory entries
If we want to list only the directories, we can use the-d option.
$ls-d * /
8. Do not print owner information
To do this, we use the-g option.
$ls-g
9. Do not print group information
-g hides the owner information, and-G hides the group information.
$ls-lG
10. Print UID and GID
If you want to numerically list the owner of the item and all the groups (that is, UID and GID), we can use the ls command with the-n option. Here's an example.
$ls-n
From the above example, we know that the UID of user pungki is 100, the GID is 1000, and the GID of root group is 0.
11. Print without color
Some Linux distributions have enabled color for the ls command. This causes ls to print the list in a variety of colors. If you don't want this, you can use the-- color=never parameter.
$ls-color=never
twelve。 Print the index number of each file
To print the index or commonly known as the inode number, we can use the-I option. The index number is displayed in the first column.
$ls-li
13. Add / (slash) mark directory
To do this, use the-p option.
$ls-p
14. Reverse the order when sorting
You may need to reverse the order when listing items. To do this, you can use the-r option.
$ls-r
15. Recursively list subdirectories
With the-R parameter, you can list the directories that contain its subdirectories.
$ls-R
16. Sort by extension
You can use the-X parameter or-- sort=extension to sort by extension.
$ls-lX
Or
17. List by modification time
Using the-t option will sort by modification time, with the new files first.
$ls-lt
18. List your home directory
To list your home directory, you can use "~" (tilde) to represent it. So you don't have to enter the full directory name. Let's assume that the home file is called / home/pungki, then the tilde makes sense for / home/pungki.
$ls ~
19. List parent directory
No matter which directory you are in, you can list the parent directory without entering the full path. This is an example.
$ls.. /
This time list the contents of the directory above layer 1.
$ls.. /..
This time list the contents of the directory above layer 2. To represent the second floor above).
20. Print ls command version
Print it with the-- version parameter.
$ls-version
Summary
These are the parameters that are used in daily operations. Of course, you can always type man ls or ls-- help to query the man pages of ls.
Via: http://linoxide.com/linux-command/linux-ls-command/
This is the end of the content of "examples of the use of the linux ls command". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.