0

I want to write one script where I need the below function :

  1. List all the files which are created in last 24 hours. If I give the find command with ctime option then it list all files which are change (permission & woner)

    find . -ctime -1

    But I need the list of new files which are created not modified or change in last 24 hours.

  2. List all the files which are removed in last 24 hours. If I removed any files then how I get those files name.

  3. How to get the birth time (Creation time) of a file. There is one format in stat command which give the birth time of a file

    %w Time of file birth, human-readable; - if unknown

    %W Time of file birth, seconds since Epoch; 0 if unknown

abc@123:# stat -c %w tzls.txt
-
abc@123:#

But it is not giving any output. My linux filesystem is ext3.

FloHimself
  • 11,492
joy87
  • 71
  • 2
  • 2
  • 3

1 Answers1

0

You can't directly do this on many Linux filesystems because the "created" attribute simply doesn't exist. You might want to read some of these links

If you really need to find files that have been created in the last 24 hours, as distinct from those that have been created or changed, you have two choices:

1 Switch to a filesystem that supports creation date, and use a combination of find and stat --format '%w' to get the list of such files

2 Run find / -type f every 24 hours, and compare the current run results with those of the previous run. Something like this could work, run once every 24 hours:

#!/bin/bash
#
test -f /tmp/today && mv -f /tmp/today /tmp/yesterday
find / -type f | sort > /tmp/today
test -f /tmp/yesterday && comm -13 /tmp/yesterday /tmp/today
Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • The OP didn't mention Linux (though he referred to GNU stat). FreeBSD/OS/X find have -Bmin, -Btime, -Bnewer to act on birth time. – Stéphane Chazelas Apr 02 '15 at 10:23
  • On Linux, the creation date (whatever that means) is stored on most modern native file systems, but (with the possible exception of some Suse based systems), there's no kernel API to retrieve it so those %w of GNU stat won't work. – Stéphane Chazelas Apr 02 '15 at 10:25
  • Oops, sorry, he did mention Linux indeed. And birth time was not available in ext3 IIRC. My bad. – Stéphane Chazelas Apr 02 '15 at 10:26
  • @Stéphane thank you. Wasn't aware that API simply didn't make it available. Am curious about that so will go investigate (for my own understanding). – Chris Davies Apr 02 '15 at 11:52