File extensions in Linux

Try not to confuse third-party software!


Saeed Mohajeryami

2 years ago | 2 min read

Unlike Windows, Linux does not care about the extension of your files. It looks into the file contents and will figure it out by its own. In other words, Linux is extension agnostic. If you are interested to test it for yourself, use file command and give it your file name as an argument. For example, imagine you have a PDF file named tutorial.pdf, you can find its type by typing $ file tutorial.pdf on the terminal. Look at below picture. As you see the file type is PDF document and even when I changed it to Tutorial.txt, its type is still PDF document.

So, by changing a file extension, you can not fool the OS. It still knows what file type it is.

The file type does not change with changing the extension

However, you might fool third-party software. For example, if you have a text file named book.txt and change its extension to book.pdf , its icon changes because your system has assigned files with .pdf extensions to your PDF reader application for your convenience.

One file with two extensions

But if you try to open the file with PDF reader, you will get an error message. Look at the error message I got when I was trying to open book.pdf with my PDF reader. As you see below, it says, the file type plain text document (text/plain) is not supported.

Error message when trying to open a file with wrong extension

You might argue that extensions are important to Linux. The answer is extensions are not important to Linux, but they are important to Gnome, which is your desktop environment for Unix-like operating systems. Desktop environments have their own mechanisms that rely on file extensions to determine which applications to call to open a file. It makes things very convenient for the user.

Although Linux is extension agnostic, it does not mean extensions are useless. They are quite useful conveying information about the file type. Linux doesn’t care, but you as a user might care to learn what file does without looking at its content. For example, the moment you see and setup.txt, you can quickly distinguish which one is executable and which one is just a guide.

This article was originally published by Saeed Mohajeryami on medium.


Created by

Saeed Mohajeryami

I am a highly skilled Senior Data Engineer with a strong background in data engineering and data science. With over 10 years of experience in the field of computer science and software engineering, I have honed my skills in a wide range of programming languages including Python, JavaScript, Scala, Java, and SQL. I have extensive experience working with various databases, including PostgreSQL, SQLite, MongoDB, DynamoDB, and Redis, and have also worked with data warehouse technologies like BigQuery, Snowflake, and AWS Redshift. I am proficient in big data platforms like Spark, Kafka, GCP Pub/Sub, AWS Kinesis, and Apache Beam, and have experience with DE tools like Apache Airflow, dbt, Ascend, and Looker. I am deeply committed to staying up-to-date with the latest technologies and am skilled in DevOps tools like Git, Terraform, Jenkins, Docker, and Github Actions. I also have experience with containerization technologies like Docker and Kubernetes, and hold an AWS Certified Solution Arc







Related Articles