Once you start working on the Linux command line on day-to-day basis, more likely than not, you'll start loving it. It's just so powerful - there's hardly a work that you can't do through it. What else, some operations are better and quickly done via the command line, compared to GUI.

Once such work is searching for files based on date. While you can definitely do this through GUI, command line makes it a cake walk. Here's how you do it:

I am sure most of you would have used (or at-least heard of) the find command (no? first read about it here). It's a powerful and feature-rich tool that lets you search files and directories through the command line. If you take a look at its man page, you'll find an option -newerXY:

find-newer-option

Ideally, we could use -newerBt followed by a date in the find command to search for files based on the date they were born. We tested this on Ubuntu 16.04, and found that B isn't implemented. So we used -newerct instead.

Suppose the requirement is to find .PNG image files that were created between June 30 and July 4 2017. So here's the command that'll do this for you:

find -newerct "30 June 2017" ! -newerct "4 July 2017" -name "*.png"

Following screenshot shows the command in action:

find-newer-in-action

So that's how you can use the find command in Linux to search files based on date.

How to search files based on date through command line in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Ad #native_company# — #native_desc# #native_cta#