Linux default open files

Why does linux use file extension to decide the default program for opening a file though it’s independent of file extensions

I have a text file as- abc.text and it has its contents as Hi I’m a text file. If I double click to open this file, then the files is opened in gedit editor. Whereas, if I rename the file to abc.html (without changing any of its contents) then by default it opens in Chrome. This sort of behavior is acceptable on a Windows machine, since Windows uses file extensions to identify file types. But as far as I’ve read, Linux doesn’t need file extensions. So why does changing file extensions in Linux changes the default program that opens it?

What @bsd is saying is that a desktop environment has its own mechanisms to determine which file to open with which application when selecting them in a file browser. And this mechanisms are usually extension based, for the convenience of the user and to follow the rule of least surprise. This has nothing to do with anything in Linux (meaning the kernel and, perhaps, the core libs and utilities), which remains extension agnostic.

3 Answers 3

Linux doesn’t use file extensions to decide how to open a file, but Linux uses file extensions to decide how to open a file.

The problem here is that “Linux” can designate different parts of the operating system, and “opening a file” can mean different things too.

A difference between Linux and Windows is how they treat application files vs data files. On Windows, the line between the two is blurred; there are a few types of executable files, and they are determined by their extension ( .exe , .bat , etc.), but in most contexts you can “execute” any file (e.g. by clicking in Explorer), and this executes the executable that is associated with that file type, where the file type is entirely determined by the extension (so executing a .doc file might start c:\Program Files\something or other\winword.exe , executing a .py file might start a Python interpreter, etc.).

On Linux, there is a notion of executable file which is independent of the file name. Executables generally have no extension, because they’re meant to be typed by the user. The type of the file is irrelevant, all the user wants to do is execute the file. The kernel determines how to execute the file from the file contents: it knows some file types natively, and the shebang mechanism allows a file to declare any other executable file¹ as its interpreter.

On the other hand, data files usually do have an extension that indicates the type of data. The general idea here is that the type of data is not synonymous with what application to use to open the file with. You may want to view a PDF in Okular, or in Evince, or in Xpdf, or in Acroread, or in Mupdf, etc.

Читайте также:  Линукс скопировать найденные файлы

There are many tools that do however allow opening a data file without having to explicitly specify what application to use. These tools almost exclusively base their decision on the file extension. The file extension and the file’s content are the only information that these tools have at their disposal: Linux does not store any meta information regarding the file format. So when you click on a .pdf file in a file manager (or when you run the .pdf file on a suitably-configured zsh command line, etc.), the file manager consults a database to find what application is the preferred one for .pdf file. This database may be structured in two sections, one that associates extensions to MIME types ( /etc/mime.types , ~/.local/share/mime ) and one that associates MIME types to applications ( /etc/mailcap , ~/.local/share/applications ), but even so the origin is the extension. While it would often be possible to figure out the application from the file content, this would be slower, and not always possible (many formats look just like text files, a .jar is a type of .zip , etc.).

Linux doesn’t need file extensions, and it doesn’t use them to determine how to run an executable file, but it does use them to determine which program to use to open a data file.

¹ That file has to be a native executable, a shebang executable can’t point to another shebang executable to avoid potentially unending recursion.

Источник

How to Change Your Ubuntu’s Default Applications

Change Ubuntu Default Applications

Change Ubuntu Default Applications

We all have our preferences when it comes to the application we want to use for opening and working with a certain file type. For example, whenever I start using a new version of an operating system, I install and switch to the VLC media player for playing music and videos. In Ubuntu, you can change your default applications both through the command line and the graphical user interface through the simple steps described in this tutorial. We have performed the commands and procedure described in this tutorial on the latest Ubuntu 18.

Change Default Apps Through the Command Line

When you access any application through the command line by a generic name, such as ‘editor’, it looks for the default application set in the system and points to the exact default application and opens it. For example when I enter the following command:

It opens the Nano editor on my system as it is the default text editor for Ubuntu 18.04 (Bionic Beaver).

If you want to change the default editor or any other program for that matter, you can use the update-alternatives utility for this purpose.

$ sudo update-alternatives --config [applicationname]

Example: Changing the default text editor

In this example I will change my default Nano editor to another preferable alternative through the following command:

$ sudo update-alternatives --config editor

This command will give me an entire list of alternatives for the text editor along with the one with auto mode status as follows:

Читайте также:  Fixing bugs in linux

Change the Ubuntu default text editor

By entering a selection number associated with my choice and then pressing Enter, I can switch to a new default text editor that will be used to open my text files next time by default.

If you use this command to look up for alternatives but none exists, you will get the following message. You will then require downloading an alternative and then switching to it.

Switch animate

Searching for alternatives all at once

The following command will list, and let you choose from, an available list of alternatives for all your default applications.

$ sudo update-alternatives --all

The following output is displayed for my system, representing that there are alternatives available only for the editor applications. By specifying a selection number and hitting Enter, I can change the default editor for my Ubuntu.

Searching for avaulable alternative applications

Change Default Apps Through the GUI

A more user-friendly alternative to changing your default applications is through the user interface. We will represent the following two ways to do so:

  • Through the Settings utility
  • By specifying default application for opening a certain file

Through the Settings Utility

Click the downward arrow located at the top right corner of your Ubuntu desktop and then click the settings icon located at the bottom left corner:

Launch the settings utility

Type Settings in the Ubuntu Dash as follows:

Search for settings utility on desktop

The Settings utility will open displaying the Wi-Fi tab as default.

Then click on the Details tab and then the Default Applications tab.

The following view will list all the default applications of your system.

List of default desktop applications

In order to choose a different application than the default one, click the downward arrow and make a new selection against a category as follows:

Select a different default application from dropdown menu

In this image, I have selected Shotwell Viewer to open my photos instead of the default Image Viewer application.

Changing Default Application for Removable Media

Through the Devices tab in System Settings, select the Removable Media tab. The list of removable media and the default program to open the media will be displayed.

In order to change the default application, click the down-arrow beside the Other Application drop-down and select the application from the Select Application dialog as follows:

Changing Default Application for Removable Media

Your newly selected application will now be used for opening the removable media from then on.

Changing Default Application for Opening a Certain File Type

By setting the default application for opening a certain file, you can select the default application for opening all files of the same type. Here is an example:

Example: Setting all .png files to be opened in Shotwell Viewer

Through the file viewer, right-click a file with the .png extension and then select Properties as follows:

Change application to view PNG files

The Properties window will open.

Click on the Image tab and select Shotwell Viewer (or any other preferable applications) and then click Reset.

Make Shotwell Viewer the default app for .png files

Your newly selected application will not only open this .png file in the future but also all other files with .png extension.

In this tutorial, you have learned several ways to change the default application used to open a file on your Ubuntu system. You can use both the command line or the two ways described in this tutorial for the GUI to select new applications that will be used to open your files.

Читайте также:  Установка кали линукс vmware

Источник

Linux default open files

Analog and digital electronics · Arduino projects · Development boards · DIY · Technology related stuff

Change default open with application in Ubuntu

LOGO

Posted by: Cornelius One Transistor Posted on: July 15, 2023 Updated on: 2023-07-15T19:49:15Z

How to change default open with application for any type of file on Linux Ubuntu using a simple command in terminal

With the new Ubuntu 23.04 release I found myself struggling to find a valid answer to a very simple task. I own a 3D printer and I design stuff in FreeCAD, then export to STL and load this in Cura to slice it and produce gcode for printer. If in Windows 11 there is a 3D viewer application which opens STL files, Ubuntu doesn’t come bundled with a similar app and I hate loading every STL file in Cura just to see the 3D model. However, there is fstl, which I found it to be exactly what I was looking for: it is lightweight and it opens STL files.

I installed it from default repositories with sudo apt install fstl. Although this is a GUI app, it can only be started from command line, having no desktop entry to open it from Apps. I didn’t have a problem with this, since I knew I could select any executable to open a file with. However, this is is no longer true. The Open With dialog no longer allows users to choose something else besides installed applications.

Open With dialog in new Ubuntu versions
Open With dialog in new Ubuntu versions

There is no option to choose something else. Neither here, neither if I open file properties. So I did the first thing: performed an internet search on how to change default open with app for a file in Ubuntu. Unfortunately, I was really disappointed with the results.

All Linux/Ubuntu how-to sites told me the same things:

  1. Right-click file, select Open With and choose another application. Ok, but what I do if I don’t have the app I want in that list?
  2. Right-click file, select Properties and change it from there. This option is no longer there, or I suddenly go blind when I open that dialog.
  3. Open Settings, go to Default Apps and change as you like. Useless, I don’t want to change common web, mail, calendar, music, video and photos defaults.
  4. Open a terminal (this already seemed promising) and run sudo update-alternatives —all. No way!
File Properties dialog in Files app
File Properties dialog in Files app

Now, after this long introduction, here is the terminal command which does exactly what I needed:

mimeopen -d your_stl_file.stl

Just point it to an existing STL file. Type 3 to select another application, then write the name or full path to that application. It is as simple as this. I had to check fstl GitHub page to find this, because all the other how-to’s failed to show me this. This is its output:

Please choose a default application for files of type model/stl 1) UltiMaker Cura (5.4.0) (appimagekit_a4a62d92a77ef06111291d2741567faa-UltiMaker_Cura) 2) FreeCAD (org.freecadweb.FreeCAD) 3) Other. use application #3 use command: fstl

It automatically sets the default app for opening similar files. This was a case where the most obvious solution was not easy to find. However, no I can double-click STL files and have them opened it fstl.

Источник

Оцените статью
Adblock
detector