I want to get the title of the media playing in VLC using the Command Line. The closest thing I currently have is this command.

ps aux | grep vlc

The output is

pc       27636  2.1  2.3 1261964 90028 ?       Sl   21:46   0:23 /usr/bin/vlc --started-from-file /media/pc/Everything/TV shows/Discovery Channel - The History Of Hacking.avi
pc       28317  0.0  0.0  11748  2196 pts/0    S+   22:05   0:00 grep --colour=auto vlc
  • vlc has a cli module. vlc --extra-intf luacli will open an X window and the cli in your terminal session. you can background it, or whatever, or run it via telnet or tcp as well. but get_title prints the currently playing media item's title. – mikeserv Dec 2 '15 at 19:34
  • You might find this script helpful. It was written by Nathan Osman who's often in the Ask Ubuntu main chat room. He might be able to help more if you catch him there and he has the time. – terdon Dec 2 '15 at 22:48

I'm sure there's a nice, clean way of doing this. Probably via D-bus. Sadly, I don't know what that way is so here's a more hacky approach. You can use lsof to print the files opened by a running process. The relevant option here is (from man lsof):

-c c    selects  the  listing  of  files  for  processes  executing the
        command that begins with the characters of c.  Multiple commands
        may be specified, using multiple -c options.  They are joined in
        a single ORed set before participating in AND option selection.

So, lsof -c vlc will list all files opened by processes whose name starts with vlc. That, however, will list all sorts of stuff, including various libraries and other things we don't care about. The 4th field of lsof's output (on my Arch, at least) is the file descriptor of the file (for regular files) followed by a single letter describing the mode in which the file has been opened (r for reading, in this case). The 5th field is the type of file and here, we want that to be REG for regular. Putting all this together, we get (the -w suppresses warnings):

$ lsof -wc vlc | awk '$4~"[0-9]r" && $5=="REG"'
vlc     16532 terdon   16r      REG    8,19    131338  69731703 /path/to/foo.avi

To get only the file name you could use GNU grep:

$ lsof -wc vlc | awk '$4~"[0-9]r" && $5=="REG"' | grep -o '/.*'

And to get the file name only:

$ lsof -wc vlc | awk '$4~"[0-9]r" && $5=="REG"' | grep -o '[^/]*$'
  • dbus method here: askubuntu.com/questions/405931/… (but IMO the trouble with dbus is that most apps' usage of it is, for the most part undocumented, and often changes without warning. you have to do a lot of querying and testing to find out if the data you want is even available, let alone how to get it) – cas Dec 3 '15 at 2:00
  • the dbus interface seems to be reasonably well documented for VLC, though. specifications.freedesktop.org/mpris-spec/latest/index.html – cas Dec 3 '15 at 2:06

I'm not sure if you are after the title (which is in the file metadata) or the filename (which is in the command line). Any ps or pgrep thing won't directly get you the title but it can get the file. You can get all the vlcs running and their command line with.

pgrep -a vlc

This will find any process with vlc in its name but not flags, so it matches a binary running called a-program-with-vlc-in-it but not someotherprogram --flags --do-vlc

Now how you extract the filename out of the command line is a bit fiddly, you might want to run it through sed but I imagine it will be a bit fragile.

pgrep -a vlc | sed -r 's%^.*\/([^/.]+)%\1%g'

You'll get a list of programs running with vlc in their binary name and the output is everything past the last slash up to the dot.

You start playing something like /home/movies/Dr. No.mpg then you're out of luck.


You can use d-bus by looking at mpris interface specification at here

By using qdbus and mpris interface:

qdbus org.mpris.MediaPlayer2.vlc \

(VLC can be replaced with other media players as well.) And then extracting Metadata from it:

/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata \

and Finally by using grep and cutting the unneeded data you can see the title:

| grep "xesam:title:" | cut -c 14-

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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