File Extensions, Explained | Introduction to Operating Systems

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

← 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 →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

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.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

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.

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?
A magic number is a fixed signature in a file's first few bytes that marks its format. A ZIP archive begins with the bytes 50 4B 03 04, shown as the letters PK, a PDF begins with %PDF, and a PNG image begins with the byte 89 followed by the letters PNG. Plain text has no signature, so it starts with its own first characters.
Does changing a file extension convert the file?
No, changing the extension changes the label, not the bytes inside. Renaming photo.png to photo.jpg leaves the PNG data untouched, so the file is still a PNG. To truly convert a file, open it in a program that understands both formats and save it in the new one. Tools that read signatures will still report the original format after a rename.
How can you tell a file's real type on Mac or Linux?
Run the file command, which reads a file's first bytes and compares them with a long list of known signatures, ignoring the name. To see the bytes yourself, xxd -l 4 prints the first four in hex and as characters. A signature is strong evidence rather than proof, since a short file can start with %PDF without being a real document.
Why do docx files start with the same bytes as ZIP files?
Modern Word documents in the docx format are packages of separate parts bundled as a ZIP archive, so they begin with the ZIP signature PK followed by the bytes 03 and 04. That is why a docx file with the wrong name, such as order.pdf, fails in a PDF reader. Renaming it back to end in .docx lets a word processor open it normally.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

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

Introduction to Operating Systems
3 credits · NCCRS
Enroll →