I've opened a file in Emacs. I'd like to view information about that file such as creation date, size, etc. within Emacs. Is there a key shortcut or any Emacs command for that? Thanks.
Here is a command that uses
dired with verbose file flags for the
ls command. You may want to customize those flags depending on your operating system.
(defun file-info () (interactive) (let ((dired-listing-switches "-alh")) (dired-other-window buffer-file-name)))
Create a keybinding to your liking.
(global-set-key (kbd "C-c d") 'file-info)
There doesn't seem to be a command to get this info interactively, although you can use dired as @jrm suggests.
You can get this information with the following elisp code:
This will return a list like this:
(nil 1 "lh" "users" (20614 64019 50040 152000) (20000 23 0 0) (20614 64555 902289 872000) 122295 "-rw-rw-rw-" t (5888 2 . 43978) (15479 . 46724))
The first line gives you the UID "lh" and GID "users".
The next three lines are the last access, modification and status change times, formatted as lists. You can convert those to human-readable strings with
(current-time-string '(20614 64019 50040 152000))
In this case, the return value is "Tue Oct 23 16:12:03 2012". With that, you can build your own function to extract whichever bits your interested in. If you just want to see the meta data in the minibuffer, this will display it for you:
(defun file-metadata () (interactive) (let* ((fname (buffer-file-name)) (data (file-attributes fname)) (access (current-time-string (nth 4 data))) (mod (current-time-string (nth 5 data))) (change (current-time-string (nth 6 data))) (size (nth 7 data)) (mode (nth 8 data))) (message "%s: Accessed: %s Modified: %s Changed: %s Size: %s bytes Mode: %s" fname access mod change size mode)))
Calling this interactively produces:
/home/tws/org/hk.org: Accessed: Mon May 30 09:38:29 2016 Modified: Thu Apr 21 11:59:06 2016 Changed: Wed May 18 16:09:31 2016 Size: 7508 bytes Mode: -rwxr-xr-x
More details in the manual (elisp) File Attributes.