Unique tips for Linux user haulage's 7 ' ls ' commands

Source: Internet
Author: User
Tags local time locale

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.

    1. # 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.

    1. # ls -full-time (方法 B)

Can be replaced with any one of the following options [STYLE] .

    1. full-iso
    2. long-iso
    3. iso
    4. locale
    5. +%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:%Dhours, minutes, and days are displayed.

    1. # ls -l --time-style=full-iso

Full ISO time format for LS command

    1. # ls -l --time-style=long-iso

Long time Format list

    1. # ls -l --time-style=iso

Time Format list

    1. # ls -l --time-style=locale

local time Format list

    1. # ls -l --time-style=+%H:%M:%S:%D

List of date and time formats

    1. # 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:

    1. # ls --format=across # 交叉
    2. # ls --format=comma # 逗号
    3. # ls --format=horizontal # 水平
    4. # ls --format=long # 长格式
    5. # ls --format=single-column # 单栏
    6. # ls --format=verbose # 详情
    7. # 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.

    1. # 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.

    1. # ls --sort=extension
    2. # ls --sort=size
    3. # ls --sort=time
    4. # ls --sort=version
    5. # 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.

    1. # 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.

    1. # ls --width 80
    2. # ls --width 100
    3. # 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.
    1. # 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.