How can I retrieve the list of recent files in bash?

I'd like to get this set of files so I can use it with rofi.

I could manually parse the data file that looks something like:

;;; Automatically generated by ‘recentf’ on Sat Apr 20 13:21:26 2019.

(setq recentf-list

But if there is a more idiomatic way that would be ideal.

2 Answers 2


You can also do this with emacsclient. Here I'm using space to separate file names:


emacsclient -e "(mapconcat #'identity recentf-list \" \")"
thescript | sed 's/\s/\n/g'
 emacs --script t.elisp | sed -r '/^\s*$/d' | sed -n -e '/^"/p' | sed -e 's/"//g'

Not pretty but it works... Had to use sed to remove blank lines, 'tramp entries' (which aren't string(?)) and the quotes..


#!/usr/local/bin/emacs --script
(defun print-if-string (x)
       (cond ((stringp x) (print x))
             (t (error "Invalid argument %s in add-on" x))))
(defun print-elements-of-list (list)
 "Print each element of LIST on a line of its own."
 (while list
   (print-if-string (car list))
   (setq list (cdr list))))
(load "~/.emacs.d/.cache/recentf")
(print-elements-of-list recentf-list)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.