ls can also sort by a variety of criteria, it can print list information in a lot of different formats, it can list the current directory or it can list recursively.įor now, let’s start with ls. Of course, that gives you a lot more information than just size. To list files by size, you can just use ls -l. Here are two other ways that make use of the Unix philosophy of just using simple commands to do complex things, or in this case, a relatively trivial thing. Of course, Linux/Unix/OSX comes with a rich tool kit for doing lots of things pretty quickly and easily like listing files by size and reformatting the output to be whatever you like. Enjoy.There are a few tips in here that explain how to do this, but for my money, awk is overkill for this and ls is slightly inadequate in and of itself. I hope I made things clear to you and now you know what does ls -lrt command does and why is it used. You achieve this with ls -lrt as the addition of option r will reverse the sorting (by time): ls -lrt What you can do here is reverse the sorting and display the newest (created or modified) files at the bottom. ![]() Why? Because you'll have to scroll up to see the newest files. But if you have 20 or 50 or 100 files in the current directory and you want to see which files were accessed or modified recently, this will be a pain. Now, this is good enough if you have a few files. For older files, it shows the year (notice 2021?). Linux shows the time for the files created in the current year. The newest files are displayed at the top. I am going to sort ls command output by size in long listing with ls -lt: ls -ltĭo you notice the change? Now the entries are sorted by time. rwxr-xr-x 1 abhishek abhishek 57430439 Mar 17 07:52 pcloudĭrwxr-xr-x 2 abhishek abhishek 4096 PenguinSubtitlePlayer-Linux rwxr-xr-x 1 abhishek abhishek 89697412 balenaEtcher-1.5.116-圆4.AppImageĭrwxr-xr-x 6 abhishek abhishek 4096 cpufetch Now, if I use ls -l, it will display one entry per line, still sorted in alphabetical order. Obsidian-0.13.19.AppImage ScreenCloud-v1.5.3-x86_64.AppImageīy default, it just gives the name of the files and directories in alphabetical order. Let me show you the contents of my sample directory: ls Let's go a little further and understand it with practical examples. You'll get the same result for ls -lrt and ls -ltr. The order of the options doesn't matter here. ![]() The newest files are shown at the bottom. So when you combine them all, you display the contents in the present directory sorted in reverse chronological order. r: This one reverses the order of ls command output.t: This one sorts the long listing output based on time.It shows one file in each line with additional info such as permissions, ownership, size, timestamps etc. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |