Pages

Thursday, June 1, 2017

How to Find Recent or Today’s Modified Files in Linux

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:
  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
      ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
                                                    ► Read more: http://adf.ly/1n5Yay
      ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

No comments:

Post a Comment