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 4, 2015 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).
    – roaima
    Sep 4, 2015 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 Sep 5, 2015 at 3:42
  • Why not use find then
    – netmonk
    Sep 5, 2015 at 6:09

3 Answers 3


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.

  • I have modified the question , How to get the files which are there in this folder for more than 5 hours Sep 5, 2015 at 4:46
  • How can I compare with today's date with the value i get from stat -c %z filename and get the difference in a variable Sep 6, 2015 at 14:37

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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.