Just sharing something neat I learned today about Linux…

In Windows, I used to do this a lot:
– Be at a command prompt, in some directory, e.g.: C:\my files\more files
– When I need to see that same folder in the Windows GUI, I’d type: start . (note the period, meaning “this directory”)
– The Windows file manager would open in a new window, focused on that same folder as the path.

I realized today I didn’t know how to do that in Linux (I’m on Ubuntu) so I searched around and found the xdg-open command.

The man page for xdg-open says:

xdg-open opens a file or URL in the user’s preferred application. If a URL is provided the URL will be opened in the user’s preferred web browser.

At any terminal prompt, I type something like:

xdg-open .

or xdg-open ~/Documents

And boom! A new KDE Dolphin files window appears, focused on that path.

or this works too, but with a browser:

xdg-open http://eff.org

Rock and/or roll!

  • marty_relaxes@discuss.tchncs.de
    link
    fedilink
    English
    arrow-up
    9
    ·
    edit-2
    10 months ago

    xdg-open is very nifty, especially due to its ubiquitousness on a variety of distributions. You can even have a look inside to see that it is actually a shell script yet again invoking other ‘opening’ scripts in the background!

    I wrote a little bit about it and an alternative to it called mimeo not too long ago. That one can even open things by advanced filters such as regexes. So you could e.g. open https://eff.org in Firefox and http://localhost:3000 in a different application or other advanced shenanigans - though I’ve never used such advanced features much.

    • atzanteol@sh.itjust.works
      link
      fedilink
      arrow-up
      4
      ·
      10 months ago

      xdg-open will check mime types and open files with preferred applications as well. So ‘xdg-open foo.ods’ will launch libre office for example.

  • astrsk@kbin.social
    link
    fedilink
    arrow-up
    3
    ·
    10 months ago

    Now you know about the command and can alias it to whatever floats your boat!

    ‘open .’
    ‘exhume /my/file’
    ‘liberate my.site’

  • abuttandahalf@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    10 months ago

    xdg-open is one of the most used commands on my system. Video files, movies, pdfs, etc if I want to use the default application to open anything I use it. No need to memorize each application’ commands.

  • palordrolap@kbin.social
    link
    fedilink
    arrow-up
    2
    ·
    10 months ago

    Users of GNOME-derived window managers might also want to look into the gio command that abstracts a lot of GUI things through the command line. Most of the functionality duplicates more basic commands, but these use the GUI’s API / behaviour where possible.

    The best example might be gio trash which can delete things to the desktop Rubbish/Recycle/Trash bin rather than vanish them completely as rm does.

    A pity there’s no xdg- wrapper that encompasses gio and whatever KDE and others do though. Maybe that’ll happen one day.

      • library_napper@monyet.cc
        link
        fedilink
        arrow-up
        2
        ·
        10 months ago

        When I type, it does what you expect (going to the file/folder in the current directory by what you type).

        Some time ago the others started doing some annoying search thing when you type, and I can’t find how to turn that off. Anyway thunar is simper and gets the job done faster