Managing files and folders is a large part of the workload for Mac users; thus, Apple has included several features to save time. The ls command invokes a list of all the files and folders in a specific directory at the command line.

By default, the list is returned in alphabetical order, which is super convenient when searching for a particular file or folder. However, sometimes it may be more convenient for the list to be sorted by date and time. This tutorial will show you how to sort a few different ways with ls command by date in Mac OS/Mac OS X/Linux.

Sort By Date Using -t flag and ls

Sorting items in the directory can serve a number of purposes depending on the user’s objective. Use the -t flag to sort Is command for outputs listed by the date and time, or even more specifically, the last date and time the file or folder was modified. To use the -t flag to sort ls command by date on Mac OS/Mac OSX/Linux, follow these steps:

Open Finder

1. Open Finder, and then go to Applications > Utilities > Terminal:

Or, if you have the Terminal icon on your Dock, you can double click on the icon to open the Terminal window.

Terminal opens in the Home directory by default

2. Terminal opens in the Home directory by default. Navigate to the directory you want to sort in Terminal. (Tip: Go to System Preferences > Keyboard > Shortcuts > Services. In the Settings, click the box for New Terminal at Folder and click Done.)

3. Now right click a folder in Finder to open in it Terminal.

4. Type this command syntax

ls -lt

5. Press Return to view the contents of the directory sorted by date. The items that were modified the most recently will appear at the top of the list.

Sort By Date Using Is with -lt Tag And -h

Using the ls command can be varied to meet your needs when managing your files. You can also sort your directory listing by date using Is with -lt, -h (human readable), and -a (all files).

1. Open Terminal by going to Applications > Terminal. Or, click on the Terminal icon on your Dock.

2. Type this command syntax

ls -halt

3. The directory items will sort human readable and ‘all files’ in the directory list

Sort By Reverse Date Using -haltr

If you want to sort your directory by date in Terminal, but with the least recent files to least first, you can use a reverse sort command with ls:

1. Type this command syntax

ls -haltr

2. The directory items will sort by date, but with the least recent first. You can also try sorting with this command and accessing the files in the new order in Finder.

Contact Apple Support

If you were not able to sort with Is command by date in Mac OS/Mac OS X/Linux by using these steps, you can contact the Genius Bar or Apple Support for more help.