163
submitted 9 months ago by perishthethought@lemm.ee to c/linux@lemmy.ml

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!

top 27 comments
sorted by: hot top controversial new old
[-] offspec@lemmy.nicknakin.com 37 points 9 months ago

I believe this is simplified to open on most platforms

[-] perishthethought@lemm.ee 16 points 9 months ago

Yep, that does for me too, thanks!!

[-] Jumuta@sh.itjust.works 19 points 9 months ago

that's cool

I've always just done

dolphin .

but that's nifty to know!

[-] atzanteol@sh.itjust.works 18 points 9 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.

[-] perishthethought@lemm.ee 4 points 9 months ago

Yes! That works too. Thanks!!

[-] Dehydrated@lemmy.world 17 points 9 months ago

I'd create an alias: alias open=xdg-open

It's easier to type in that way

[-] perishthethought@lemm.ee 8 points 9 months ago

I totally did, yes:

alias xo='xdg-open $1 &>/dev/null'

... since it always has some odd output when I run it here on my pc.

[-] Dehydrated@lemmy.world 2 points 9 months ago

That's actually a great idea, thanks for the suggestion

[-] palordrolap@kbin.social 6 points 9 months ago

Some systems already have this implemented. For example, on my machine open is /usr/bin/open which links to /etc/alternatives/open which in turn currently points at /usr/bin/xdg-open.

[-] Dehydrated@lemmy.world 3 points 9 months ago

I've seen this on a few Linux distros. MacOS also has something similar, not based on XDG but it works really well. It also uses the open command.

[-] marty_relaxes@discuss.tchncs.de 16 points 9 months ago* (last edited 9 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.

[-] stepanzak@iusearchlinux.fyi 4 points 9 months ago

Does your blog have an rss feed?

[-] marty_relaxes@discuss.tchncs.de 5 points 9 months ago

The rss feed should be accessible here but it's unfortunately a little buggy, been meaning to spruce it up for ages.

[-] stepanzak@iusearchlinux.fyi 1 points 9 months ago

Awesome, thanks

[-] perishthethought@lemm.ee 3 points 9 months ago

Ooooh, really? I need to do that next

[-] merthyr1831@lemmy.world 10 points 9 months ago

<3 XDG, bringing so much utility and cross-compatibility to Linux regardless of your distro and window manager

[-] astrsk@kbin.social 6 points 9 months ago

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

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

[-] perishthethought@lemm.ee 2 points 9 months ago

alias 'rise-chtulu-rise-you-immortal-god /some/path'

hahaha

[-] abuttandahalf@lemmy.ml 6 points 9 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.

[-] jbrains@sh.itjust.works 4 points 9 months ago

Between this and rifle, all things are possible. Enjoy.

[-] NegativeLookBehind@kbin.social 3 points 9 months ago
[-] GreyFalcon@iusearchlinux.fyi 2 points 9 months ago
[-] perishthethought@lemm.ee 1 points 9 months ago

You're welcome

[-] palordrolap@kbin.social 2 points 9 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 1 points 9 months ago
[-] perishthethought@lemm.ee 1 points 9 months ago
[-] library_napper 2 points 9 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

this post was submitted on 19 Jan 2024
163 points (97.1% liked)

Linux

48040 readers
967 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS