7 Linux ls command tips you should know

Source: Internet
Author: User
Tags local time

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.

    • 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]               (method A)

Note – The format of the above switch –time must be used in conjunction with the-l switch, otherwise it will not reach the destination.

# Ls-full-time                           (method B)

You can replace [STYLE] with any of the following options.

full-isolong-isoisolocale+%h:%m:%s:%d

note – in the line above, H (time), M (min), S (s), D (day) order can be adjusted arbitrarily. In addition, you only have to select those related options, not all options. For example, LS-L–TIME-STYLE=+%H will only display hours. The ls-l–time-style=+%h:%m:%d will display hours, minutes, and days.

# 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        # cross # ls--format=comma         # comma # ls--format=horizontal    # horizontal # ls--format=long          # long format # ls --format=single-column # single Bar # ls--format=verbose       # detail # ls--format=vertical      # 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 LS command with the-P option 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 sort the output by extension using the –extension option, the –size extension option is sorted by size, the-t extension option is sorted by time, and the-V extension option sorts the version.

We can also use the –none option, which outputs 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 : Specify the value of [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.

7 Linux ls command tips you should know

Related Article

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.