Check New Files In File System

  1. date command – Get the system date.
  2. touch command – Create a file and set file timestamps using date command.
  3. find command – Search for files in file system as per given condition.


Step #1: Get the current date

Type the following date command to get the date as per your requirements:

## get old date i.e. if today is 27/Jan get 20/Jan in $d ##
d=$(date +"%Y-%m-%d" --date="7 days ago")
echo "$d"

Sample outputs:


Step #2: Create a new file

Type the following touch command:

touch --date "$d" "$file"
echo "$file"
ls -l "$file"

Sample outputs:

-rw-r--r--. 1 nixcraft nixcraft 0 Jan 20 00:00 /tmp/test.txt.17697

Step #3: List newer files

To find files in the /var/www/upload/ directory tree that are newer than the $file (/tmp/test.txt.17697 file), use the find command as follows:

find /var/www/upload/ -newer $file


find /var/www/upload/ -type f -newer $file


find /var/www/upload/ -type f -iname "*.jpg" -newer $file


find /var/www/upload/ -iname "*.jpg" -newer $file -ls

OR bsd/unix safe options:

find /var/www/upload/ -name "*.jpg" -newer $file -exec ls -l {} \;

Sample outputs:

15728917   20 -r--r--r--   1 cyberciti cyberciti    18144 Jan 27 06:47 ./01/last-command-output-300x118.jpg
11534726   92 -r--r--r--   1 cyberciti cyberciti    91370 Jan 27 06:47 ./01/last-command-output.jpg
11534720   12 -r--r--r--   1 cyberciti cyberciti     9691 Jan 27 03:44 ./01/who-command.jpg
11534721  104 -r--r--r--   1 cyberciti cyberciti   104077 Jan 27 04:08 ./01/who-command-output.jpg

A shell script to check new files in the file system

# A quick shell script to show new files added to the file system
# Syntax ./script /path/to/dir days 
# Defaults ./script $PWD 3 
# Author: nixCraft <> under GPL v2.x+
# -----------------------------------------------------------------
_now=$(date +"%Y-%m-%d" --date="${2:-3} days ago")

# a bad idea but I'm too lazy

touch --date "$_now" "$_f"
find "$_d" -type f -newer "$_f"
/bin/rm -f "$_f"

Sample outputs:

./script 7 /var/www/uploads/