PortableHole

29Mar/110

Getting Around UNIX Files & Directories

The first thing I ever learned how to do (and wish had been distilled better) was moving around and understanding UNIX file systems from a shell. The precise details of what makes file systems different from each other aren't usually visible to the user, so I will ignore them here. The short version is that most UNIX file systems are the same from the point of view of applications, but they differ on how they accomplish the same goals.

Most file systems use the idea that data is stored in units called files, which are identified abstract blobs with a location. The common identification system for a file is it's path, or location in the file system. Files are organized in a tree structure called directories, which have a root node known as the root directory. Paths are written out by the set of directories that describe their location separated by forward slashes. Example: "/home/pquimby/filename", is the absolute path that describes a file named "filename" in a directory called "pquimby" in a directory called "home" that's in the root directory. The reason it's called an absolute path is because it starts with the root directory ('/') and fully describes how to navigate to the file in question. Keep this in mind for a second, because there is a second way to describe a path that works differently. You can always spot an absolute path because it will start with a forward slash, "/something/else/goes/here".

There is a notion of the "current working directory" when interacting with a file system. The current working directory is the "current" place that "you" (the user or program) uses to interpret relative actions; the current working directory provides a location to start interpreting paths. The second way to describe a path is to start with the current working directory (written with the period character, '.') and describe how to get somewhere from there. For instance, suppose I am in "/home" (by convention we don't write the trailing slash), and I want to reference the file "filename". I can use a relative path that begins in the current working directory and shortens the path to "./pquimby/filename". Sometimes it's common to ignore the leading '.'.

Recap: "Files go in directories. Directories go in directories. Everything goes in '/', known as the root directory."

It turns out that there are a few other things that we need to understand to use paths effectively. Every directory has two special links in them. Links are references to other places in the file system that can be followed, a bit like a wormhole. One link that's in every directory is the link to itself, called '.'  (which explains what the leading period means in relative paths). Another link that's in every directory is '..' , which refers to the parent directory (the one that contains it). These two links can be useful in relative navigation. Suppose I am in "/home/pquimby/dir1" and I want to refer to "/home/pquimby/dir2/temp". The relative path will be "../folder2/temp". You can do this multiple times: "../../.." means "go up three directories".

So... how does any of this matter to me? Well, you can use a few commands to navigate and view your files from the shell:

  • pwd shows you your current working directory.
  • ls [optional path] (Example: "ls /home/pquimby") shows you what's in the current working directory if you don't specify a path or shows you what's at a path if one is given.
  • cd [optional path] (Example: "cd pquimby/dir1") changes your current working directory to the relative path after it (in this case "/home/pquimby/dir1").
  • mkdir [optional path] (Example: "mkdir dir3") makes a new directory in the current working directory.

If you want to know more, try looking at the manual page, "man [program name]". If you're new to UNIX, the result may just look like total gibberish... but I assure you it's actually (mostly) useful. just remember that "return" scrolls down and "q" exits the manual page.

Filed under: Uncategorized No Comments
28Mar/110

The End Has Not Yet Been Written

This entry is intended to be a live document that lists some things I haven't written about or want to write more about:

UNIX:

  • Files, directories, links, and navigation. [pwd, cd, ls, ln]
  • Packages & package management [apt-get]
  • UNIX root directory layout
  • Users, Permissions, and ACLs
Filed under: Uncategorized No Comments
27Mar/110

Hello, World!

Every once in a while I find myself wishing that something had been explained to me the way I wanted it explained. This blog is an experiment in seeing what happens if I have a public way to express my outrage at the world's explanations that just don't go with my way of thinking.

Please feel free to contact me about anything I say here, and most importantly, correct me when I'm wrong. I have high standards for anything I put on the Internet, so please express your opinions when you have something useful to say about my content.

Filed under: Uncategorized No Comments