In this article, we will explain two, simple command line tips that enable you to only list all today’s files.
One of the common problems Linux users encounter on the command line is locating files with a particular name, it can be much easier when you actually know the filename.
However, assuming that you have forgotten the name of a file that you created (in your
home folder which contains hundreds of files) at an earlier time during the day and yet you need to use urgently.
Below are different ways of only listing all files that you created or modified (directly or indirectly) today.
1. Using the ls command, you can only list today’s files in your home folder as follows, where:
-a– list all files including hidden files
-l– enables long listing format
--time-style=FORMAT– shows time in the specified FORMAT
+%D– show/use date in %m/%d/%y format
# ls -al --time-style=+%D | grep 'date +%D'
Find Recent Files in Linux
In addition, you can sort the resultant list alphabetically by including the
# ls -alX --time-style=+%D | grep 'date +%D'
You can also list based on size (largest first) using the
# ls -alS --time-style=+%D | grep 'date +%D'
2. Again, it is possible to use the find command which is practically more flexible and offers plenty of options than ls, for the same purpose as below.
-maxdepthlevel is used to specify the level (in terms of sub-directories) below the starting point (current directory in this case) to which the search operation will be carried out.
-newerXY, this works if timestamp X of the file in question is newer than timestamp Y of the file reference. X and Y represent any of the letters below:
- a – access time of the file reference
- B – birth time of the file reference
- c – inode status change time of reference
- m – modification time of the file reference
- t – reference is interpreted directly as a time
This means that, only files modified on 2016-12-06 will be considered:
# find . -maxdepth 1 -newermt "2016-12-06"
Find Today’s Files in Linux
Important: Use the correct date format as reference in the find command above, once you use a wrong format, you will get an error as the one below:
# find . -maxdepth 1 -newermt "12-06-2016" find: I cannot figure out how to interpret '12-06-2016' as a date or time
Alternatively, use the correct formats below:
# find . -maxdepth 1 -newermt "12/06/2016" OR # find . -maxdepth 1 -newermt "12/06/16"
Find Todays Modified Files in Linux
You can get more usage information for
find commands in our following series of articles on same.
- Master Linux ‘ls’ Command with This 15 Examples
- Useful 7 Quirky ‘ls’ Tricks for Linux Users
- Master Linux ‘find’ Command with This 35 Examples
- Ways to Find Multiple Filenames with Extensions in Linux
In this article, we explained two important tips of how to list only today’s files with the help of ls and find commands. Make use of the feedback form below to send us any question(s) or comments about the topic. You can as well inform us of any commands used for the same goal.