Play or open newest file from the linux command line

In some cases it is convenient to have a shortcut to open the newest file in a directory. Maybe the last show your dvr recorded, or the last file you bought from amazon.

For these cases I found this little bash snippet useful:

ls -tr | tail -n 1 | xargs -I FILE kde-open "FILE"

Instead of kde-open, which opens any file with the associated program, you can use any program, gnome-users might want gnome-open, people with other window managers can use xdg-open from xdg-utils. Or you can just insert mplayer, if you are only interested in music and videos.

I prefer it installed somewhere in the path, and then one can add a command-line parameter, the number of files to be played:

ls -tr | tail -n ${1:-1} | xargs -I FF kde-open "FF"

filetype playlast (63 B, 2011-10-23)

This entry was posted in Computers and tagged , . Bookmark the permalink.

2 Responses to Play or open newest file from the linux command line

  1. Fine way of describing, and nice paragraph to obtain information regarding
    my presentation subject matter, which i am going to convey
    in academy.

  2. Thanks for every other great post. The place else may just anybody get that kind of
    info in such a perfect means of writing? I have a presentation next week, and I’m
    at the search for such information.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>