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?
3 Answers
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)
-
-
-
-
i think it is displayed with debug flag on stat: unix.stackexchange.com/questions/50177/birth-is-empty-on-ext4 Sep 5, 2015 at 9:58
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.
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.inotifywait
for one).