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?
Asked
Active
Viewed 3,697 times
-1

VRVigneshwara
- 197
3 Answers
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
-
I have modified the question , How to get the files which are there in this folder for more than 5 hours – VRVigneshwara Sep 05 '15 at 04: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 – VRVigneshwara Sep 06 '15 at 14:37
1
stat without options allows you to see all timestamps (birth,access,modify,change)

Jelmer de Reus
- 421
-
-
-
-
i think it is displayed with debug flag on stat: http://unix.stackexchange.com/questions/50177/birth-is-empty-on-ext4 – Jelmer de Reus Sep 05 '15 at 09:58
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
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:02inotifywait
for one). – Chris Davies Sep 04 '15 at 20:13