Ubuntu – How do i find the recently used files through terminal

command line

I want to see the recently used(accessed) files along with their path through terminal.

How could i get that files list?

Note: This question is not a duplicate of Show recent modified/created files using Terminal

Best Answer

It works on Ubuntu systems which has nautilus as a default file-manager.

Run the below command on terminal to see the recently accessed(aka viewed) files.

sed -nr 's/.*href="([^"]*)".*/\1/p' ~/.local/share/recently-used.xbel

Information about all the recently accessed files are stored in this particular ~/.local/share/recently-used.xbel file. Extracting only the file along with it's path was done by the above command.

Command Explanation:

sed -nr 's/.*href="([^"]*)".*/\1/p' ~/.local/share/recently-used.xbel

-n --> suppress automatic printing of pattern space

-r --> Extended regex. If we use sed with -r, then we don't have to escape some characters like ((,),{,},etc)

's/.*href="([^"]*)".*/\1/p' --> sed searches for a line which has this(.*href="([^"]*)".*) regex in the input file. If it find any, then it grabs only the characters that are within double quotes which was after href=(href="") and stored it in a group. Only the stored group are printed through back-reference(\1).

Example:

$ sed -nr 's/.*href="([^"]*)".*/\1/p' ~/.local/share/recently-used.xbel
file:///media/truecrypt8/bar.txt
file:///media/truecrypt8/picture.txt
file:///media/truecrypt8/bob.txt
file:///media/truecrypt8/movie.txt
file:///media/truecrypt8/music.txt
file:///media/truecrypt8/foo.txt

If you want the output to be formatted then run this,

$ sed -nr 's/.*href="([^"]*)".*/\1/p' ~/.local/share/recently-used.xbel | sed 's|\/\/| |g'
file: /media/truecrypt8/bar.txt
file: /media/truecrypt8/picture.txt
file: /media/truecrypt8/bob.txt
file: /media/truecrypt8/movie.txt
file: /media/truecrypt8/music.txt
file: /media/truecrypt8/foo.txt