Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I often need to do something like command most_recently_created_file_or_folder from the terminal. I'd appreciate any help.

share|improve this question
I don't know of any such command, but you could possibly query gnome-recently-used (sorry I don't have a link to docs on that) to find files most recently created by apps in GNOME. – RolandiXor Oct 31 '10 at 22:40
Can you give us more context for what you're trying to do? There might be a better solution. – Matthew Pirocchi Nov 1 '10 at 2:09
I'm trying to open the most recently created file with nzbget – James Nov 2 '10 at 0:12
up vote 6 down vote accepted

If you're running Zeitgeist you could use the following script:

#! /usr/bin/env python

from zeitgeist.client import ZeitgeistDBusInterface
from zeitgeist.datamodel import Event, Interpretation, TimeRange, \
 StorageState, ResultType

zg = ZeitgeistDBusInterface()
events = zg.FindEvents(
 StorageState.Any, 1, ResultType.MostRecentEvents)

last_event = Event(events[0])
last_subject = last_event.get_subjects()[0]

print last_subject.uri
share|improve this answer
could you provide sources to learn how to use the API this way? – Benjamin May 12 '12 at 7:14
Hi Benjamin. You can find the documentation for Zeitgeist's Python API at If there is interest I may write some easier to understand tutorial blog posts. – Siegfried Gevatter May 25 '12 at 16:43
As a follow up, I did write a tutorial here: – Siegfried Gevatter Mar 13 '13 at 23:12

You can use the find command, or fileschanged if you need to do it dynamically. The answers to a similar recent question may also help.

share|improve this answer

The command history will print a list of the last (500 or so depending on the settings) commands that were executed in the shell.

you can do history |grep mkdir to search for any new directories made. However it will only work if the directory was made explicitly (i.e. by the user) and in the shell.

share|improve this answer
command "`ls -c1 | head -n1`"

will run command on the most recently created file in the current working directory. Different quoting or escaping may be required for your shell.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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