Linux users should be familiar with the unique tips of the seven 'LS' commands.

Source: Internet
Author: User

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.

  1. # Ls-l-time-style = [STYLE] (method)

Note-the above Switch--timeMust be in the same format-lThe switch is used at the same time, otherwise it cannot reach the goal.

  1. # Ls-full-time (method B)

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

  1. full-iso
  2. long-iso
  3. iso
  4. locale
  5. +%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=+%HOnly the hours are displayed.ls -l --time-style=+%H:%M:%DThe hour, minute, and day are displayed.

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

Complete ISO time format for ls commands

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

List of long time formats

  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

Date and Time Format list

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

  1. # Ls -- format = upload SS # crossover
  2. # Ls -- format = comma # comma
  3. # Ls -- format = horizontal # horizontal
  4. # Ls -- format = long # long format
  5. # Ls -- format = single-column # bytes
  6. # Ls -- format = verbose # details
  7. # 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-pOption. It adds one of the above indicators based on the file type.

  1. # ls -p

Add indicator to content

 

4. Sort the directory content by extension, size, time, and version.

We can use--extensionTo sort the output results by extension,--sizeExtended options are sorted by size,-tExtended options are sorted by time,-vExtended options are used to sort versions.

We can also use--noneOption, which outputs results in the regular 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 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.

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

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

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.