Operating systems like Windows and macOS have spent the last 25 years trying to hide the filesystem from the average user as much as possible. Maybe you, too, have muddled through earlier courses with only a vague idea of what it is. (I think they try to teach this in one of the early courses (Big Ideas??) but I still get students who are confused about this stuff, so.)
You are no longer an average user and it’s time for you to to learn how the filesystem works. You have to. The filesystem is a foundational underlying concept in most software and you have to learn what it is, how it’s shaped, what filenames are, and what extensions are.
1. Enable file extension display
- Windows users:
- open an Explorer window (a folder view)
- in the toolbar, open View > Show and check File name extensions
- macOS users:
- open a Finder window (a folder view)
- in the menu bar at the top of the screen, go to Finder > Preferences (or just ⌘+, (yes command-comma))
- under Advanced, check Show all filename extensions
- Linux users:
- you know what file extensions are and you probably already have them turned on.
Now try going to your Documents or Downloads folders. See the extensions on all the filenames? Stuff like .pptx
, .c
, .java
, .docx
, .jpg
, etc. etc. etc. There they are!
2. What are filenames? (And what aren’t they?)
Every file on your computer has a name. The name is just a string. The file’s name is entirely for our benefit - it mostly means nothing to the computer.
The extension is the last part of the file’s name: the period and the characters after it. The extension is a hint about what kind of data is contained within the file. This is one of the ways operating systems decide what icon to use for that file and what program to run when you open that file. A .docx
file opens in Word, an .html
file opens in your browser, and so on.
Bags of corn, marked “onions.”
However, the file’s name (including the extension) has no connection to the file’s contents (the kind of data that is actually inside it). It is entirely possible to put the “wrong extension” on a file, but doing so is no different than putting a bunch of corn in a bag and labeling it “onions”. Like the picture over there.
This is why they hide file extensions from you by default: because before they did that, so many people mistakenly changed or removed the file extensions when they tried to rename files, causing the OS to think it was a different type of file altogether.
This means that you cannot “convert” a file from one type to another by just changing its extension! Changing image.jpeg
to image.png
does not convert it to a PNG! It’s just a JPEG wearing a nametag that says “hello, yes, I am a PNG!”
Well there is one exception: plain text files.
.java
,.c
,.py
etc. source code files are all plain text files, and so is.txt
.
But now you know better. And you need to see the extensions because those are part of the filenames! When you want to access the filesystem from a programming language, you have to include the file extensions. Your file is not named “English Paper 1”, it’s named “English Paper 1.docx”.
3. Viewing the structure
Many people never really see the filesystem structure, and instead see “Recent files” or “Recents” and use the search feature to find their files. This is a shame, because that is a really, really messy way to organize things, and the filesystem has a really nice structure built in.
The filesystem is shaped like a tree. The base of the tree is the root directory. Inside that are other directories, which can contain more directories and files, and so on. (“Directory” and “folder” mean the same thing.)
Viewing the filesystem on Windows
- Hit Win+R. This opens the “Run” box. (this is extremely old-school and still works!)
- In the box, type
C:\
and hit enter.C:\
is the root directory.
- Do View > Details.
Now you can double-click folders to go inside them and see their contents. You can use the ⬆️ up-arrow button in the toolbar to go up a level to the enclosing directory. Users
contains your user directory. Inside that is where your Desktop
, Documents
, etc. are stored. The stuff sitting on your desktop is really just sitting in that Desktop
folder.
Viewing the filesystem on macOS
- In Finder, do Go > Computer.
- Open “Macintosh HD”. Or whatever it’s called. (the one without “- Data” on it.)
- This is the root directory.
- Do View > as List.
You can click the arrows next to the folders to expand them and see their contents. Users
contains your user directory. Inside that is where your Desktop
, Documents
, etc. are stored. The stuff sitting on your desktop is really just sitting in that Desktop
folder.
Viewing the filesystem on Linux
You aren’t even reading this! lol
4. Viewing the structure from the shell/command line/terminal
You may be used to viewing your files in a graphical way, but the filesystem is just a data structure. It can be viewed in many ways. When you use the shell (command line, terminal, whatever you wanna call it), you are viewing the same filesystem in a textual way.
Navigating the filesystem on the Windows command line
- Hit Win+R, type
cmd
, hit enter. (or hit Win to bring up the start menu, typecmd
, hit enter.) - This opens the command line. The prompt looks like
C:\Users\yourusername >
. That’s the directory that you are currently working in, known as the current working directory. (Amazing.) - You can list the contents of the current directory with the
dir
command. - You can change directories with the
cd
command:cd Desktop
would take you into the desktop directory. You can thendir
to see the files.cd ..
goes up a directory.cd %HOMEPATH%
goes to your home directory. (The one that containsDesktop
etc.)
Navigating the filesystem in the macOS Terminal (and Linux!)
- Hit ⌘+Space. This brings up spotlight. Type
term
, andTerminal.app
should show up. Hit enter.- (Linux users do something else)
- This opens the Terminal app. I think the prompt looks like
computername:~ username $
The~
is actually the directory name, sort of.~
is shorthand for your home directory. - You can list the contents of the current directory with the
ls
command. - You can see the actual directory you are in with the
pwd
(print working directory) command. - You can change directories with the
cd
command:cd Desktop
would take you into the desktop directory. You can thenls
to see the files.cd ..
goes up a directory.cd ~
goes to your home directory. (The one that containsDesktop
etc.)
5. What about cloud storage?
Cloud storage, like Apple iCloud, Microsoft OneDrive, Google Drive, DropBox, Box, etc. is a marketing term. They all work mostly the same way:
- they store copies of your files on their computers; and
- they put some app on your computer that makes it look like those files are on your computer.
That app is clever and automatically downloads and uploads files to their computers, so that to you, it seems like the files are “on” your computer and “on” other devices, magically. Sometimes they also do really weird shenanigans like on Windows where you have, like, two Things named “Documents” and one of them is a real folder and one of them is a fake folder that actually uses OneDrive and it’s super confusing and man they could have implemented that better
“Copying files between computers” is not a new idea. It’s literally why the internet was created in the first place. And there are many ways of doing it, even without big corporations. And that’s what you’ll learn about in lab 1!