DEV Community


Is there any way I can change a file header in Linux like how I'd change a file extension in Windows (10).

Calin Baenen
I'm a programmer born on October 30th, 2006. I love programming, it has, and always will be my passion.
・2 min read

I know in Windows, "file extensions", the part of a file name after the final period in the file name, are more than just part of the file name, they also act as metadata to tell Windows what kind of file the document should be treated as, and what apps to open them in (i.e. what apps are associated with those file types).

However, I want to start moving to Linux (Ubuntu) which I installed on my PC a while back, so, I recently tried making a new file ("extensionless"), and I wanted to make it a different type, so I tested to see if that would work by testing by renaming it .go, so I could try to open it in VSCode like I normally would on WIndows.
Surprise, it doesn't work.

I look up multiple searches, involving how to change the file extension (only getting results using command line), and eventually coming over to a horrifying S.O. answer that horrified me, it gave me the info that "extensions" (file types) are determined by header.

There doesn't seem to be any way in the "Files" file manager for Ubuntu to change the header type.
There seems to be no concept of anything other than a plain "Text" file.
(Well, there is, but you just can't see or change it.)

What I want is a program that can give me a simple GUI to edit the file type of a file so I can easily go between one or the other as needed/wanted.
(Even better, and more appreciated would be some kind of program that works with "Files" to add the option to change the filetype-header in context menu (when a certain file is selected). Though, either will do.)


OS: Ubuntu 20.04.2 LTS
WindowingSystem: X11
GNOME: 3.36.8
Enter fullscreen mode Exit fullscreen mode

Discussion (2)

cappe987 profile image

You are correct in that the extension doesn't matter and the type of file is determined by the header. But you don't change the header, that can mess up the file. What you instead should change is the default application used to open that file type. You don't say what happens when you try to open the .go file, but when I open both an extensionless or a .go file it defaults to Gedit (simple text editor). If I right click that file and select Properties and then Open With I can set the default to vscode. Then double clicking the file opens it in vscode.

Windows works the same, except that it looks at the file extension instead of the file header to determine which program it should use. If the wrong program is used you can change the default on Windows as well.

baenencalin profile image
Calin Baenen Author • Edited

Is there any way to set the default program for a group of "extensions" on Ubuntu?
I read what you suggested, but I can't tell if this is file or extension specific.