DEV Community

Calin Baenen
Calin Baenen

Posted on

1 2

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

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.)

Info:

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

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (2)

Collapse
 
cappe987 profile image
Casper

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.

Collapse
 
calinzbaenen profile image
Calin Baenen • 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.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay