Skip to content
This repository has been archived by the owner on Jan 3, 2018. It is now read-only.

Commit

Permalink
Suggested revisions to PR #93
Browse files Browse the repository at this point in the history
Very minor editing and fixes
  • Loading branch information
ahmadia committed Nov 20, 2013
1 parent 138fe84 commit d17d944
Showing 1 changed file with 56 additions and 66 deletions.
122 changes: 56 additions & 66 deletions lessons/swc-shell/shell-filedir.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"metadata": {
"name": "shell-overview"
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -59,7 +59,7 @@
"this step will \"only\" take about two weeks.\n",
"\n",
"The bad news is, if she has to run `goostat` and `goodiff` by hand,\n",
"she'll have to enter filenames and click \"OK\" roughly 300^2^ times (300\n",
"she'll have to enter filenames and click \"OK\" roughly 300^2 times (300\n",
"runs of `goostat`, plus 300\u00d7299 runs of `goodiff`). At 30 seconds each,\n",
"that will 750 hours, or 18 weeks. Not only would she miss her paper\n",
"deadline, the chances of her getting all 90,000 commands right are\n",
Expand Down Expand Up @@ -88,9 +88,9 @@
"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",
"> 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",
"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",
Expand All @@ -108,14 +108,14 @@
"\n",
"Instead, you could also use the 'absolute path':\n",
"\n",
" /users/Amanda/Desktop/Work_Stuff/Project_1/datasheets/super_important.xlsx\n",
" /Users/Amanda/Desktop/Work_Stuff/Project_1/datasheets/super_important.xlsx\n",
"\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",
"So why would you want two ways of specifing a path? \n",
"So why would you want two ways of specifying 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",
Expand Down Expand Up @@ -151,7 +151,7 @@
"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",
"just a dollar sign, but it 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",
Expand All @@ -164,7 +164,7 @@
"source": [
" vlad$ pwd\n",
" \n",
" /users/vlad\n",
" /Users/vlad\n",
" \n",
" vlad$"
]
Expand All @@ -173,7 +173,7 @@
"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",
"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\")"
]
},
Expand Down Expand Up @@ -211,7 +211,7 @@
"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`:"
"When `cd` works correctly, it doesn't give you any output, but you can list the contents of your new directory with `ls`:"
]
},
{
Expand All @@ -230,8 +230,8 @@
"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."
"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 practice 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."
]
},
{
Expand Down Expand Up @@ -364,7 +364,7 @@
"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:"
"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 typing. 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:"
]
},
{
Expand Down Expand Up @@ -433,7 +433,7 @@
"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:"
"Why? Because the shell interpretes spaces as special characters, in this case, as the delimiters 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:"
]
},
{
Expand All @@ -447,7 +447,7 @@
"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:"
"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, let's make a new directory to hold our file and move into it:"
]
},
{
Expand Down Expand Up @@ -475,7 +475,7 @@
"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:"
"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:"
]
},
{
Expand Down Expand Up @@ -503,7 +503,7 @@
"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",
"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:"
]
Expand All @@ -521,7 +521,7 @@
"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."
"`sh` is yet another command, which refers to the shell program. Using `sh` followed by a filename executes the named file line-by-line just as if we'd typed them in ourselves. The shell opened our text file, ran the `echo` command, and printed it to our screen, just as if we'd typed `echo \"hello world\"` at the prompt."
]
},
{
Expand All @@ -530,36 +530,30 @@
"source": [
"### *Windows*\n",
"\n",
"<em>\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",
"</em>\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",
"<em>\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",
"</em>\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",
"<em>\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",
"</em>"
"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"
]
},
{
Expand All @@ -568,25 +562,21 @@
"source": [
"### *For Cygwin Users*\n",
"\n",
"<em>\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",
"</em>\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",
"<em>\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",
"</em>"
"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."
]
},
{
Expand Down Expand Up @@ -698,4 +688,4 @@
"metadata": {}
}
]
}
}

0 comments on commit d17d944

Please sign in to comment.