<p>Was in a conference the other day and someone was showing intercept security... A .exe file started with MZ. Why? Those are the initials of the man who created the first DOS executable file format. Many kinds of files have 'signatures' in the first few bytes. </p>

<p>I used to use a tool called 'strings' that would show any displayable sequences of characters in an otherwise 'binary' file. Helpful sometimes. We have gotten far away from this level of reality in our everyday use of computers, so it is good to show that there is really no mystery, it is all just a heap of ideas people have had over time, piled up in layers. Start at the bottom with characters and follow the clues.</p>

<p>Attack it in many ways, showing the aspects of 'files' that are meaningful to you. Give some of the history. I am sure you can come up with analogies. One issue is that although 'file' makes some sense, 'folder' does not, because we don't ever nest manila folders! Nnnnt! The other term, 'directory', has fallen in to disuse, and really is not any better. </p>

<p>What is a synonym for what we call folder...? There isn't one! It is a brand new concept, like variables. Nothing else in our world is like that. This is why we have to show that analogies are limited and misleading. You have to actually <em>know</em> some things.</p>

CC BY-SA 4.0
2019-04-20T13:06:07.427Z
And how many of the students have seen a manila folder? A floppy? A dial phone? They have no experience with the things we analogize *from*! Lost beyond lost in a hall of mirrors.
Scott Rowe
CC BY-SA 4.0
2019-04-22T11:00:11.607Z
Could you explain what you mean by *"lost beyond lost in a hall of mirrors."*?
Malekai
CC BY-SA 4.0
2019-04-22T11:12:35.917Z
@LogicalBranch Sure. Humans usually make meaning by relating to things in their environment. The floppy disk is the icon for 'store' because they used to be commonplace. But to someone who has never seen one, it doesn't have any inherent meaning. If a student is asking what a file is, it probably means they have no referent, no commonplace objects, situations and processes that they can intuitively substitute. If all of computing is strewn with metaphors and references to never-before-known things, it is basically like going to a foreign planet and trying to start from nothing.
Scott Rowe
CC BY-SA 4.0
2019-04-22T11:17:10.423Z
Beyond, that, the references seem pointless and strained. Floppies only make sense without an internet. And if your entire life experience is that the internet has always just "been there", how can any other scenario make any sense? If I put you down in the Amazon rainforest and said, "There is lots of food here. Just watch out for the dangerous things." would you be likely to survive even for 2 days, or know what killed you in your sleep? No. This is the world we put our children in to with no preparation, because we cannot see it from their point of view.
Scott Rowe
CC BY-SA 4.0
2019-04-22T11:18:32.850Z
Thanks for taking the time to explain, I appreciate it.
Malekai
CC BY-SA 4.0
2019-04-22T11:20:28.050Z
Sure. This is why I keep crying like the little voice in the wilderness: "We have to start with the the basic level of how things *actually work*!" And everyone here says I am wrong. We shall see. Wait... We are seeing now.
Scott Rowe
CC BY-SA 4.0
2019-04-22T18:57:18.383Z
+1 @ScottRowe, "Just watch out for the dangerous things" - this reminded me of theme in Heinlein's "Tunnel in the Sky": the kids are sent to a remote planet and among other things are told to "watch out for stobor." They weren't told how this *stobor* looks like and what can it do. Interestingly, this seemed to work, but I'm not throwing spoilers here :)
Aksakal almost surely binary
CC BY-SA 4.0
2019-04-20T13:03:20.123Z
2019-04-20T13:03:20.123Z
Scott Rowe
<p><em>As is the case with most simplified explanation, I have glossed over some more advanced specific details that don't factor into the basics on file systems.</em></p>
<h2>File content</h2>
<p>At its most basic level, a file is really just <strong>a sequence of ones and zeroes</strong>. It's data. There's nothing more to it than that.</p>
<p>This data can then be interpreted. We (or an application) take the ones and zeroes, attribute meaning to them, and this interpretation is informative to us (or an application).</p>
<p>&quot;Interpretation&quot; is the operative keyword here. The same arbitrary sequence of ones and zeroes can be interpreted in any way you want to. However, in most cases only one interpretation will make sense, and other interpretation will look like garbage.</p>
<p>So how do we know which interpretation should be used for which file? Answer: the <strong>file extension</strong>. A file extension denotes how the data in the file is structured, and therefore how it can be sensically interpreted.</p>
<p>Your OS automates this process for you. Instead of you having to look at the extension and then find the correct application which can interpret your file in the way you need it to be interpreted, your OS automatically maps a given file extension to your preferred application. For example, you might configure Windows to open <code>.txt</code> files with WordPad, or Notepad, or Notepad++, or some application you wrote yourself. All of these application are capable of performing the interpretation that a <code>.txt</code> file needs.</p>
<p>You can override this behavior. You can open a <code>.png</code> file in Notepad. It won't make sense, but what you are seeing is the result of a <code>.txt</code> interpretation being applied to a file whose data structure is that of a <code>.png</code>.</p>
<p><code>.txt</code> files are very easy to interpret. Ignoring encoding for now (let's assume ASCII), every byte (= 8 bits) of the ones and zeroes represents a single number, which in turn represents a single character.<br />
To really prove the point, you could do this manually. Let's say I want to store a text file containing <code>apple</code>. You can use an <a href="http://sticksandstones.kstrom.com/appen.html" rel="nofollow noreferrer">ASCII table</a> to look up what the numeric representation of each character is.</p>
<pre><code>a = 01100001
p = 01110000
p = 01110000
l = 01101100
e = 01100101
</code></pre>
<p>If you use your text editor of choice, set the encoding to ASCII, enter <code>apple</code> and save the file, the file's ones and zeroes will exactly be the sequence of binary digits I just listed.</p>
<p><code>.txt</code> is really easy, but file structures can get significantly more complex, to the point where it is no longer feasible for a human to manually interpret all the data. For example, even though a <code>.pdf </code>file might only contain text (to your eyes) just like a <code>.txt</code>, it actually stores a whole lot more data (text markup, file metadata, ...) and this makes it less than obvious to interpret the binary data ourselves.</p>
<p>But to prove the point on how you can interpret files in a non-text example, suppose you (as a teacher) want to track whether your students were present/absent every day of school. Assuming you have 16 students, you could track this using a very simple sequence of 16 binary digits:</p>
<pre><code>1111111111011111
</code></pre>
<p>Everyone was present that day, except student 11.</p>
<p>Is this a good file format? Well, it's very efficient. But it also lacks context. There's an assumption on which students were in your class. There's no way to track justified absences, etc. To really cover all the information you need, you're going to need a more complex system. But if you assume a simple present/absent mark for a fixed list of students, the above file format could theoretically suffice.</p>
<blockquote>
<p><strong>Interesting experiment</strong><br />
Take an existing Word/Excel file, one with an &quot;x&quot; in the file extension (<code>.docx</code> or <code>.xlsx</code>). Change its file extension to <code>.zip</code> and try to open it. It... works!?<br />
Since the advent of the new Office file formats, Word and Excel documents are really just secret zip archives, not custom binary file formats like they used to be. But by using a unique file extension instead of <code>.zip</code>, people can still configure these <code>.docx</code> or <code>.xlsx</code> files to be automatically opened using Word/Excel instead of however they've configured <code>.zip</code> files to be opened.</p>
</blockquote>
<hr />
<h2>File name (and path)</h2>
<p>At its most basic level, a file name is just one long string of characters, nothing more.</p>
<p>Obviously, we're likely going to want to store more than one file on our computer. So we need a way to reference each file that we store. This is why we give them a name, to tell them apart. This is no different from why humans give eachother names.</p>
<p>As mentioned before, we add a file extension to the end of the name, so that we remind ourselves (and the OS) of the data structure that was used for the file content.</p>
<p>But we often have a lot of files. We'd really like to organize them properly into little collections, instead of throwing them all on one big messy pile. To do this, we started prepending our filenames with what we call the &quot;path&quot;.</p>
<p>A path is nothing more than a (back)slash-separated sequence of names which list the hierarchy of how we'd like to organize our files. The OS will take the file name, split the names into the separate chunks, and will use that hierarchical information to show your files in a neat and organized manner.</p>
<p>Every file's name is really just a combination of:</p>
<pre><code>[folder chunks][name of the file].[file extension]
</code></pre>
<p>Take the example of the following file names:</p>
<pre><code>C:\Fruit\apple.txt
C:\People\PeopleILike\Tom.png
C:\Fruit\banana.txt
C:\People\PeopleIHate\Kevin.png
</code></pre>
<p>If you split the names in the chunks between the backslashes, you can start seeing the structure. For example, the first and third file have exactly the same chunks before their file name. Therefore, they belong in the same folder. The second and fourth file have a common first chunk, but then they have a different chunk. Therefore, they are found in the same parent directory but then live in a different subdirectory.</p>
<p>If you apply this logic, just like how an OS does, you come up with the intended organisational structure:</p>
<pre><code>C/
├─ Fruit/
│  ├─ apple.txt
│  ├─ banana.txt
├─ People/
│  ├─ PeopleIHate/
│  │  ├─ Kevin.png
│  ├─ PeopleILike/
│  │  ├─ Tom.png
</code></pre>
<p>We like to think of our file system as this neat nested system of folders and subfolders. But in the underlying file system, we don't actually store a &quot;folder&quot; by itself. A folder is really just generated dynamically based on the slash-separated chunks found in a file's name.</p>
<p>This leads to some interesting effects:</p>
<ul>
<li>Want to move a file? All you have to change is the file's path. You don't need to update a folder itself.</li>
<li>Want to rename a folder? Then you're going to need to change this name in all of the files who contain this folder in their path.</li>
</ul>
<p><strong>This is an oversimplification</strong>. File systems are more complicated than this, because you need the ability to e.g. create empty folders. But this is a good first explanation of how the file system works.</p>
<hr />
<h2>File metadata</h2>
<p>Next to the file name and content, there's more things we know about the file, such as when it was created, whether it is read-only, any permissions attached to the file, ... These things are not stored in the file content. They are an addendum to the file.</p>
<p>If you transfer a file from one file system to another, this data may be lost if the target system doesn't know how to work with the source system's metadata structure. However, this doesn't matter in terms of using the file itself. Your data is safe. You might just lose track of e.g. when your file was created.</p>

CC BY-SA 4.0
2021-10-29T15:26:28.607Z
this is incorrect. A name is just the name of a single file or directory. What you describe as name is a path. Also, the name is part of the path.
linuxUser123
CC BY-SA 4.0
2022-04-28T20:26:30.427Z
good, but I wouldn't start with "a series of ones and zeros" in the most basic explanation, since there's basically no simple way for students to view files as a series of ones and zeros.  I feel like starting with "a series of letters, numbers, and about 200 other symbols" will let them explore better, and next they can learn that these symbols are representations of ones and zeros.
Michael Scott Asato Cuthbert
CC BY-SA 4.0
2022-04-29T08:33:02.560Z
@MichaelScottAsatoCuthbert _"a series of letters, numbers, and about 200 other symbols"_ does not in my opinion adequately cover what a file is, it is one specific way (of countless many) of how a file can be interpreted. Yours is a more concrete example use case of a file and I agree that this helps with understanding the general purpose of a file; which is why my answer pretty much _immediately_ discusses interpretation after stating that a file is a sequence of ones and zeroes; but it is not a good base definition of a file in and of itself.
Flater
CC BY-SA 4.0
2022-04-29T08:39:15.220Z
@linuxUser123: The answer builds up the understanding of file names and paths step by step. I refer to the name (i.e. filename) first before then introducing paths which are used to further organizes these files (which up until then only had names, not paths). The wording I used was intentionally chosen to be layman-readable. As mentioned in the final paragraph of that section, my explanation is an oversimplification. This answer favors layman-human-readability over technical pedantry. It should not be used as a technical reference, only as a basic grasp on the components at play.
Flater
CC BY-SA 4.0
2021-10-04T10:41:25.920Z
2021-10-05T10:17:33.363Z
2021-10-05T10:17:33.363Z
Flater
<p>Nothing wrong with citing all the "dictionary" definitions found on the Internet.</p>

<p>I'd add that a file tends to be the lowest level of abstraction of a container or boundary around data that the Operating System manages.  That is the file's name is accessed through the OS and if you want to know the bits and bytes of data "in" the file you need an Application or program to read/write the file.  The OS "promises" to return the data to any Application in the same order in which the creating Application specified but physically the OS may scatter the data to the wind - as long as the OS can return the data properly to some Application.</p>

CC BY-SA 4.0
2019-04-20T22:45:26.473Z
Right, the OS exists basically to manage files and launch programs.
Scott Rowe
CC BY-SA 4.0
2019-04-20T20:55:55.303Z
2019-04-20T20:55:55.303Z
Tommy131313
<p>A file is a <strong>metaphor</strong>, representing a <strong>mental model</strong> that would be familiar to office workers who were the initial users of computing systems.</p>
<p>Different users in a different context require different metaphors as they have different mental models.</p>

CC BY-SA 4.0
2021-10-01T10:07:25.113Z
This is by far the best answer, cutting through all the detail to the real issue: files don't actually exist. (Folders doubly so.) No one has seen one at any time, they are a made up idea in a made up system in... a made up world. Until someone gets it that we invented everything except gravity and the integers, they will not see the way in which this question could even arise.
Scott Rowe
CC BY-SA 4.0
2021-10-01T10:10:37.847Z
Wasn't it Pascal who said something like: *Geometry is not 'true', it is convenient.*
Scott Rowe
CC BY-SA 4.0
2021-09-24T18:20:06.900Z
2021-09-24T18:20:06.900Z
Maui Mind Academy
<p>A slightly different but insightful take on this :-</p>

<p>On UNIX systems everything is a file. A file of data is a datafile but a directory (folder) is also a file. A device is a file (found in the /dev directory). Programs are executable files and even running program and system states have associated files (found in /run). Network connections are files that can be read and written. </p>

<p>I suppose that explains why its difficult to define what a file is. In a physical sense it is just a list of connected disk or tape or memory sectors containing codes for data values.</p>

CC BY-SA 4.0
2019-05-08T21:34:15.160Z
2019-05-08T21:34:15.160Z
Jon Guiton
<p>I'd actually answer this question from an <em>Intro</em> student from more of the <strong>HCI perspective</strong>, because they likely have more experience <em>using</em> a computer than understanding how the computer works. @MichelBillaud had a similar notion in suggesting it as an abstraction (although most intro students won't fully appreciate what abstraction means the point of asking what a file is). <strong>Relating the abstraction to what they already understand in the physical world helps establish a good foundation.</strong></p>

<p>I'd start by explaining that the first personal computers with graphical interfaces (<a href="https://en.wikipedia.org/wiki/Xerox_Star" rel="nofollow noreferrer">Xerox Star</a> if they want a historical context) faced the challenge of making it easy for someone who works in an office learn how to work with a computer, which stores information digitally instead of on paper.</p>

<p>In an office, they might have records of a client's information that they'd traditionally write on a piece of paper and store it away in a file cabinet. That <strong>file is a record of related information that you can look up by a name</strong>. That metaphor works for computers. They store information electronically instead of on paper, but that <strong>digital record is organized in one place and can be looked up by the file name</strong>.</p>

<p>From there, you can build upon that fundamental to explain different file formats (e.g. plain text vs binary) or how the metaphor extends to other abstractions of digital data represented in ways people can relate to in the physical world (e.g. folders, storage, copying/moving and recycle/trash, to <a href="https://en.wikipedia.org/wiki/WIMP_(computing)" rel="nofollow noreferrer">other WIMP metaphors</a>.</p>

CC BY-SA 4.0
2021-10-01T09:59:04.967Z
Great explanation! Now we just need to re-base it to a world where people never used paper files, folders, desks, offices... What does "a record of clients information" mean to someone who has not used paper for that, or really know what a client is? Children truly face a crazy learning situation, and they always have, but now things have changed so much in one lifetime that our teaching is way behind. How do we get ahead of their already lived experience in order to show them where things are going? I bet we can't. So we have to explain clearly where things came from and hope for the best.
Scott Rowe
CC BY-SA 4.0
2019-05-08T22:43:03.917Z
2019-05-08T22:43:03.917Z
Kevin Buffardi
<p>The question is actually quite deep. For instance, I'm sure you've heard the phrase "<a href="https://en.wikipedia.org/wiki/Everything_is_a_file" rel="noreferrer">everything is a file</a>," that is associated with a design of Unix operating system. So, the answer could be puzzling "a file is almost everything in Unix," for example devices can "look like" files to some processes. They use a file as a common interface between many processes. Hence, the file is quite a general notion of a sequence of bytes in Unix.</p>

<p>My simple answer would be that a file is a sequence of bytes with a reference to them, by which you can access these bytes.</p>

CC BY-SA 4.0
2019-04-22T01:57:39.047Z
2019-04-22T01:57:39.047Z
Aksakal almost surely binary
<p>I think in this case a short answer is better than a long one, which is harder, but I might give it a shot:</p>
<blockquote>
<p>A file is a list of bytes and an identifier [location].</p>
</blockquote>
<p>Make sure to explain that there are no physical files and the term is just an abstraction.
With my definition you can explain the following:</p>
<ul>
<li>If you create a new file with a different identifier but the same bytes, it is a copy of the file.</li>
<li>If you just change the identifier [location], you say the file moves.</li>
<li>If you keep the identifier but change the bytes, the file is said to change.</li>
</ul>
<p>The identifier can be different - e.g. a filename (&quot;C:\Desktop\MyFile.txt&quot;) or a URL (&quot;https://www.mydomain.edu/MyFile.txt&quot;) - but the content is basically always a list of 0 to many bytes.</p>
<p>You could go into details how files are stored and how HTTP works, but in the end you only need to explain the abstraction to understand what &quot;file&quot; means.</p>

CC BY-SA 4.0
2021-09-13T04:06:05.850Z
Nice answer (the best I can see) : **A list of bytes...**
Rushi
CC BY-SA 4.0
2019-04-28T10:16:53.727Z
2021-09-25T20:32:03.720Z
2021-09-25T20:32:03.720Z
Helena
<p>I would approach this pragmatically, beginning with the metaphor that kicked it off.  I would tell the students something like this:</p>

<p>Imagine that it's 1925, and you're working at a giant company like General Electric as a secretary.  There are files, meaning pieces of paper, for all kinds of things. Personnel files about employees, files of record for payments, files of company policies, board meetings, tax documents, you make it.  There are hundreds of rooms holding thousands of file cabinets holding millions of files in hanging folders.</p>

<p>So the metaphor of a file, then, is a document with some information about something.  And the metaphor for the folder is as a place to store those files.</p>

<p>We also call these folders "directories", another metaphor.  A "directory" is from the same etmological root as direction, and it means "to guide".  So, folders can be thought of as places where files sit, or can be thought of as a guide to where files are.</p>

<p>But translating that idea to the very alien mind of a computer involves some tweaks.  First there's the idea that folders can contain folders, which can contain more folders still.  This is incredibly convenient, and using the same metaphor as "directory", we call the list of folders and subfolders and subfolders that bring us to a particular file as a "path".  Get it?</p>

<p>As for the files themselves, there are two perspectives to think about this.  Again, the metaphor is there, but it breaks apart a bit in translation:</p>

<p>The first is from the file system, which is concerned with being able to store and retrieve these files.  As far as the file system is concerned, a file is a size and a series of locations as to where the various parts of the file are stored.  This is because the files don't have to be contiguous inside the computer.  It doesn't actually matter if the first half is stored over here in the hard drive and the second half is stored somewhere else, since the file system will retrieve it for us as if it were one document anyway.  The file system just has to keep track of everything so that the files can be assembled properly when they are needed.</p>

<p>The second perspective is the perspective of a file itself, which is really just some way to store some data, after all.  So far, that's just like a file in our big office.  But our files can store so many different kinds of data! We aren't just storing readable text.  We can store pictures.  We can store sounds.  We can store runnable code.  All of these require very different internal organizations, so the contents of files are extremely variable.  </p>

<p>Many files begin with some sort of metadata.  "Hey, I'm a picture, and this is my encoding and my color depth and my size and and and and...".  Some files depend on the file system to just remember what kind of files they are.  Every file is designed to be read by programs or by the computer itself, and is highly organized to make this possible.</p>

<p>So, a "file" means different things in different contexts, and the only overriding idea is that a file is a way to group data together.</p>

CC BY-SA 4.0
2019-04-22T11:26:33.993Z
Everything in computing is either a container or something that goes in a container. Because everything in our minds is either a concept, or an instance of a concept. The hardest thing is coming up with so many names for stuff that never did exist in the first place. (And cache invalidation - the failure of a name.)
Scott Rowe
CC BY-SA 4.0
2021-10-29T15:18:18.477Z
this explanation gives the impression that a path leads to a file, which is incorrect. The file name is part of the path.
linuxUser123
CC BY-SA 4.0
2019-04-21T18:05:55.477Z
2019-04-21T18:05:55.477Z
Ben I.
<p>"File" is an abstraction. Even worse, we use it for different abstractions.</p>

<p>Well, suppose I copy a file to this site, and you download it. Would you say it is the <em>same file</em>?  What do you mean by <em>same</em>?</p>

<p>Actually, we'll have, more or less, parts of our hard disks (or is it a floppy?) containing bytes which we understand (through the magic of operating systems) as a representation of the same informations.</p>

CC BY-SA 4.0
2019-04-20T17:35:23.347Z
Hard disks are being replaced by solid state 'drives'. (What exactly is driving or driven? Even the words are abstracted away to absurdity.) And much of what we do is "in the cloud" now, so even talking about your computer doesn't apply anymore.
Scott Rowe
CC BY-SA 4.0
2019-04-21T12:38:19.503Z
My not so abstract computer actually has a hard disk, so it does
Michel Billaud
CC BY-SA 4.0
2019-04-21T13:41:33.123Z
Hey, I have a dial telephone sitting on a shelf, but nothing to plug it in to. Give it a few years, then computers will no longer even have screens or keyboards, because most of what we need can be done with voice, as a million years of evolution sans reading has demonstrated. It is being done with voice, and increasingly will be. The question "what is a file?" will no longer have any referent, or anything to prompt it. Files and screens were a temporary phase, like telephone dials and switchboard operators.
Scott Rowe
CC BY-SA 4.0
2019-04-20T14:04:12.530Z
2019-04-20T15:50:51.753Z
2019-04-20T15:50:51.753Z
Michel Billaud
<p>I recently had a student in my Intro to CS class ask me: what is a file? I can't honestly say I had a good answer for him. Those of us who have been around a while <em>know</em> what a file is, but I was at a bit of a loss to explain it to a novice.</p>

<p>Today's students believe (and rightfully so) that a file is an icon-thingy in a folder or on the Desktop. They have some vague idea that there are files for images (JPEG, GIF, PSD, etc.), files for music (MP3, WAV), files for doing office stuff (docx, pptx, etc.), and maybe even HTML files. But they don't know what's <em>in</em> a file. That's where I kind of stumbled around for a few minutes because I didn't have a good answer prepared, nor a really good demonstration.</p>

<p>Looking back, I think I might have shown him what a text file looks like using a hex editor. Maybe also a simple image format such as PBM or BMP. I searched around on YouTube for a good video, but found pretty much nothing.</p>

<p>If you've been asked this question before, what's your answer? What <em>is</em> a file?</p>

CC BY-SA 4.0
2019-04-20T07:22:49.607Z
Long answer later, if a better one don't show up sooner. To answer the question, next time, just grab a file, or folder, out of your desk and show them a "file." English, German, binary, hex, or Martian, is merely the "encoding."
Gypsy Spellweaver
CC BY-SA 4.0
2019-04-20T12:51:34.827Z
I upvoted the question when you said Hex Editor. Great start!
Scott Rowe
CC BY-SA 4.0
2019-04-20T22:44:05.750Z
Related question? --  https://cseducators.stackexchange.com/questions/3535/introducing-file-systems-to-students-who-really-dont-understand
Scott Rowe
CC BY-SA 4.0
2021-09-12T15:13:10.467Z
Necessary viewing for ppl who chant **Everything is a file in *nix** https://youtu.be/9-IWMbJXoLM and don't recognize that that is part of the problem not the solution!
Rushi
CC BY-SA 4.0
2022-01-27T04:30:50.767Z
Files are what file systems manage. File systems have state & operators. Operators suggest certain abstractions for what a "file" is. And the documentation explains the abstraction.
philipxy
CC BY-SA 4.0
2022-04-28T20:22:05.550Z
(This question has been linked to from an article in The Verge: https://www.theverge.com/22684730/students-file-folder-directory-structure-education-gen-z )
Michael Scott Asato Cuthbert
<operating-systems><file-system>
What is a file?
# What is a file?

(Asked by: username_0 on 2019-04-20)

I recently had a student in my Intro to CS class ask me: what is a file? I can't honestly say I had a good answer for him. Those of us who have been around a while *know* what a file is, but I was at a bit of a loss to explain it to a novice.

Today's students believe (and rightfully so) that a file is an icon-thingy in a folder or on the Desktop. They have some vague idea that there are files for images (JPEG, GIF, PSD, etc.), files for music (MP3, WAV), files for doing office stuff (docx, pptx, etc.), and maybe even HTML files. But they don't know what's *in* a file. That's where I kind of stumbled around for a few minutes because I didn't have a good answer prepared, nor a really good demonstration.

Looking back, I think I might have shown him what a text file looks like using a hex editor. Maybe also a simple image format such as PBM or BMP. I searched around on YouTube for a good video, but found pretty much nothing.

If you've been asked this question before, what's your answer? What *is* a file?

**Tags:** operating-systems, file-system

> **Comments:**
> **username_1**: Long answer later, if a better one don't show up sooner. To answer the question, next time, just grab a file, or folder, out of your desk and show them a "file." English, German, binary, hex, or Martian, is merely the "encoding."  
> **username_2**: I upvoted the question when you said Hex Editor. Great start!  
> **username_2**: Related question? --  https://cseducators.stackexchange.com/questions/3535/introducing-file-systems-to-students-who-really-dont-understand  
> **username_3**: Necessary viewing for ppl who chant **Everything is a file in *nix** https://youtu.be/9-IWMbJXoLM and don't recognize that that is part of the problem not the solution!  
> **username_4**: Files are what file systems manage. File systems have state & operators. Operators suggest certain abstractions for what a "file" is. And the documentation explains the abstraction.  
> **username_5**: (This question has been linked to from an article in The Verge: https://www.theverge.com/22684730/students-file-folder-directory-structure-education-gen-z )  

---

## 10 answers

### Answer by username_15 on 2019-04-21. Score: 8

I would approach this pragmatically, beginning with the metaphor that kicked it off. I would tell the students something like this:

Imagine that it's 1925, and you're working at a giant company like General Electric as a secretary. There are files, meaning pieces of paper, for all kinds of things. Personnel files about employees, files of record for payments, files of company policies, board meetings, tax documents, you make it. There are hundreds of rooms holding thousands of file cabinets holding millions of files in hanging folders.

So the metaphor of a file, then, is a document with some information about something. And the metaphor for the folder is as a place to store those files.

We also call these folders "directories", another metaphor. A "directory" is from the same etmological root as direction, and it means "to guide". So, folders can be thought of as places where files sit, or can be thought of as a guide to where files are.

But translating that idea to the very alien mind of a computer involves some tweaks. First there's the idea that folders can contain folders, which can contain more folders still. This is incredibly convenient, and using the same metaphor as "directory", we call the list of folders and subfolders and subfolders that bring us to a particular file as a "path". Get it?

As for the files themselves, there are two perspectives to think about this. Again, the metaphor is there, but it breaks apart a bit in translation:

The first is from the file system, which is concerned with being able to store and retrieve these files. As far as the file system is concerned, a file is a size and a series of locations as to where the various parts of the file are stored. This is because the files don't have to be contiguous inside the computer. It doesn't actually matter if the first half is stored over here in the hard drive and the second half is stored somewhere else, since the file system will retrieve it for us as if it were one document anyway. The file system just has to keep track of everything so that the files can be assembled properly when they are needed.

The second perspective is the perspective of a file itself, which is really just some way to store some data, after all. So far, that's just like a file in our big office. But our files can store so many different kinds of data! We aren't just storing readable text. We can store pictures. We can store sounds. We can store runnable code. All of these require very different internal organizations, so the contents of files are extremely variable.

Many files begin with some sort of metadata. "Hey, I'm a picture, and this is my encoding and my color depth and my size and and and and...". Some files depend on the file system to just remember what kind of files they are. Every file is designed to be read by programs or by the computer itself, and is highly organized to make this possible.

So, a "file" means different things in different contexts, and the only overriding idea is that a file is a way to group data together.

> **Comments:**
> **username_2**: Everything in computing is either a container or something that goes in a container. Because everything in our minds is either a concept, or an instance of a concept. The hardest thing is coming up with so many names for stuff that never did exist in the first place. (And cache invalidation - the failure of a name.)  
> **username_9**: this explanation gives the impression that a path leads to a file, which is incorrect. The file name is part of the path.  

---

### Answer by username_7 on 2019-04-22. Score: 6

The question is actually quite deep. For instance, I'm sure you've heard the phrase "[everything is a file](https://en.wikipedia.org/wiki/Everything_is_a_file)," that is associated with a design of Unix operating system. So, the answer could be puzzling "a file is almost everything in Unix," for example devices can "look like" files to some processes. They use a file as a common interface between many processes. Hence, the file is quite a general notion of a sequence of bytes in Unix.

My simple answer would be that a file is a sequence of bytes with a reference to them, by which you can access these bytes.


---

### Answer by username_14 on 2019-04-28. Score: 5

I think in this case a short answer is better than a long one, which is harder, but I might give it a shot:

> A file is a list of bytes and an identifier [location].

Make sure to explain that there are no physical files and the term is just an abstraction.
With my definition you can explain the following:

* If you create a new file with a different identifier but the same bytes, it is a copy of the file.
* If you just change the identifier [location], you say the file moves.
* If you keep the identifier but change the bytes, the file is said to change.

The identifier can be different - e.g. a filename ("C:\Desktop\MyFile.txt") or a URL ("https://www.mydomain.edu/MyFile.txt") - but the content is basically always a list of 0 to many bytes.

You could go into details how files are stored and how HTTP works, but in the end you only need to explain the abstraction to understand what "file" means.

> **Comments:**
> **username_3**: Nice answer (the best I can see) : **A list of bytes...**  

---

### Answer by username_16 on 2019-04-20. Score: 4

"File" is an abstraction. Even worse, we use it for different abstractions.

Well, suppose I copy a file to this site, and you download it. Would you say it is the *same file*? What do you mean by *same*?

Actually, we'll have, more or less, parts of our hard disks (or is it a floppy?) containing bytes which we understand (through the magic of operating systems) as a representation of the same informations.

> **Comments:**
> **username_2**: Hard disks are being replaced by solid state 'drives'. (What exactly is driving or driven? Even the words are abstracted away to absurdity.) And much of what we do is "in the cloud" now, so even talking about your computer doesn't apply anymore.  
> **username_16**: My not so abstract computer actually has a hard disk, so it does  
> **username_2**: Hey, I have a dial telephone sitting on a shelf, but nothing to plug it in to. Give it a few years, then computers will no longer even have screens or keyboards, because most of what we need can be done with voice, as a million years of evolution sans reading has demonstrated. It is being done with voice, and increasingly will be. The question "what is a file?" will no longer have any referent, or anything to prompt it. Files and screens were a temporary phase, like telephone dials and switchboard operators.  

---

### Answer by username_2 on 2019-04-20. Score: 2

Was in a conference the other day and someone was showing intercept security... A .exe file started with MZ. Why? Those are the initials of the man who created the first DOS executable file format. Many kinds of files have 'signatures' in the first few bytes.

I used to use a tool called 'strings' that would show any displayable sequences of characters in an otherwise 'binary' file. Helpful sometimes. We have gotten far away from this level of reality in our everyday use of computers, so it is good to show that there is really no mystery, it is all just a heap of ideas people have had over time, piled up in layers. Start at the bottom with characters and follow the clues.

Attack it in many ways, showing the aspects of 'files' that are meaningful to you. Give some of the history. I am sure you can come up with analogies. One issue is that although 'file' makes some sense, 'folder' does not, because we don't ever nest manila folders! Nnnnt! The other term, 'directory', has fallen in to disuse, and really is not any better.

What is a synonym for what we call folder...? There isn't one! It is a brand new concept, like variables. Nothing else in our world is like that. This is why we have to show that analogies are limited and misleading. You have to actually *know* some things.

> **Comments:**
> **username_2**: And how many of the students have seen a manila folder? A floppy? A dial phone? They have no experience with the things we analogize *from*! Lost beyond lost in a hall of mirrors.  
> **username_6**: Could you explain what you mean by *"lost beyond lost in a hall of mirrors."*?  
> **username_2**: @LogicalBranch Sure. Humans usually make meaning by relating to things in their environment. The floppy disk is the icon for 'store' because they used to be commonplace. But to someone who has never seen one, it doesn't have any inherent meaning. If a student is asking what a file is, it probably means they have no referent, no commonplace objects, situations and processes that they can intuitively substitute. If all of computing is strewn with metaphors and references to never-before-known things, it is basically like going to a foreign planet and trying to start from nothing.  
> **username_2**: Beyond, that, the references seem pointless and strained. Floppies only make sense without an internet. And if your entire life experience is that the internet has always just "been there", how can any other scenario make any sense? If I put you down in the Amazon rainforest and said, "There is lots of food here. Just watch out for the dangerous things." would you be likely to survive even for 2 days, or know what killed you in your sleep? No. This is the world we put our children in to with no preparation, because we cannot see it from their point of view.  
> **username_6**: Thanks for taking the time to explain, I appreciate it.  
> **username_2**: Sure. This is why I keep crying like the little voice in the wilderness: "We have to start with the the basic level of how things *actually work*!" And everyone here says I am wrong. We shall see. Wait... We are seeing now.  
> **username_7**: +1 @ScottRowe, "Just watch out for the dangerous things" - this reminded me of theme in Heinlein's "Tunnel in the Sky": the kids are sent to a remote planet and among other things are told to "watch out for stobor." They weren't told how this *stobor* looks like and what can it do. Interestingly, this seemed to work, but I'm not throwing spoilers here :)  

---

### Answer by username_8 on 2021-10-04. Score: 2

As is the case with most simplified explanation, I have glossed over some more advanced specific details that don't factor into the basics on file systems.
File content
At its most basic level, a file is really just a sequence of ones and zeroes. It's data. There's nothing more to it than that.
This data can then be interpreted. We (or an application) take the ones and zeroes, attribute meaning to them, and this interpretation is informative to us (or an application).
"Interpretation" is the operative keyword here. The same arbitrary sequence of ones and zeroes can be interpreted in any way you want to. However, in most cases only one interpretation will make sense, and other interpretation will look like garbage.
So how do we know which interpretation should be used for which file? Answer: the file extension. A file extension denotes how the data in the file is structured, and therefore how it can be sensically interpreted.
Your OS automates this process for you. Instead of you having to look at the extension and then find the correct application which can interpret your file in the way you need it to be interpreted, your OS automatically maps a given file extension to your preferred application. For example, you might configure Windows to open .txt files with WordPad, or Notepad, or Notepad++, or some application you wrote yourself. All of these application are capable of performing the interpretation that a .txt file needs.
You can override this behavior. You can open a .png file in Notepad. It won't make sense, but what you are seeing is the result of a .txt interpretation being applied to a file whose data structure is that of a .png.
.txt files are very easy to interpret. Ignoring encoding for now (let's assume ASCII), every byte (= 8 bits) of the ones and zeroes represents a single number, which in turn represents a single character.
To really prove the point, you could do this manually. Let's say I want to store a text file containing apple. You can use an ASCII table to look up what the numeric representation of each character is.
a = 01100001
p = 01110000
p = 01110000
l = 01101100
e = 01100101

If you use your text editor of choice, set the encoding to ASCII, enter apple and save the file, the file's ones and zeroes will exactly be the sequence of binary digits I just listed.
.txt is really easy, but file structures can get significantly more complex, to the point where it is no longer feasible for a human to manually interpret all the data. For example, even though a .pdf file might only contain text (to your eyes) just like a .txt, it actually stores a whole lot more data (text markup, file metadata, ...) and this makes it less than obvious to interpret the binary data ourselves.
But to prove the point on how you can interpret files in a non-text example, suppose you (as a teacher) want to track whether your students were present/absent every day of school. Assuming you have 16 students, you could track this using a very simple sequence of 16 binary digits:
1111111111011111

Everyone was present that day, except student 11.
Is this a good file format? Well, it's very efficient. But it also lacks context. There's an assumption on which students were in your class. There's no way to track justified absences, etc. To really cover all the information you need, you're going to need a more complex system. But if you assume a simple present/absent mark for a fixed list of students, the above file format could theoretically suffice.

Interesting experiment
Take an existing Word/Excel file, one with an "x" in the file extension (.docx or .xlsx). Change its file extension to .zip and try to open it. It... works!?
Since the advent of the new Office file formats, Word and Excel documents are really just secret zip archives, not custom binary file formats like they used to be. But by using a unique file extension instead of .zip, people can still configure these .docx or .xlsx files to be automatically opened using Word/Excel instead of however they've configured .zip files to be opened.


File name (and path)
At its most basic level, a file name is just one long string of characters, nothing more.
Obviously, we're likely going to want to store more than one file on our computer. So we need a way to reference each file that we store. This is why we give them a name, to tell them apart. This is no different from why humans give eachother names.
As mentioned before, we add a file extension to the end of the name, so that we remind ourselves (and the OS) of the data structure that was used for the file content.
But we often have a lot of files. We'd really like to organize them properly into little collections, instead of throwing them all on one big messy pile. To do this, we started prepending our filenames with what we call the "path".
A path is nothing more than a (back)slash-separated sequence of names which list the hierarchy of how we'd like to organize our files. The OS will take the file name, split the names into the separate chunks, and will use that hierarchical information to show your files in a neat and organized manner.
Every file's name is really just a combination of:
[folder chunks][name of the file].[file extension]

Take the example of the following file names:
C:\Fruit\apple.txt
C:\People\PeopleILike\Tom.png
C:\Fruit\banana.txt
C:\People\PeopleIHate\Kevin.png

If you split the names in the chunks between the backslashes, you can start seeing the structure. For example, the first and third file have exactly the same chunks before their file name. Therefore, they belong in the same folder. The second and fourth file have a common first chunk, but then they have a different chunk. Therefore, they are found in the same parent directory but then live in a different subdirectory.
If you apply this logic, just like how an OS does, you come up with the intended organisational structure:
C/
├─ Fruit/
│  ├─ apple.txt
│  ├─ banana.txt
├─ People/
│  ├─ PeopleIHate/
│  │  ├─ Kevin.png
│  ├─ PeopleILike/
│  │  ├─ Tom.png

We like to think of our file system as this neat nested system of folders and subfolders. But in the underlying file system, we don't actually store a "folder" by itself. A folder is really just generated dynamically based on the slash-separated chunks found in a file's name.
This leads to some interesting effects:

Want to move a file? All you have to change is the file's path. You don't need to update a folder itself.
Want to rename a folder? Then you're going to need to change this name in all of the files who contain this folder in their path.

This is an oversimplification. File systems are more complicated than this, because you need the ability to e.g. create empty folders. But this is a good first explanation of how the file system works.

File metadata
Next to the file name and content, there's more things we know about the file, such as when it was created, whether it is read-only, any permissions attached to the file, ... These things are not stored in the file content. They are an addendum to the file.
If you transfer a file from one file system to another, this data may be lost if the target system doesn't know how to work with the source system's metadata structure. However, this doesn't matter in terms of using the file itself. Your data is safe. You might just lose track of e.g. when your file was created.

> **Comments:**
> **username_9**: this is incorrect. A name is just the name of a single file or directory. What you describe as name is a path. Also, the name is part of the path.  
> **username_5**: good, but I wouldn't start with "a series of ones and zeros" in the most basic explanation, since there's basically no simple way for students to view files as a series of ones and zeros.  I feel like starting with "a series of letters, numbers, and about 200 other symbols" will let them explore better, and next they can learn that these symbols are representations of ones and zeros.  
> **username_8**: @MichaelScottAsatoCuthbert _"a series of letters, numbers, and about 200 other symbols"_ does not in my opinion adequately cover what a file is, it is one specific way (of countless many) of how a file can be interpreted. Yours is a more concrete example use case of a file and I agree that this helps with understanding the general purpose of a file; which is why my answer pretty much _immediately_ discusses interpretation after stating that a file is a sequence of ones and zeroes; but it is not a good base definition of a file in and of itself.  
> **username_8**: @username_9: The answer builds up the understanding of file names and paths step by step. I refer to the name (i.e. filename) first before then introducing paths which are used to further organizes these files (which up until then only had names, not paths). The wording I used was intentionally chosen to be layman-readable. As mentioned in the final paragraph of that section, my explanation is an oversimplification. This answer favors layman-human-readability over technical pedantry. It should not be used as a technical reference, only as a basic grasp on the components at play.  

---

### Answer by username_10 on 2019-04-20. Score: 2

Nothing wrong with citing all the "dictionary" definitions found on the Internet.

I'd add that a file tends to be the lowest level of abstraction of a container or boundary around data that the Operating System manages. That is the file's name is accessed through the OS and if you want to know the bits and bytes of data "in" the file you need an Application or program to read/write the file. The OS "promises" to return the data to any Application in the same order in which the creating Application specified but physically the OS may scatter the data to the wind - as long as the OS can return the data properly to some Application.

> **Comments:**
> **username_2**: Right, the OS exists basically to manage files and launch programs.  

---

### Answer by username_11 on 2021-09-24. Score: 1

A file is a **metaphor**, representing a **mental model** that would be familiar to office workers who were the initial users of computing systems.

Different users in a different context require different metaphors as they have different mental models.

> **Comments:**
> **username_2**: This is by far the best answer, cutting through all the detail to the real issue: files don't actually exist. (Folders doubly so.) No one has seen one at any time, they are a made up idea in a made up system in... a made up world. Until someone gets it that we invented everything except gravity and the integers, they will not see the way in which this question could even arise.  
> **username_2**: Wasn't it Pascal who said something like: *Geometry is not 'true', it is convenient.*  

---

### Answer by username_12 on 2019-05-08. Score: 1

A slightly different but insightful take on this :-

On UNIX systems everything is a file. A file of data is a datafile but a directory (folder) is also a file. A device is a file (found in the /dev directory). Programs are executable files and even running program and system states have associated files (found in /run). Network connections are files that can be read and written.

I suppose that explains why its difficult to define what a file is. In a physical sense it is just a list of connected disk or tape or memory sectors containing codes for data values.


---

### Answer by username_13 on 2019-05-08. Score: 1

I'd actually answer this question from an *Intro* student from more of the **HCI perspective**, because they likely have more experience *using* a computer than understanding how the computer works. @MichelBillaud had a similar notion in suggesting it as an abstraction (although most intro students won't fully appreciate what abstraction means the point of asking what a file is). **Relating the abstraction to what they already understand in the physical world helps establish a good foundation.**

I'd start by explaining that the first personal computers with graphical interfaces ([Xerox Star](https://en.wikipedia.org/wiki/Xerox_Star) if they want a historical context) faced the challenge of making it easy for someone who works in an office learn how to work with a computer, which stores information digitally instead of on paper.

In an office, they might have records of a client's information that they'd traditionally write on a piece of paper and store it away in a file cabinet. That **file is a record of related information that you can look up by a name**. That metaphor works for computers. They store information electronically instead of on paper, but that **digital record is organized in one place and can be looked up by the file name**.

From there, you can build upon that fundamental to explain different file formats (e.g. plain text vs binary) or how the metaphor extends to other abstractions of digital data represented in ways people can relate to in the physical world (e.g. folders, storage, copying/moving and recycle/trash, to [other WIMP metaphors](https://en.wikipedia.org/wiki/WIMP_(computing)).

> **Comments:**
> **username_2**: Great explanation! Now we just need to re-base it to a world where people never used paper files, folders, desks, offices... What does "a record of clients information" mean to someone who has not used paper for that, or really know what a client is? Children truly face a crazy learning situation, and they always have, but now things have changed so much in one lifetime that our teaching is way behind. How do we get ahead of their already lived experience in order to show them where things are going? I bet we can't. So we have to explain clearly where things came from and hope for the best.  

---

