Linux users should be familiar with the unique tips of the seven 'LS' commands.
In the previous two articles in our series, we have covered the vast majority of the content about the 'LS' command. The last part of the 'ls command 'series in this article. If you have not read the other two articles in this series, you can visit the following link.
- 15 basic 'LS' command examples in Linux
- Ls command: Ten interview-level questions-Episode 2
- Ls command: 15 interview-level questions for Linux-Episode 1
7 Unique ls commands
1. List contents in the directory with timestamps in various time formats
To list directory content in time format, you need to select either of the following two methods.
# Ls-l-time-style = [STYLE] (method)
Note-the above Switch--time
Must be in the same format-l
The switch is used at the same time, otherwise it cannot reach the goal.
# Ls-full-time (method B)
Can be replaced with any of the following options[STYLE]
.
full-iso
long-iso
iso
locale
+%H:%M:%S:%D
Note: In the preceding row, the sequence of H (hour), M (minute), S (second), and D (day) can be adjusted as needed. In addition, you only need to select the relevant options, not all options. For example,ls -l --time-style=+%H
Only the hours are displayed.ls -l --time-style=+%H:%M:%D
The hour, minute, and day are displayed.
# ls -l --time-style=full-iso
Complete ISO time format for ls commands
# ls -l --time-style=long-iso
List of long time formats
# 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
Date and Time Format list
# ls --full-time
Complete format time list
2. List contents in multiple formats, such as separated by commas (,), horizontal format, long format, vertical format, and cross format.
You can use the following ls commands to list directory content in various formats:
# Ls -- format = upload SS # crossover
# Ls -- format = comma # comma
# Ls -- format = horizontal # horizontal
# Ls -- format = long # long format
# Ls -- format = single-column # bytes
# Ls -- format = verbose # details
# Ls -- format = vertical # vertical
Ls command List format
3. Use the ls command to add an indicator like (/= @ |) to the output result of the directory content.
With-p
Option. It adds one of the above indicators based on the file type.
# ls -p
Add indicator to content
4. Sort the directory content by extension, size, time, and version.
We can use--extension
To sort the output results by extension,--size
Extended options are sorted by size,-t
Extended options are sorted by time,-v
Extended options are used to sort versions.
We can also use--none
Option, which outputs results in the regular way without sorting.
# ls --sort=extension
# ls --sort=size
# ls --sort=time
# ls --sort=version
# ls --sort=none
Sort content by option
5. Run the ls command to print the UID and GID of each item in the directory.
The preceding environment can be implemented by using the ls command with the-n identifier.
# ls -n
Print the content list using UID and GID
6. Print more columns in the directory content in the standard output result than the default one.
Okay, the ls command automatically outputs the directory content based on the screen size.
However, we can manually assign the screen width value and the number of control columns that appear. You can use'--width
'Switch implementation.
# ls --width 80
# ls --width 100
# ls --width 150
List content based on window size
Note: You can test what value you can pass to the width mark.
7. Use the ls command to manually specify the tab size for the listed directory content rather than the default 8.
# ls --tabsize=[value]
List content by table size
Note: Specify[Value]
.
So far, all of them have been finished. Keep connections. We will publish the next article. Don't forget to provide us with valuable feedback in the following comments. Give us a thumbs up and share them with us to help us promote them.
Via: http://www.tecmint.com/linux-ls-command-tricks/
Author: Avishek Kumar Translator: GOLinux Proofreader: wxy
This article was originally translated by LCTT and launched with the Linux honor in China
Source: https://linux.cn/article-5531-1.html
This article permanently updates the link address: