UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 6.5 Free with a free account
File Extensions
Introduction to Operating Systems · Chapter 6: File Systems and Data ManagementSection 6.5 · lesson 52 of 836 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Hard and Soft Links →← File Allocation MethodsNext lesson: Hard and Soft Links →
A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →
In this lesson
How extensions label files and magic numbers reveal what they hold.
- Explain what a file extension is and how Windows, macOS and Linux use it
- Identify common formats from their magic numbers, such as PK for ZIP and %PDF for PDF
- Use the file command and xxd to check a file's real type
- Explain why renaming a file does not convert its format
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (825 words). Read along, or search it.
Opening Puzzle
The Name or the Bytes
Sam, who runs a small online bakery, gets an email with a file called order dot pdf. Sam double-clicks it, and it opens fine. Then a second file arrives, called photo dot t x t. A text program opens it, and shows a screen full of strange symbols. Same laptop, same operating system, two very different results. The difference is a tiny detail at the end of each name, and an even smaller one at the start of each file. So who's telling the truth: the name, or the bytes?
Definition
Letters After the Last Dot
The letters after the last dot of a name are the file extension. By habit, they say what kind of data the file is meant to hold. Dot t x t for plain text. Dot p n g and dot j p g for pictures. Dot p d f for documents, and dot zip for packed folders. Dot m p three for audio, and dot h t m l for web pages.
Operating Systems
How Windows, Mac and Linux Use Extensions
Systems lean on extensions differently. Windows maps each extension to a program, and by default File Explorer hides the extensions of well-known types. A Mac uses extensions too, but keeps extra type information as well. Linux doesn't need an extension at all, and many tools look inside the file instead. Either way, the extension is only a label on the box. A label alone can't prove what's inside. So turn on show file extensions, and a trick like invoice dot pdf dot exe can't hide.
Magic Numbers
Signatures in a File's First Bytes
Let's make three files on this Mac: a text note with echo, a real ZIP archive of that note, and a file that starts with percent P D F. Many file formats start with a fixed signature: a few bytes that mark the format. They're called magic numbers. x x d, dash l four, prints a file's first four bytes, in hex on the left and as characters on the right. The ZIP starts with hex five zero, four b: the letters P and K. Then come the bytes three and four. ZIP archives start this way. The PDF starts with percent P D F. The note starts with its own first characters, two, space, d, o, because plain text has no signature.
The file Command
Checking Signatures Instead of Names
The file command does this checking for you. It reads the first bytes, compares them with a long list of known signatures, and ignores the name. It calls the ZIP a Zip archive, the PDF a PDF document, and the note ASCII text. But look closely at menu dot pdf. It's only nine bytes long, not a real document. It starts with percent P D F, so file believes it. A signature is evidence, not proof.
Common Mistake
Renaming Does Not Convert a File
Now rename the ZIP to recipes dot t x t, with mv. The label changes. But file still says Zip archive, and the first bytes are still P K. Renaming changes the label, not the box. It's the same with converting. Renaming photo dot p n g to photo dot j p g doesn't make it a JPEG. To convert a file, open it in a program that knows both formats, and save it in the new one.
Quick Check
A PDF That Starts With PK
Quick check. Another file reaches Sam, called order dot pdf, and this one won't open in a PDF reader. Ivy, who looks after the computers at a school, checks its first four bytes: P, K, three, four. Is it a PDF whose start got damaged, plain text that happens to begin with P K, or a ZIP archive with the wrong name? Pause and predict. A zip archive. P K, three, four is the ZIP signature, whatever the name says. A damaged PDF is the tempting answer, but damage almost never produces an exact ZIP signature. And here's the twist: modern Word documents are really ZIP archives, packed full of parts.
Hidden ZIP
Word Documents Are ZIP Archives
Watch. This Mac's textutil tool turns the note into a Word document. Its first bytes are P K, three, four. Copy it under the name order dot pdf, and file still calls it a Word document. So Sam's file was most likely a Word document with the wrong name. Renamed to dot docx, it opens.
Puzzle Solved
A PNG Picture Labeled as Text
And photo dot t x t, from the start? Here's the start of a PNG picture: the eight bytes every PNG file begins with. The first one is hex eighty-nine, then the letters P N G. So a file named photo dot t x t, starting this way, is a picture with the wrong label. A text program shows its bytes as strange symbols. Renamed to photo dot p n g, it opens in a picture viewer.
Key Takeaways
When Name and Bytes Disagree
To recap. A file extension is a label: a habit that tells programs what the file is meant to be. Many formats begin with a magic number, a fixed signature, and tools like file read it instead of the name. Renaming changes the label, never the bytes. So when the name and the bytes disagree, believe the bytes.
About Introduction to Operating Systems at UPI Study
Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About File Extensions
What is a magic number in a file?
Does changing a file extension convert the file?
How can you tell a file's real type on Mac or Linux?
Why do docx files start with the same bytes as ZIP files?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Operating Systems.
83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →