TranslateProject/sources/tech/20161206 How to Find Recent or Today’s Modified Files in Linux.md
2016-12-29 14:21:06 +08:00

5.4 KiB
Raw Blame History

How to Find Recent or Todays Modified Files in Linux

In this article, we will explain two, simple command line tips that enable you to only list all todays 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 todays files in your home folder as follows, where:

  1. -a – list all files including hidden files
  2. -l – enables long listing format
  3. --time-style=FORMAT – shows time in the specified FORMAT
  4. +%D – show/use date in %m/%d/%y format
# ls  -al --time-style=+%D | grep 'date +%D'

Find Recent Files in Linux

Find Recent Files in Linux

In addition, you can sort the resultant list alphabetically by including the -X flag:

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

You can also list based on size (largest first) using the -S flag:

# 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.

  1. -maxdepth level 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.
  2. -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:
    1. a access time of the file reference
    2. B birth time of the file reference
    3. c inode status change time of reference
    4. m modification time of the file reference
    5. 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

Find Todays 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

Find Todays Modified Files in Linux

You can get more usage information for ls and find commands in our following series of articles on same.

  1. Master Linux ls Command with This 15 Examples
  2. Useful 7 Quirky ls Tricks for Linux Users
  3. Master Linux find Command with This 35 Examples
  4. Ways to Find Multiple Filenames with Extensions in Linux

In this article, we explained two important tips of how to list only todays 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.


作者简介:Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.


via: http://www.tecmint.com/find-recent-modified-files-in-linux/

作者: Aaron Kili 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出