-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathintroduction-to-the-terminal.html
More file actions
82 lines (80 loc) · 4.67 KB
/
introduction-to-the-terminal.html
File metadata and controls
82 lines (80 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<script src="/bjc-r/llab/loader.js"></script>
<title>Introduction to the Terminal</title>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-176402054-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-176402054-1');
</script>
</head>
<body>
<h2>What's a Terminal?</h2>
<p>
You're used to navigating around your computer by clicking on folder icons and using menus to create new files and folders. We can do all of this from the terminal as well, by typing out commands instead of using the mouse to click on things.
</p>
<h2>Opening a Terminal</h2>
<p>
If you're on one of the lab computers or on your own Mac, search for the application Terminal and open it. If you're using Windows, search for cmd.exe instead. After you open the program, you should have a window that has <em>something</em> like this in it:
</p>
<p><pre><code>
Alonzos-MacBook:~ alonzo$$
</code></pre></p>
<p>
The little bit of text that's already in the window is called the <b>prompt</b>. It gives you a bit of information about the computer that you're on. When you type commands, they appear to the right of the prompt.
</p>
<p>
Let's learn how to navigate around. Right now, you're in the <b>home</b> directory, also called <b>~</b>. A <b>directory</b> is just another name for a folder (like the <code>Documents</code> folder).
</p>
<h3><code>ls</code>: listing contents of a directory</h3>
<p>
To see what's in the current directory, we can use the command <code>ls</code> (use <code>dir</code> instead if on Windows). The <code>ls</code> command lists the contents of our current directory. To use a command, type it in the terminal, then press 'enter'. Try it out. You should see something like this:
</p>
<p><pre><code>
Alonzos-MacBook:~ alonzo$$ ls
Applications Downloads Pictures
Library Public Music
Desktop Movies Documents
</code></pre></p>
<h3><code>cd</code>: navigating to another directory</h3>
<p>
We can see that the home directory has some other directories in it, such as <code>Documents</code> and <code>Desktop</code>. If we want to go into one of those directories, we can use the command <code>cd</code>, followed by that directory's name. Try it out by using the command <code>cd Documents</code>.
</p>
<p><pre><code>
Alonzos-MacBook:~ alonzo$$ cd Documents
Alonzos-MacBook:Documents alonzo$$
</code></pre></p>
<p>
Now you're in the <code>Documents</code> directory. We can use <code>ls</code> again to see the contents of <code>Documents</code>.
</p>
<p>
How can we get back to the home directory from here? <code>cd ..</code> moves us upward one directory, which puts us back in home. The "dot dot" always means "parent directory". This means we can use <code>cd ..</code> to go to upward one directory. Try it out!
</p>
<p><pre><code>
Alonzos-MacBook:Documents alonzo$$ cd ..
Alonzos-MacBook:~ alonzo$$
</code></pre></p>
<h3><code>mkdir</code>: making a new directory</h3>
<p>
Okay, now that we've tried that, let's go back to <code>Documents</code>. (If you're in <code>home</code>, use the command <code>cd Documents</code>). You're probably used to making new folders on your computer by using a menu action like "File > New Folder", or a keyboard shortcut like "shift-cmd-N". To make a new directory (folder) using the terminal, we can use the command <code>mkdir</code> followed by the name we want for the new directory. Try the command <code>mkdir PythonLab1</code>.
</p>
<p><pre><code>
Alonzos-MacBook:~ alonzo$$ cd Documents
Alonzos-MacBook:Documents alonzo$$ mkdir PythonLab1
</code></pre></p>
<p>
Nice! now use <code>ls</code> to confirm that your directory has been created! We can use <code>cd PythonLab1</code> to go into our new directory.
</p>
<p><pre><code>
Alonzos-MacBook:Documents alonzo$$ cd PythonLab1
Alonzos-MacBook:PythonLab1 alonzo$$
</code></pre></p>
<p class="alert alert-info quoteBlue">
You can also use the terminal to do almost anything, such as moving, copying, and removing files and directories. If you would like an explanation of some other useful terminal commands check out this <b><a target ="_blank" href="http://cs61a.org/articles/unix.html">article</a></b>.
</p>
</body>
</html>