Quickly find recently modified files!

In this article, we will explain two simple command -line tricks that can help you list only all of today's files. One of the common problems Linux  users encounter on the command line is locating files with specific names, which can be much easier if you know the exact filename.

However, suppose you forgot the name of a file you created earlier in the day (in your home folder that contains hundreds of files), but now you need it urgently. Below is a different way to list only all the files you created or modified today (directly or indirectly).

1. Use the ls command to list only today's files in your home folder

# ls -al --time-style=+%D | grep 'date +%D'

where:
-a- list all files, including hidden files
-l- enable long listing format
> --time-style=FORMAT- show time for specified FORMAT
+ %D- start with >%m/%d/%y (month /day/year) format to display or use the date

Find Recent Files in Linux

Additionally, you can use the -X flag to sort the results alphabetically:

# ls -alX --time-style=+%D | grep 'date +%D'

You can also use the -S flag to sort based on size (biggest to smallest):

# ls -alS --time-style=+%D | grep 'date +%D'

2. In addition, using the find command will be more flexible and provide more options than ls, which can achieve the same purpose

  1.  The -maxdepth level is used to specify the search level (number of subdirectory levels) below the starting point of the search operation (in this case, the current directory).
  2.  newerXY is used for files whose timestamp X is newer than the reference file's timestamp Y. X and Y represent any of the following letters:
    -a-access time of the referenced file
    -B-creation time of the referenced file
    -c-inode state change time of the referenced file
    -m-modification time of the referenced file
    -t-directly specify an absolute time

The following command means to find only the files modified on 2016-12-06:

# find . -maxdepth 1 -newermt "2016-12-06"

Find Today's Files in Linux

Important: Use the correct date format as the reference time in the above  find command , once you use the wrong format, you will get the following error:

 
# 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 format below:

# find . -maxdepth 1 -newermt "12/06/2016" 
or 
# find . -maxdepth 1 -newermt "12/06/16"

In this article, we explained how to use the ls and find commands to help list only today's files. Please use the feedback field below to send us any questions or comments on this topic. You can also remind us of other commands that can be used for this purpose.

Guess you like

Origin blog.csdn.net/yaxuan88521/article/details/130214665