We sure do have a lot of file management articles and this is another one that will help you find files created on a specific date. This is a relatively easy task and you won’t even have to install anything new. If you want to find files created on a specific date, you might as well use this method!
Here’s a similar article.
Find Files Modified On A Specific Day
So, what is file management? To me, it’s manipulating files on your file system. It’s gathering information about the files on your file system. That’s what I mean when I say ‘file management’. I’ve covered a lot of articles with this as a subject.
Seriously… I tag articles with various terms. There are pages and pages of articles that have been tagged with file management.
Articles Tagged With File Management
Yup, that’s a lot of articles. Managing your files is something you do on a daily basis. You’re creating, editing, and moving your files around your file system. That’s file management and that’s okay!
Because this is something you do on a daily basis, even if you don’t pay attention to it, it’s something covered often. Even if you’re just browsing the internet, you’re adding files such as cached files. If you’re emailing with an email client, you have added and deleted files – if not more. File management is a pretty big thing.
Today, we’ll be using two basic commands – ls and grep. Let’s learn more!
The ls Command:
The ls command is an application that lets you list files. There are flags you can use, but it’s a basic application that, at its core, just lists files. You don’t need to install anything. You can verify that ls is available with this command:
1 | which ls |
The output should look like this:
1 2 | $ which ls /usr/bin/ls |
Check the ls man page with this command:
1 | man ls |
If you do that, you’ll see that we’re on the right path if we want to find files created on a specific date. The ls command is briefly described as this:
ls – list directory contents
We’ll be using the ls command to output a list of files and we’ll then use the pipe operator to process that output with grep.
The grep Command:
The grep command is one of those commands that’s used in conjunction with another command. By itself, it’s not that useful. It is when you use grep with other commands that you realize how powerful it is.
The grep command is usually used with the | “pipe” operator. The pipe operator takes the output from one command and processes it with another application. I’ve not yet covered this in an article, nor have I done an article about the grep command. I should do both.
Again, you won’t need to install anything. You can verify this with this command:
1 | which grep |
The output should match this:
1 2 | $ which grep /usr/bin/grep |
Next, you can check the man page with this command:
1 | man grep |
grep, egrep, fgrep, rgrep – print lines that match patterns
You can see that there are options. We’ll be using just plain grep. And, as you can deduce, this is yet another process that will help us find files created on a specific date. We’ll take the output from one command and use it with the grep command. This should appear obvious shortly if you have not yet realized how we’ll be proceeding in this article.
Find Files Created On A Specific Date:
Both ls and grep are tools used in the terminal. As such, you can be sure that you’ll need an open terminal. Either open a terminal from your application menu or open a terminal by pressing
With your terminal open, we can begin to find files created on a specific date. Further, let’s stay right there in the ~/home/user directory. We’ll keep it simple.
Let’s start with this command:
1 | ls |
That will list all your files. Now, let’s add hidden files – with the -a (all) flag with the following command:
1 | ls -a |
Next up, let’s get more information from the ls command with the -l (long listing format) flag. That looks like this:
1 | ls -la |
You should now see that there’s a time listed. We’re going through this just so that the example commands work. This isn’t strictly necessary, it’s just how it is being explained in this article.
If you want, you can sort that output by time. The following example command will show you the time the files were created, starting with the most recent example.
1 | ls -lat |
Again, that’s not strictly necessary.
Pay attention to the date section, because that’s what we’ll be using.
More specifically, we’ll be piping the output from the ls command to the grep command. That’s done like this:
1 | ls -la | grep '<date>' |
NOTE: You’ll be grepping a pattern. So, if you look carefully, the dates from 1 to 9 have two spaces! You’ll need to grep accordingly!
So, if you wanted to list articles created on the day this will be published, the command would look like this:
1 | ls -la | grep 'Mar 9' |
Notice that there are two spaces.
If you wanted to find files created on the 10th of February, your command would be different. You don’t add a 2nd space, as there is no second space in the pattern you’re looking for:
1 | ls -la | grep 'Feb 10' |
That will show you all the files (including the hidden files) that were created on the 10th of February. It does not care about the year and doesn’t show the year field. You’re simply finding files created on a specific date (ignoring the year, of course).
This is still useful.
This is also only true for files created within the past year. The ls command will happily show the date on files older than a year.
Here’s an example where the files are older than a year:
1 2 3 4 5 6 7 8 | -rw-rw-r-- 1 kgiii kgiii 9371790 Aug 19 2022 'Radiohead - Creep (The Usual Suspects).mp3' -rw-rw-r-- 1 kgiii kgiii 9721992 Jun 16 2023 'Ripped To Pieces (TB).mp3' -rw-rw-r-- 1 kgiii kgiii 13264896 Aug 19 2022 'Shut Up And Rock.mp3' -rw-r--r-- 1 kgiii kgiii 7393697 Dec 24 2021 'Silent Night - TB & N (Fixed Volume).mp3' -rw-rw-r-- 1 kgiii kgiii 12862316 Aug 19 2022 'SRV - Tightrope (The Usual Suspects).mp3' -rw-rw-r-- 1 kgiii kgiii 7974013 Nov 4 2022 'Still Pictures In Motion (The Usual Suspects).mp3' -rw-rw-r-- 1 kgiii kgiii 1658982 Aug 1 2022 'Studio Monitors.jpg' -rw-rw-r-- 1 kgiii kgiii 11257856 Oct 15 2021 'The Duality of Man (The Usual Suspects).mp3' |
So, to find files including the year, your command now has more spaces to contend with. For this command, you would now add two spaces between the day and the year. Like so:
1 | ls -la | grep 'Oct 15 2021' |
See the two spaces? That’s essential.
Again, don’t forget that you need two spaces when you’re working with days that are a single digit. If I wanted to find files from the 4th of November in 2022, that command would be this:
1 | ls -la | grep 'Nov 4 2022' |
REMEMBER: The grep command is used to find patterns and will only find the specified patterns. It’s very specific! It is also very powerful when used properly.
You can do even more with this. If you want to find files older than a year and by the specific year of their creation, you could simply run a command that looks like this:
1 | ls -la | grep '2020' |
Of course, you can substitute ‘2020’ with any year you’d like and get results – so long as you have files that were created in that year.
Also, of course, that command is ONLY useful if you do not have year numbers or numbers similar to years in file names. After all, 2022 is 2022 and grep is going to find them all. That’s what grep does – it finds patterns. As such, it’s up to you to pick the patterns you’ve used and this does have a limited functionality if you’ve gone ahead and added dates to your file names.
If you do have numbers in your file names and you don’t have spaces, you can still grep for a pattern. For example, this might work assuming no space in your file name is in front of the year field – which there generally shouldn’t be:
1 | ls -la | grep ' 2020' |
I can’t be too specific because I don’t know if you’ve put numbers/years in your file names. If you have, grep will equally find those. This whole article assumes that you’ve done nothing of the sort.
This can be even handier and here’s a little bit of some bonus information.
Let’s say you have a directory where you’ve stored files for years. Further, you want to know how many files you created in the year 2022. This directory contains files containing many years and you don’t want to just count them.
Well, you can do something about that!
1 | ls -la | grep '2022' | wc -l |
That command lists the files. The grep command then finds files created in 2022. You then pipe that output to the ‘wc’ command to count the lines.
Here’s an example output:
1 2 | $ ls -la | grep '2023' | wc -l 8 |
That means I added 8 files to that directory in the year 2023.
It’s pretty complicated. If you have years and spaces in your file names, this isn’t going to work that well for you. If you use patterns that match the output from the ls command, grep will find them. That’s what grep does.
While this does have a bit of a limited use case, it’s more of an exploration of what you can do with two simple commands. Unless you use matching patterns in your file names, this should work just famously for you. Otherwise, not so much – but you can have both fun trying AND you can look for other patterns that you can pass to grep.
Closure:
Well, that was kind of fun. We used the ls and grep commands to find files created on a specific date. There are always so many fun things to do with Linux. Many of these fun things can be done in the terminal. I like to think we both learn and have fun here on this site.
This can also be a handy tool. Let’s say you made some changes and then had some trouble later. You know you added files, but you can’t remember which files those were. Before restoring from a backup, you decide you want to troubleshoot. To do so, you start by finding files you created on the same day that you last changed your system.
Of course, this can be useful in a business setting. If you need to account for a problem, you can find the files created that day. Should there be something amiss, you can find files created on a specific date. If, for example, files were created on a date when no files should have been created… Well, you get the idea.
Perhaps more importantly, this shows what you can do with just two basic Linux commands. You’ll find ls and grep on every single desktop Linux (or server Linux) you touch. There’s no need for you to install something. You don’t have to worry about which package manager you use or building software from scratch because the developers didn’t release a package for your distro. You just use the commands that are already available.
Anyhow, this article is already too long. Sorry about that…
I kid. If I was sorry, I wouldn’t have done it in the first place! Ha! Take that!
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.
Last Updated on March 9, 2024 by KGIII
Now that was a long article!