7 Quirky ‘ls’ Command Tricks Every Linux User Should Know

We have covered most of the things on ‘ls’ command in last two articles of our Interview series. This article is the last part of the 7 Quirky ls command series. If you have not gone through last two articles of this series you may visit the links below. 7 Quirky ‘ls’ Command Tricks Every Linux User Should Know:

7 Quirky ls command

1. List the contents of a directory with time using various time styles.

To list the contents of a directory with times using style, we need to choose any of the below two methods.

Note – The above switch (--time style must be run with switch -l, else it won’t serve the purpose).

Replace [STYLE] with any of the below option.

Note – In the above line H(Hour), M(Minute), S(Second), D(Date) can be used in any order.

Moreover you just choose those relevant and not all options. E.g., ls -l --time-style=+%H will show only hour.

ls -l --time-style=+%H:%M:%D will show Hour, Minute and date.

ls command

2. Output the contents of a directory in various formats such as separated by commas, horizontal, long, vertical, across, etc.

Contents of directory can be listed using ls command in various format as suggested below.

  1. across
  2. comma
  3. horizontal
  4. long
  5. single-column
  6. verbose
  7. vertical

3. Use ls command to append indicators like (/=@|) in output to the contents of the directory.

The option -p with ‘ls‘ command will server the purpose. It will append one of the above indicator, based upon the type of file.

4. Sort the contents of directory on the basis of extension, size, time and version.

We can use options like --extension to sort the output by extension, size by extension --size, time by using extension -t and version using extension -v.

Also we can use option --none which will output in general way without any sorting in actual.

5. Print numeric UID and GID for every contents of a directory using ls command.

The above scenario can be achieved using flag -n (Numeric-uid-gid) along with ls command.

6. Print the contents of a directory on standard output in more columns than specified by default.

Well ls command output the contents of a directory according to the size of the screen automatically.

We can however manually assign the value of screen width and control number of columns appearing. It can be done using switch ‘--width‘.

Note: You can experiment what value you should pass with width flag.

7. Include manual tab size at the contents of directory listed by ls command instead of default 8.

Note: Specify the [Value]= Numeric value.

That’s all for now. Stay tuned to Tecmint till we come up with next article. Do not forget to provide us with your valuable feedback in the comments below. Like and share us and help us get spread.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.