I will share the convenient options for the ls command to sort the list of files. The ls command is for listing files and directories, but by default it sorts the list by name. Typically, the ls command displays directories mixed with files. Some implementations of the ls command support a useful option for sorting and display format. In this article, we will figure out how to properly structure files in the terminal workspace.

Let’s start by executing some basic ls commands.

ls Command

Running the ls command without adding any argument will display the contents of the current directory. In order to sort the list of files the following options are used

$ ls

ls -l Command

You can also display detailed information about each file, for example, file permissions, number of links, owner name, file size, last modification time, etc. This can be achieved with the -l option, which means a long list format, as in the following screenshot:

$ ls -l

ls -lt Command

Finally, to list files in a directory and sort them by the last change in date and time, use the -t option, as in the command below:

$ ls -lt

Read more: How Download File with CURL?

ls -ltr Command

If you need to sort files from “newer” to “older” based on date and time, you can use the -r option to display as follows:

$ ls -ltr

Conclusion

That’s all, but the ls command has a lot more options, so try viewing them on the man page. This is important since every Linux or Mac user needs to know how to use the sort command.

man ls

It’s the best time to ask questions and give us your feedback in comments.

Author

Hi there! My Name is Vincent Lago! My goal is to share insightful reviews, guides, and manuals for people looking to know more about current solutions for Apple hardware and OS. I have years of technological background knowledge including owning a custom iMacs & PCs which was using for different types of business. And now, I want to share my experience with you.

Write A Comment