-1

I have a directory called /home/mydir/test A file will be sent from some other team which lands in this directory. How to find what is the time the file came to this particular directory? ( I need both time in time stamp format and normal hh:mm:ss format too ) I have to move the files to directory which is here for more than 5 hours. How to fetch those files?

  • 1
    Please [edit] your question and tell us i) why the timestamp from ls -l file is not enough; ii) if that is not enough, explain how the file is being copied and iii) the filesystem you are using. – terdon Sep 04 '15 at 12:02
  • This feels like an XY problem. Do you need to know the time it arrived so that you know it's a "new" file and needs to be processed? If so, please say so because there are better ways of identifying when a file has arrived in a directory (inotifywait for one). – Chris Davies Sep 04 '15 at 20:13
  • I need the time of file arrival in order to do check for the files which are in the directory for more than 4 hours – VRVigneshwara Sep 05 '15 at 03:42
  • Why not use find then – netmonk Sep 05 '15 at 06:09

3 Answers3

4

You can use stat -c %w filename, it will provide the date of birth in human readable way, and -C will provide in unix timestamp.

Time of birth is not supported on every filesystem; use stat -c %z, i.e. time of last change, in those cases.

Thomas Erker
  • 2,857
netmonk
  • 1,870
1

stat without options allows you to see all timestamps (birth,access,modify,change)

1

For the last part of your question: Use find to find all files older than 5 * 60 minutes (-cmin tests for change time in minutes, +300 means more than 300); {} is replaced with the filename:

find in_dir -cmin +300 -type f -exec mv {} out_dir \;

Update: added -type f to not move in_dir itself to out_dir.

Thomas Erker
  • 2,857