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:

#!/bin/sh
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.

One Response 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.

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>