Skip to content

Instantly share code, notes, and snippets.

@sks147
Created June 27, 2016 06:45
Show Gist options
  • Save sks147/72d13153b79cff874376de32845b78f7 to your computer and use it in GitHub Desktop.
Save sks147/72d13153b79cff874376de32845b78f7 to your computer and use it in GitHub Desktop.
Getting metadata of a file using ruby
# pass file arguments in double quotes
# e.g last_modified("/etc/passwd")
def last_modified(file)
t1 = File.stat(file).ctime
t2 = Time.now
elapsed = (t2-t1)/(60*60*24)
puts "#{file} was modified #{elapsed} days ago."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment