A File System basically refers to the organizational scheme every OS (Operating System) uses to organize and manage your files in its storage.
By storage I mean whatever your system is using to store files permanently, whether that is a hard drive or solid state memory.
Although most modern OSs use a GUI (Graphical User Interface), where the mouse and/or trackpad are the stars, let's not loose site of the fact that underneath that shinny veneer sits a good old command driven shell.
The purpose of the shell, whether PS (PowerShell) or Command Prompt on Windows, or the Terminal on a Mac or Unix box, is to interact with the OS via commands.
Often, you are required to use applications or utilities that require you to run a command in the OS's shell, and here is where knowing a bit about the shell becomes useful.
Ok, so you know you need to type a command in the shell, but how to you get one?
Let's take a look then.
A Mac user must open a Terminal, which is an application in the /Applications/Utilities
folder. Here opening simply means to run the app.
A Windows user can open an older command prompt by typing cmd
in the search field and clicking the user or administrator version of the app.
Alternatively a user can open a Power Shell by typing powershell
instead of cmd
. The power shell is more of a Unix-like shell and makes both interactions (Mac and Win) consistent. Be brave and try it out.
First thing to notice is the prompt. It tells you a number of things, but at this stage I am interested in the directory the shell is using as the current or more appropriately the working directory. It so happens that both the Mac and Win shells will place you in your home directory by default.
Note: On Windows 10, version 2004, you can further install a Linux subsystem that will give you a unix-like interface. Run PS as an administrator and then at the prompt enter wsl --install
and press enter. That's it.
By the way, directory is the proper nomenclature for a folder. Folder being the fuzzy name used in the GUI.
On a Mac that is the funny looking ~
symbol, called the tilde. It is simply a shortcut mapping to the actual home directory. To find out exactly which directory you are in, use pwd
for Print Working Directory.
As we can see my working directory is /Users/stornarSIUE
.
On a Win PC it is C:\Users\ctornar
as evident in both the command prompt and the PowerShell window.
Things you might wonder how to do at some point are:
ls
command, for list. If you are in the Win camp and using the command prompt, then use dir
instead.The ls
command lists the contents of the directory, which may include files and other directories. The root directory on a Mac is the /
, whereas on a Win it is the C:\
.
cd
command.To change to another directory you need to know where you are and where you want to go of course. Depending on the relationship of the current and destination directories, you may use a relative or absolute path to get there.
An absolute path starts from the root directory and drills down each level until you end up at the destination directory. A relative path begins in the current directory and navigates up and/or down to the destination directory.
To move down a level simply use the directory name directly:
The ls
command shows a number of child directories - notice the /
suffix. To change to the Applications
directory, a child directory of the stornarSIUE
directory, I used cd
with a relative path:
cd Applications
Notice how the prompt now indicates the working directory as ~/Applications
.
The same result using an absolute path:
When using an absolute path you must begin with the root directory and navigate down each level until you reach the destination directory.
Depending where you are in the overall file system tree, one path approach will be more appropriate than the other.
Now, to move up using a relative path you use the shortcut for the parent directory which is ..
, namely two dots. A single dot, .
represents the current or as we saw earlier, the working directory.
Let's move back up to the home directory from the Applications
directory.
The prompt and the pwd
command both verify we are back home.
The home directory can be changed to from anywhere on the tree by simply typing cd
and pressing the enter
key. If not path is given it defaults to the home directory.
Although the shell is very powerful in creating, removing directories as well as changing directories, you may find that using the GUI (Finder, Windows Explorer) in tandem can be a more powerful combination.
Basically, create/remove folders (directories) using the GUI. Most of you are familiar with that as it is anyway.
If you need to change directories so you may run a command from there, or save a file from some command, or for whatever other reason, then you have two options:
Both options require you to open a shell window first of course.
cd
command as we saw above and navigate to the destination. You may even refer to the GUI file system to see the tree structure in case you don't remember all the directories you can to list in the command.cd
followed by a space.enter
. Voila. You have changed directories.The goal here is not to abandon the GUI interface, but rather to expose you to some useful CLI commands you can use to interact with your corresponding shell.
To create a directory named sub1 use:
mkdir sub1
To create a directory named sub2 by creating the directory sub1 along its path use:
mkdir -p sub1/sub2
To remove an empty directory named sub1 use:
rmdir sub1
To remove a non-empty directory named sub1 use:
rm -R sub1