DEV Community

Cover image for How To Open A File or Folder ( to GUI ) From The Terminal in Ubuntu
Martins Ngene
Martins Ngene

Posted on

6 1

How To Open A File or Folder ( to GUI ) From The Terminal in Ubuntu

While you can use the cd command to navigate into folders and files, sometimes you may want to view the content of a file or a folder graphically without going through the hassle 😤 of using your GUI tools.

Today I will show you how to do that 😎. Hi, I'm Martins Ngene, A Software Engineer. I'm happy to bring you this information 🤓

So, getting started I presume you are at the home directoy in your terminal. Let's say johndoe@johndoe-HP-EliteBook-8460xx:~$ and you want to take a look at the package.json file of a project deeply nested in your projects folder located in your Desktop folder ~/Desktop/projects/blog/package.json

All you need to do is use the xdg-open command which is installed by default in Ubuntu 22.04. You can also use it in Ubuntu 18.04, 20.04 or install it if its not available using
sudo apt-get install xdg-utils. If you encounter any issues maybe you use a different distro, you can refer to this Stack exchange post.

Using the xdg-open command

To use the command simply type the code below in your terminal and adjust path url to the file/folder you wish to open:

johndoe@johndoe-HP-EliteBook-8460xx:~$ xdg-open ~/Desktop/projects/blog/package.json
Enter fullscreen mode Exit fullscreen mode

This opens the package.json file in your default text editor.

To open a folder:

johndoe@johndoe-HP-EliteBook-8460xx:~$ xdg-open ~/Desktop/projects/blog
Enter fullscreen mode Exit fullscreen mode

This opens the blog folder with your default file manager.

An Alternative

Maybe for some reason the above tool doesn't work for your distro, you can always use an alternative.

The command below will perform the same operation:

gnome-open ~/Desktop/projects/blog or
gio-open ~/Desktop/projects/blog if you use a more recent
version of ubuntu.

You can download this tool using sudo apt-get install libgnome2-0 in your terminal.

I hope this helps you and feel free to share your thoughts and/or contributions in the comment section 🤗

We can connect on LinkedIn. Follow me here for more contents on proramming and software engineering.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay