Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any file in unix based system which I can read, to get the same value that time() in php would return?

share|improve this question
Will you be reading the file using php? – RedGrittyBrick Oct 19 '11 at 16:42
If you can execute commands, use date +%s. – Daniel Beck Oct 19 '11 at 16:45
I can only use a read_file function to do this so a command wouldn't work. – Panayiotis Oct 19 '11 at 17:06
Apparently PHP has a time() function. Why do you need to read it from a file? – Keith Thompson Oct 19 '11 at 17:43
What is the actual end problem that you're trying to solve? (this smells like an X-Y problem) – Piskvor Oct 19 '11 at 17:51
up vote 0 down vote accepted

Unlike my other answer reading metadata, grepping through /proc for "sec" I indeed found a file containing the current system time:

/proc/timer_list contains two values: the uptime in nsec (now at...) and a little further down the time the system was started, also in nsec (.offset). If you add them and divide through 10^9 you've got the current time.

Timer List Version: v0.6
now at 2089173850911347 nsecs

cpu: 0
 clock 0:
  .base:       0000000000000000
  .index:      0
  .resolution: 1 nsecs
  .get_time:   ktime_get_real
  .offset:     1316955129915578545 nsecs

EDIT: And another one: /sys/devices/pnp0/00:05/rtc/rtc0/since_epoch seems to contain the real unix timestamp, no offset or such. But I'm not sure about what this file is really about, just found it grepping.

If you've also got some terminal access for development you can try yourself:

grep 131904 `find /sys 2>/dev/null` 2>/dev/null

to find files containing the first digits of the unix timestamp (replace if using it later) in /sys you've got access to.

share|improve this answer
Thanks, what i wanted! – Panayiotis Oct 19 '11 at 18:11
But you still need to tell us what you want to do exactly. Sorry for being curios. ;) – Jens Erat Oct 19 '11 at 18:16
This will be really offtopic but I will, at Defcon shows how a PHPSESSID cookie can be bruteforced by knowing some of its varables which include the epoch time of php. I've been trying to think of a way of getting that, and I was looking for a file to read with load_file (mysql injection), that will give me this value. There you go :) – Panayiotis Oct 19 '11 at 18:25
  • On my system, /proc/cpuinfo's {a|c|m}time is equal to the current system time.
  • Maybe you can just execute date and read from its output?
share|improve this answer
I have tried doing cat /proc/cpuinfo but can't find the time anywhere, just cpu specifications, why? – Panayiotis Oct 19 '11 at 17:07
As i stated you need to read its meta data (eg. stat cpuinfo). The time is not in the file, but the file's metadata equals it. – Jens Erat Oct 19 '11 at 17:10
Oh ok, but unfortunately I can only use read_file(path) for this, and it won't do the trick – Panayiotis Oct 19 '11 at 17:13

PHP's time() function returns seconds since the Unix epoch. You can format it as a date and/or time any way you want using other PHP functions.

Unix's date command (at least the GNU version) can do the same

# date "+%s"

So you can easily create a file containing that number, as needed (e.g. using PHP's system() function)

Or just read it directly

$secs_since_epoch = system('date "+%s"', $return_value);

I can't think of a sensible use case for what you ask though.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .