In the previous two articles of our series, we have covered most of the content of the ' ls ' command. This article is the last part of the ' LS Command ' series. If you haven't read the other two articles in the series, you can visit the links below.
- Example of 15 basic ' ls ' commands in Linux
- Interview questions for 15 ' ls ' commands (i)
- 10 ' ls ' Command questions for interview (II)
Unique tips for 7 LS commands
1. List contents in a directory with timestamps in various time formats
To list directory contents in a time format, we need to select either of the following two methods.
# ls -l –time-style=[STYLE] (方法 A)
Note -The format of the above switch --time
must be used in conjunction with the -l
switch, otherwise it will not achieve the purpose.
# ls -full-time (方法 B)
Can be replaced with any one of the following options [STYLE]
.
full-iso
long-iso
iso
locale
+%H:%M:%S:%D
note -in the line above, H (time), M (min), S (s), D (day) can be arbitrarily adjusted in order. In addition, you only have to select those related options, not all options. For example, ls -l --time-style=+%H
only hours will be displayed. ls -l --time-style=+%H:%M:%D
hours, minutes, and days are displayed.
# ls -l --time-style=full-iso
Full ISO time format for LS command
# ls -l --time-style=long-iso
Long time Format list
# ls -l --time-style=iso
Time Format list
# ls -l --time-style=locale
local time Format list
# ls -l --time-style=+%H:%M:%S:%D
List of date and time formats
# ls --full-time
Full format Time list
2. List contents in multiple formats, such as comma-delimited, horizontal, long, vertical, cross-formatting, and so on.
The contents of the catalog can be listed in the various formats of the LS command as suggested below:
# ls --format=across # 交叉
# ls --format=comma # 逗号
# ls --format=horizontal # 水平
# ls --format=long # 长格式
# ls --format=single-column # 单栏
# ls --format=verbose # 详情
# ls --format=vertical # 垂直
The list format of the LS command
3. Use the LS command to add an indicator like (/[email protected]|) to the output of the catalog content.
The -p
LS command with options will do the same for this purpose. It adds one of these indicators based on the file type.
# ls -p
Add indicator to content
4. Sort the contents of the catalog according to the extension, size, time, and version.
We can use the --extension
options to sort the output by extension, the extended options are sorted by size, the extended options are sorted by --size
-t
time, and -v
the extended option sorts the versions.
We can also use --none
options, which will output the results in the usual way without sorting.
# ls --sort=extension
# ls --sort=size
# ls --sort=time
# ls --sort=version
# ls --sort=none
Sort content by Options list
5. Use the LS command to print the digital UID and GID for each item in the directory.
The above environment can be implemented by using the LS command with the-n designation.
# ls -n
Print a list of contents by UID and GID
6. The standard output results in more columns than the default specified in the Print catalog content.
Well, the LS command automatically prints the contents of the directory based on the screen size.
However, we can manually assign the screen width value and the control number of the column that appears. This can be achieved by using the ' --width
' switch.
# ls --width 80
# ls --width 100
# ls --width 150
List content based on window size
Note : You can experiment with what values you can pass to the width tag.
7. Manually specify the tab size for the listed directory contents by using the LS command instead of the default of 8.
# ls --tabsize=[value]
List content by table size
Note : [Value]
the specified numeric value.
So far, it's all done. Stay connected and we'll roll out the next article. Don't forget to provide us with valuable feedback in the comments below. For us to praise and share, to help us promote.
Unique tips for Linux user haulage's 7 ' ls ' commands