Navigating Disk Storage

Before we program, we need to first get us familiar with how and where computer stores programs, so we know what program is available and more importantly, where to find and show off the program that we are going to write.

We know computer has disk somewhere inside, that’s where all data storage happens. We store different sorts of data in the name of ‘file’, the document we write is a file, the picture we draw is a file, the game we download there might have more than one file, and the Operating system itself has a ton of different files. Of course, the program we are going to write is also a file.

A file is a collection of ‘bytes”, where ‘byte’ is the minimal storage unit. So the more ‘bytes’ available in the disk, the more storage space we have. When we say we have a disk of 100GB, we have a disk that has 100 Giga Bytes. One ‘Giga Byte’ has 1,000,000,000 bytes, or rather 1,073,741,824 bytes in computer term. We’ll explain this once we learn the difference between decimal and binary.

We have a big disk that can store lots of files, in order for us to tell which file is which, we need to give each file a unique name. That seems easy, we can simply name each file by a number, say file1, file2, file9999 etc. Right?

The only problem of that approach is we will have lots of magic files that we don’t know what they are for. Hmmm, what is file3789 for again?

Instead, we, or rather Operating System, manage files like a tree. There’s one and only one ‘root’, then there are ‘branches’ above root, there can be more ‘sub-branches’ above any branch, eventually there is ‘leaf’. We call branch as ‘directory’, thus ‘sub-branch’ is ‘sub-directory’, and the ‘leaf’ is our ‘file’.

We can then give each directory/sub-directory and file a unique name, to help us remember which is which. This way, anywhere in the tree, we can climb to find any ‘leaf’, the ‘file’ we want. Any file will be stored at given directory, which can be a sub-directory of other directory. We call this chain of directories that leads to a given file the ‘path’, since this is the ‘path’ we climb in order to find this file.

For example,


So we first climb to ‘user’ branch, then ‘frank’ sub-branch, then ‘games’ sub-branch and so on, eventually we get to the ‘score’ file, this is probably where Frank keeps his pvz2 game score. :-)

This sounds all familiar, yes, this is what the Windows ‘file explorer’ does. When clicking to expand a ‘directory’, we actually climb onto it. When collapsing it, we climb back to its parent ‘directory’. File explorer exists in Linux as well, but we instead will introduce the navigating methods when we are in a command terminal, since that’s also where we learn to run the program we write etc.

It is actually quite simple to navigate directory tree, by knowing only the following two commands and one special case,

1. Command #1: cd

‘cd’ command is used to Change directory. ‘cd <directory-name>’ will navigate from current directory to new directory specified by <directory-name>.

2. Command #2 : ls

‘ls’ command is used to list contents of current directory.

3. Parent directory: ..

‘..’ is a special name for parent directory. For example, ‘cd ..’  will leave current directory and go to its parent directory.

That is all you need to know to navigate directory tree, now open a terminal (by holding CTRL + ALT, and letter ‘t’), and try them out …

‘ls’ command also takes options. Option is additional typing to further change the ‘ls’ command behaviour. For example, ‘ls -a’, will show all contents of current directory, this will show all hidden files as well, if any is available.

It is important to know that most commands come with ‘user manual’ installed. Any time, ‘man <command>’, will print the manual for given <command>. For example, ‘man ls’ will print the detailed user manual for ‘ls’ command. To learn more on any command, simple ‘man <command-name>’. This is most of the time more convenient than asking our Google friend.

Now, try ‘man man’, yes, you guessed it, this will print the user manual for ‘man’ command itself.

With ‘cd’ and ‘ls’, we now are able to navigate the disk, next we’ll try to actually create a file and make sure we can find it as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">