diff --git a/lessons/swc-shell/shell-overview.ipynb b/lessons/swc-shell/shell-overview.ipynb index 53227493a..f2aed6e21 100644 --- a/lessons/swc-shell/shell-overview.ipynb +++ b/lessons/swc-shell/shell-overview.ipynb @@ -11,7 +11,24 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# The Unix Shell" + "# The Unix Shell: Files and Directories" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Students should be able to:\n", + "\n", + "- Describe the parts of a file-system\n", + "- Explain the difference between a relative and absolute path.\n", + "- Construct absolute and relative paths that identify specific files\n", + " and directories.\n", + "- Identify the actual command, flags, and filenames in a command-line\n", + " call.\n", + "- Demonstrate the use of tab completion, and explain its advantages.\n", + "\n", + "**Duration**: 15 minutes (longer if people have trouble getting an editor to work)." ] }, { @@ -60,121 +77,625 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## For Instructors\n", + "## Lesson\n", + "\n", + "The [file system](glossary.html#file-system) is the part of your operating system \n", + "responsible for managing files and directories.\n", + "This may sound obscure, but the UNIX shell just uses different names for \n", + "things you already know: \n", + "\n", + "Imagine you are away from your main computer, and suddenly realize you need\n", + "an important excel spreadsheet. So you call back to your lab, and direct someone\n", + "to email you the excel document. What do you tell them? It's probably something like:\n", + "\n", + " \"Double click on the \"Work_Stuff\" folder on my desktop, then choose the \"Project_1\" \n", + " folder, then click the \"datasheets\" folder, and my excel sheet is in there, \n", + " it's called \"super_important.xlsx\"\"\n", "\n", - "Many people have questioned whether we should still teach the shell.\n", - "After all, anyone who wants to rename several thousand data files can\n", - "easily do so interactively in the Python interpreter, and anyone who's\n", - "doing serious data analysis is probably going to do most of their work\n", - "inside the IPython Notebook or R Studio. So why teach the shell?\n", + "The folders and documents you've just described are what the UNIX shell calls\n", + "'directories' and 'files' respectivly, and the collection of all of them is \n", + "your 'file system'. The series of pointing and clicking you gave your coworker \n", + "also has a name: the 'path', your words led them down the path to your file. \n", "\n", - "The first answer is, \"Because so much else depends on it.\" Installing\n", - "software, configuring your default editor, and controlling remote\n", - "machines frequently assume a basic familiarity with the shell, and with\n", - "related ideas like standard input and output. Many tools also use its\n", - "terminology (for example, the `%ls` and `%cd` magic commands in\n", - "IPython).\n", + "Now imagine that instead of pointing and clicking, and searching for the right \n", + "folder on your desktop, you could just dictate this path to your computer directly. \n", + "It turns out you can! To give your computer a path, you replace all the clicking with slashes:\n", "\n", - "The second answer is, \"Because it's an easy way to introduce some\n", - "fundamental ideas about how to use computers.\" As we teach people how to\n", - "use the Unix shell, we teach them that they should get the computer to\n", - "repeat things (via tab completion, `!` followed by a command number, and\n", - "`for` loops) rather than repeating things themselves. We also teach them\n", - "to take things they've discovered they do frequently and save them for\n", - "later re-use (via shell scripts), to give things sensible names, and to\n", - "write a little bit of documentation (like comment at the top of shell\n", - "scripts) to make their future selves' lives better.\n", + " Desktop/Work_Stuff/Project_1/datasheets/super_important.xlsx\n", "\n", - "Finally, and perhaps most importantly, teaching people the shell lets us\n", - "teach them to think about programming in terms of function composition.\n", - "In the case of the shell, this takes the form of pipelines rather than\n", - "nested function calls, but the core idea of \"small pieces, loosely\n", - "joined\" is the same.\n", + "This particular path is called a 'relative path' because it begins in an arbitrary place: \n", + "your co-worker had to start from your desktop to follow the instructions. \n", "\n", - "All of this material can be covered in three hours as long as learners\n", - "using Windows do not run into roadblocks such as:\n", + "Instead, you could also use the 'absolute path':\n", "\n", - "- not being able to figure out where their home directory is\n", - " (particularly if they're using Cygwin);\n", - "- not being able to run a plain text editor; and\n", - "- the shell refusing to run scripts that include DOS line endings.\n", + " /users/Amanda/Desktop/Work_Stuff/Project_1/datasheets/super_important.xlsx\n", "\n", - "Here are some ways to approach this material:\n", + "This path is 'absolute' because it always starts from the same place: your 'root directory'.\n", + "Root is the top directory in your computer, everything else: every other file and directory\n", + "is stored inside of it. The UNIX shell refers to root as simply '/'. It's the very first thing in \n", + "the absolute path above.\n", "\n", - "- Have learners open a shell and then do `whoami`, `pwd`, and `ls`.\n", - " Then have them create a directory called `bootcamp` and `cd` into\n", - " it, so that everything else they do during the lesson is unlikely to\n", - " harm whatever files they already have.\n", - "- Get them to run an editor and save a file in their `bootcamp`\n", - " directory as early as possible. Doing this is usually the biggest\n", - " stumbling block during the entire lesson: many will try to run the\n", - " same editor as the instructor (which may leave them trapped in the\n", - " awful nether hell that is Vim), or will not know how to navigate to\n", - " the right directory to save their file, or will run a word processor\n", - " rather than a plain text editor. The quickest way past these\n", - " problems is to have more knowledgeable learners help those who need\n", - " it.\n", - "- Tab completion sounds like a small thing: it isn't. Re-running old\n", - " commands using `!123` or `!wc` isn't a small thing either, and\n", - " neither are wildcard expansion and `for` loops. Each one is an\n", - " opportunity to repeat one of the big ideas of Software Carpentry: if\n", - " the computer *can* repeat it, some programmer somewhere will almost\n", - " certainly have built some way for the computer *to* repeat it.\n", - "- Building up a pipeline with four or five stages, then putting it in\n", - " a shell script for re-use and calling that script inside a `for`\n", - " loop, is a great opportunity to show how \"seven plus or minus two\"\n", - " connects to programming. Once we have figured out how to do\n", - " something moderately complicated, we make it re-usable and give it a\n", - " name so that it only takes up one slot in working memory rather than\n", - " several. It is also a good opportunity to talk about exploratory\n", - " programming: rather than designing a program up front, we can do a\n", - " few useful things and then retroactively decide which are worth\n", - " encapsulating for future re-use.\n", - "- We have to leave out many important things because of time\n", - " constraints, including file permissions, job control, and SSH. If\n", - " learners already understand the basic material, this can be covered\n", - " instead using the online lessons as guidelines.\n", - "- Installing Bash and a reasonable set of Unix commands on Windows\n", - " always involves some fiddling and frustration. Please see the latest\n", - " set of installation guidelines for advice, and try it out yourself\n", - " *before* teaching a class.\n", + "So why would you want two ways of specifing a path? \n", + "\n", + "The same reason you can put in different starting directions on Google maps! \n", + "If Google always gave you directions starting from the North Pole, no matter where you were, \n", + "it would be giving the absolute path to your destination. This would be useful in some situations, \n", + "but more often you want the relative path, i.e. the directions from where you are now. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now that you understand conceptually what all these words mean, let's log into \n", + "a UNIX shell and see how they can improve your workflow\n", + "\n", + "To start exploring, let's open a terminal and log in to\n", + "the computer by typing our user ID and password. Most systems will print\n", + "stars to obscure the password, or nothing at all, in case some evildoer\n", + "is shoulder surfing behind us." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " login: vlad\n", + " password: ********\n", + " $" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once we have logged in we'll see a [prompt](glossary.html#prompt), which\n", + "is how the shell tells us that it's waiting for input. This is usually\n", + "just a dollar sign, but which may show extra information such as our\n", + "user ID or the current time. First let's find out where we are right now \n", + "by running a command called `pwd` (which stands for \"print working directory\").\n", + "At any moment, our [current working directory](glossary.html#current-working-directory)\n", + "is our current default directory, it's where you are right now. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ pwd\n", + " \n", + " /users/vlad\n", + " \n", + " vlad$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Here, the computer's response is `/users/vlad`, which is Vlad's [home directory](glossary.html#home-directory). This is where the operating system stores all the files and directories that belong to Vlad. To see what is in Vlad's\n", + "home directory, we would ask the computer to list all the entries with the command `ls` (\"list\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ ls\n", + " \n", + " Applications Documents Movies Tacos\n", + " Desktop Downloads Music\n", + " \n", + " vlad$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Notice that only six directories are visible, even though there may be hundreds of directories on Vlad's computer.\n", + "Working in the shell behaves in exactly the same way as navigating through your file system by pointing and clicking:\n", + "you can only see the directories and files that are in your current directory. By extension, you can also only _work with_\n", + "the directories and files in your current directory unless you specify their path. If we `cd` or \"change directories\"\n", + "to the `Movies` directory:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ cd Movies/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "when `cd` works correctly, it doesn't give you any output, but you can list the contents of your new directory with `ls`:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ ls\n", + " \n", + " avengers.mp4 I_am_legend kids_movies\n", + " gravity.avi matrix_3.mov\n", + " \n", + " vlad$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "we can now see Vlad's movies. `cd` moved us into the `Movies` directory, and now we only see the files and directories inside of it. \n", + "One other thing to note from Vlad's movies is the 'file extensions', the letters after the '.' on most files. File extensions are an easy way for you to guess what type of file you're looking at, but aren't actually necessary. It is considered a 'best practice' to include file extensions on your files, but your computer will happily play the movie `I_am_legend`, even if we changed the file extension to `.xlsx`. We can see why file extensions are a best practise by looking at `kids_movies`. Is that a movie title that's missing an extension? Or a directory full of more movies? We can check this using a 'flag' for `ls`. A 'flag' is an extra modifier you issue after the command to run `ls`. You can find an exhaustive list of the modifiers for `ls`, or almost any other command by looking in the manual `man ls`, but for now, let's just use `-F`, which adds a `/` after any directory." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ ls -F\n", + " \n", + " avengers.mp4 I_am_legend kids_movies/\n", + " gravity.avi matrix_3.mov" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we can tell that while neither `I_am_legend` nor `kids_movies` has a file extension, they aren't the same kinds of files. `kids_movies` is clearly a directory." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can also try this on other directories, as long as we specify the path. For instance, we can check out Vlad's home directory using an absolute path:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ ls -F /users/vlad\n", + " \n", + " Applications/ Documents/ Movies/ Tacos\n", + " Desktop/ Downloads/ Music/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Or a relative path:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ ls -F ..\n", "\n", - "## Prerequisites\n", + " Applications/ Documents/ Movies/ Tacos\n", + " Desktop/ Downloads/ Music/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "How is `..` a relative path? This is actually a special shortcut. The shell was \n", + "originally created in the 70's for teletype, and every keystroke counted: the devices \n", + "of the day were slow, and backspacing on a teletype was so painful that cutting \n", + "the number of keystrokes in order to cut the number of typing mistakes was actually \n", + "a win for usability. This is also why commands like `ls` aren't simply `list`, \n", + "shorter was better! In this instance, `..` is a special directory name meaning \n", + "\"the directory containing this one\", or, more succinctly, the [parent](glossary.html#parent-directory)\n", + "of the current directory.\n", "\n", - "There are no prerequisites." + "Any given directory probably has several directories inside of it, so it would \n", + "be difficult to give each one a shortcut and remember them all, but the \n", + "creators of the shell came up with a clever solution, tab complete.\n", + "Let's `cd` back to Vlad's home directory to see how it works:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Lessons\n", + " vlad$ cd .." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ ls -F\n", + " \n", + " Applications/ Documents/ Movies/ Tacos\n", + " Desktop/ Downloads/ Music/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's go find Vlad's copy of our `super_important.xlsx` from earlier. First we need the `cd`, to tell the shell we want to traverse the file system, and to start typing the path to our file:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ cd D\n", + "If we type `tab` twice instead of typing the rest of the word, the shell will try to guess where we want to go. If it can't decide the shell will present us with all the available options. Since Vlad's home directory has more than one file or directory that starts with \"D\", the shell provides all the files and directories that start with \"D\":" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ cd D\n", + " Desktop/ Documents/ Downloads/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We want to go to Vlad's desktop, so we type an \"e\" and then type `tab` twice more:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ cd De\n", + " \n", + " vlad$ cd Desktop/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The shell has guessed that \"De\" means we want \"Desktop\" and filled in the rest. To see what is available now, we can tap `tab` again, or we can add a \"W\" because we know the file we're looking for is in the `Work_Stuff` directory. In this way we can wind our way down the path with a minimum of typeing. But this isn't just a way to move our fingers less! Tab complete greatly minimizes error and the most common frustrations of learning the shell. Let's say that in our last example, we just pushed `Enter` instead of continuing down the path to our excel file, and now we're just in the `Desktop` directory:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ pwd\n", + " /users/vlad/Desktop\n", "\n", - "FIXME: these links open the raw JSON files.\n", + " vlad$ ls -F\n", "\n", - "- [Files and Directories](files/shell-filedir-instructor.ipynb)" + " grant_Proposal/ phone_backup Project_2/\n", + " home pictures/ Project_1/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Summary\n", - "\n", - "The Unix shell is older than most of the people who use it. It has\n", - "survived so long because it is one of the most productive programming\n", - "environments ever created\u2014maybe even *the* most productive. Its syntax\n", - "may be cryptic, but people who have mastered it can experiment with\n", - "different commands interactively, then use what they have learned to\n", - "automate their work. Graphical user interfaces may be better at the\n", - "first, but the shell is still unbeaten at the second. And as Alfred\n", - "North Whitehead wrote in 1911, \"Civilization advances by extending the\n", - "number of important operations which we can perform without thinking\n", - "about them.\"" + "What if we want to go into the directory with Vlad's grant proposal?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ cd grant_proposal/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "However, this won't get us anywhere! This is because the shell is case sensitive, so it thinks `grant_Proposal/` and `grant_proposal/` are completely different things! If we tab complete, this is easy to avoid, because when we type \"g\" and tab complete, the shell fills in the capital letters appropriatly." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What if we want to go into the directory with Vlad's home pictures? Presumably, we would type:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ cd home pictures/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "But this doesn't work either! Instead we get an error!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " -bash: cd: home: No such file or directory" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Why? Because the shell interpretes spaces as special characters, in this case, as the deliminators for command modifiers. It thinks you want to \"cd\" to \"home\" with the \"pictures/\" option, but `cd` doesn't have a pictures option, so it errors. This illustrates two important points: first, use tab complete as much as possible, and second, try to avoid spaces in file and directory names. To correctly change to the `home pictures` directory, we need to tell the shell that this particular space is not a special character, but is instead part of the file name. We do this by \"escaping\" out the space, which looks like this:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ cd home\\ pictures/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Putting a `\\` in front of any character tells the shell to interpret that character as the literal text. Now, the command will `cd` correctly. But remember, we could have avoided this whole issue with tab completion! There are many, many other commands that are used to add, move, modify and delete files and directories, and we will cover several of them in later sessions. But one of the most important is how to create new files. First, lets make a new directory to hold our file and move into it:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ cd /user/vlad" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ mkdir my_new_directory\n", + " \n", + " vlad$ ls -F\n", + " \n", + " Applications/ Documents/ Movies/ my_new_directory/\n", + " Desktop/ Downloads/ Music/ Tacos\n", + " \n", + " vlad$ cd my_new_directory" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The command `mkdir` is short for \"make directory\", and it creates a new directory with whatever name you type after the command, we've made \"my_new_directory\" with no spaces, so its easier to type later. After we made the directory, we asked for a list `ls` of the items in the current directory to make sure our new one was created, and finally we `cd` into our new directory so we can make files inside of it. So let's make a file:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ nano my_first_file.txt" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Nano is a text editor. To use it, you type `nano` and then the name of the file you'd like to open. If the filename you specify doesn't exist in your current working directory, Nano creates it for you and opens the empty file. We've just created a new text file called `my_first_file.txt`. We have carefully typed a `.txt` after it so our future selves remember what kind of file it is, but Nano doesn't care. Let's type something in it:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " echo \"hello world\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "to save your work in Nano, you type `ctrl` and `x`, then `y` (for \"yes\") and `enter`. Nano also helpfully keeps all of these instructions at the bottom of the screen for your reference. \n", + "\n", + "It may not look like it, but you've just created your first program! Like `ls`, `echo` is a shell command. `echo` prints any following text to the terminal. Normally you would use `echo` as part of a program to give the user and update, like how much processing time is left, but here we're just printing a greeting. To run your program:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " vlad$ sh my_first_file.txt\n", + " \n", + " hello world" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The `sh` is yet another command, this one tells the shell that you want to run a file full of shell commands, and you follow it with the name of that file. So the shell opened our text file, ran the `echo` command, and printed it to our screen." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### *Windows*\n", + "\n", + "\n", + " Everything we have seen so far works on Unix and its descendents, such\n", + " as Linux and Mac OS X. Things are a bit different on Windows. A typical\n", + " directory path on a Windows machine might be `C:\\Users\\vlad`. The\n", + " first part, `C:`, is a [drive letter](glossary.html#drive-letter) that\n", + " identifies which disk we're talking about. This notation dates back to\n", + " the days of floppy drives; today, different \"drives\" are usually\n", + " different filesystems on the network.\n", + "\n", + "\n", + "\n", + " Instead of a forward slash, Windows uses a backslash to separate the\n", + " names in a path. This causes headaches because Unix uses backslash for\n", + " input of special characters. For example, if we want to put a space in a\n", + " filename on Unix, we would write the filename as `my\\\u00a0results.txt`.\n", + " Please don't ever do this, though: if you put spaces, question marks,\n", + " and other special characters in filenames on Unix, you can confuse the\n", + " shell as we saw earlier.\n", + "\n", + "\n", + "\n", + " Finally, Windows filenames and directory names are [case insensitive](glossary.html#case-insensitive): upper and lower case\n", + " letters mean the same thing. This means that the path name\n", + " `C:\\Users\\vlad` could be spelled `c:\\users\\VLAD`, `C:\\Users\\Vlad`, and\n", + " so on. Some people argue that this is more natural: after all, \"VLAD\" in\n", + " all upper case and \"Vlad\" spelled normally refer to the same person.\n", + " However, it causes headaches for programmers, and can be difficult for\n", + " people to understand if their first language uses a cased\n", + " alphabet as in the example above\n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### *For Cygwin Users*\n", + "\n", + "\n", + " [Cygwin](http://www.cygwin.org) tries to make Windows paths look more\n", + " like Unix paths by allowing us to use a forward slash instead of a\n", + " backslash as a separator. It also allows us to refer to the C drive as\n", + " `/cygdrive/c/` instead of as `C:`. (The latter usually works too, but\n", + " not always.) Paths are still case insensitive, though, which means that\n", + " if you try to put files called `backup.txt` (in all lower case) and\n", + " `Backup.txt` (with a capital 'B') into the same directory, the second\n", + " will overwrite the first.\n", + "\n", + "\n", + "\n", + " Cygwin does something else that frequently causes confusion. By default,\n", + " it interprets a path like `/home/vlad` to mean `C:\\cygwin\\home\\vlad`,\n", + " i.e., it acts as if `C:\\cygwin` was the root of the filesystem. This is\n", + " sometimes helpful, but if you are using an editor like Notepad, and want\n", + " to save a file in what Cygwin thinks of as your home directory, you need\n", + " to keep this translation in mind.\n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Nelle's Pipeline: Organizing Files\n", + "\n", + "Knowing just this much about files and directories, Nelle is ready to\n", + "organize the files that the protein assay machine will create. First,\n", + "she creates a directory called `north-pacific-gyre` (to remind herself\n", + "where the data came from). Inside that, she creates a directory called\n", + "`2012-07-03`, which is the date she started processing the samples. She\n", + "used to use names like `conference-paper` and `revised-results`, but she\n", + "found them hard to understand after a couple of years. (The final straw\n", + "was when she found herself creating a directory called\n", + "`revised-revised-results-3`.)\n", + "\n", + "Each of her physical samples is labelled according to her lab's\n", + "convention with a unique ten-character ID, such as \"NENE01729A\". This is\n", + "what she used in her collection log to record the location, time, depth,\n", + "and other characteristics of the sample, so she decides to use it as\n", + "part of each data file's name. Since the assay machine's output is plain\n", + "text, she will call her files `NENE01729A.txt`, `NENE01812A.txt`, and so\n", + "on. All 1520 files will go into the same directory.\n", + "\n", + "If she is in her home directory, Nelle can see what files she has using\n", + "the command:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " $ ls north-pacific-gyre/2012-07-03/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Since this is a lot to type, she can take advantage of Bash's [command completion](glossary.html#command-completion). If she types:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " $ ls no" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and then presses tab, Bash will automatically complete the directory name for her:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " $ ls north-pacific-gyre/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If she presses tab again, Bash will add `2012-07-03/` to the command,\n", + "since it's the only possible completion. Pressing tab again does\n", + "nothing, since there are 1520 possibilities; pressing tab twice brings\n", + "up a list of all the files, and so on. As above, this is called [tab completion](glossary.html#tab-completion), and we will see it in many\n", + "other tools as we go on." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Key Points\n", + "\n", + "- The file system is responsible for managing information on disk.\n", + "- Information is stored in files, which are stored in directories\n", + " (folders).\n", + "- Directories can also store other directories, which forms a\n", + " directory tree.\n", + "- `/` on its own is the root directory of the whole filesystem.\n", + "- A relative path specifies a location starting from the current\n", + " location.\n", + "- An absolute path specifies a location from the root of the\n", + " filesystem.\n", + "- Directory names in a path are separated with '/' on Unix, but '\\\\'\n", + " on Windows.\n", + "- '..' means \"the directory above the current one\"; '.' on its own\n", + " means \"the current directory\".\n", + "- Most files' names are `something.extension`; the extension isn't\n", + " required, and doesn't guarantee anything, but is normally used to\n", + " indicate the type of data in the file.\n", + "- `cd path` changes the current working directory.\n", + "- `ls path` prints a listing of a specific file or directory; `ls` on\n", + " its own lists the current working directory.\n", + "- `pwd` prints the user's current working directory (current default\n", + " location in the filesystem).\n", + "- Most commands take modifiers (flags) which begin with a '-'." ] } ], "metadata": {} } ] -} \ No newline at end of file +}