-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunix.html
223 lines (198 loc) · 13.6 KB
/
unix.html
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"/>
<title>Hillary Sanders</title>
<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="css/style.css" type="text/css" rel="stylesheet" media="screen,projection"/>
</head>
<body>
<nav class="blue-grey" role="navigation">
<div class="nav-wrapper container">
<!-- Dropdown Structure -->
<ul id="dd_art" class="dropdown-content blue-grey">
<li><a href="graphite.html" class="white-text">graphite</a></li>
<li><a href="ink.html" class="white-text">sharpie</a></li>
<li><a href="paint.html" class="white-text">paint</a></li>
<li><a href="mixed.html" class="white-text">mixed</a></li>
</ul>
<ul id="dd_cheatsheets" class="dropdown-content blue-grey">
<li><a href="python.html" class="white-text">Python</a></li>
<!-- <li><a href="r.html" class="white-text">R</a></li> -->
<li><a href="unix.html" class="white-text">UNIX</a></li>
<li><a href="latex.html" class="white-text">LaTeX</a></li>
<!-- <li><a href="probability.html" class="white-text">Probability</a></li> -->
</ul>
<nav>
<div class="nav-wrapper">
<a href="index.html" class="brand-logo hillz"> hillz</a>
<ul class="right hide-on-med-and-down">
<li><a href="resume.html">Resume</a></li>
<li><a href="recent_projects.html">Recent Projects</a></li>
<!-- <li><a href="bayesian_statistics.html">Bayesian Statistics</a></li> -->
<li><a href="about_me.html">About Me</a></li>
<!-- Dropdown Trigger -->
<!-- <li><a class="dropdown-button" href="#" data-hover="true" data-beloworigin="true" data-activates="dd_cheatsheets">
Cheatsheets
<i class="material-icons right">arrow_drop_down</i></a></li> -->
<li><a class="dropdown-button" href="#" data-hover="true" data-beloworigin="true" data-activates="dd_art">
Art
<i class="material-icons right">arrow_drop_down</i></a></li>
</ul>
</div>
</nav>
<ul id="nav-mobile" class="side-nav blue-grey white-text">
<li><a href="index.html" class="white-text">HOME</a></li>
<li><a href="resume.html" class="white-text">Resume</a></li>
<li><a href="recent_projects.html" class="white-text">Recent Projects</a></li>
<!-- <li><a href="bayesian_statistics.html" class="white-text">Bayesian Statistics</a></li> -->
<li><a href="about_me.html" class="white-text">About Me</a></li>
<li><a class="white-text">Art</a></li>
<li><a href="graphite.html" class="white-text"> draw</a></li>
<li><a href="ink.html" class="white-text"> sharpie</a></li>
<li><a href="paint.html" class="white-text"> paint</a></li>
<li><a href="mixed.html" class="white-text"> mixed</a></li>
<li><a class="white-text">Cheatsheets</a></li>
<li><a href="python.html" class="white-text"> Python</a></li>
<li><a href="r.html" class="white-text"> R</a></li>
<li><a href="unix.html" class="white-text"> UNIX</a></li>
<li><a href="latex.html" class="white-text"> LaTeX</a></li>
<li><a href="probability.html" class="white-text"> Probability</a></li>
</ul>
<a href="#" data-activates="nav-mobile" class="button-collapse"><i class="material-icons">menu</i></a>
</div>
</nav>
<div class="row center">
<h2 class="header col s12 white-text">UNIX</h2>
</div>
<div class="row">
<div class="col s12 m4 l3">
<div class="cheatbox">
<h5>The Basics</h5>
<li><b>$ ls</b> : shows what's listed in the current directory</li>
<li><b>$ ls -a</b> : shows what's listed in the current directory, including hidden files</li>
<li><b>$ mkdir foo</b> : makes a folder in the current directoy called foo</li>
<li><b>$ cd foo</b> : move into the folder foo</li>
<li><b>$ cd ..</b> : move backwards into the parent directory</li>
<li><b>$ pwd</b> : prints current working directory</li>
<li><b>$ ls foo</b> : lists the contents of the folder foo</li>
<br>
<li><b>$ ls ~/foo</b> : lists the contents of the folder foo that lives in your home directory (~/, e.g. '/Users/hills') </li>
<li><b>$ cp foo.txt bar.txt</b> : duplicates foo.txt and saves it as bar.txt </li>
<li><b>$ mv foo.txt some-folder/bar.txt</b> : moves foo.txt to the some-folder folder, and calls it bar.txt (foo.txt is deleted)</li>
<li>$ rm bar.txt<b></b> : deletes foo.txt</li>
<br>
<li><b>$ ^L</b> ([Control]-[d]) : clears terminal screen (<b>clear</b> also does this)</li>
<li><b>$ cat foo.txt</b> : prints all of foo.txt to the screen</li>
<li><b>$ less foo.txt</b> : prints the first few lines of foo.txt to the screen: to continue, press space, to quit reading, press q.</li>
<li><b>$ head foo.txt</b> : prints the first ten lines of foo.txt</li>
<li><b>$ tail foo.txt</b> : prints the last ten lines of foo.txt</li>
</div>
<div class="cheatbox">
<h5>Text Searches</h5>
<li><b>$ less /keyword</b> : If you use the <b>less foo.txt</b> command to inspect the contents of foo.txt, you can type a keyword: <b>/some-keyword</b> before you exit (<b>q</b>), and any matches to that keyword will be highlighted.</li>
<br>
<li><b>$ grep keyword foo.txt</b> : searches for an exact match to keyword in the file foo.txt</li>
<li><b>$ grep 'I like ice cream' foo.txt</b> : searched for an exact match to the phrase 'I like ice cream'</li>
- <b>grep -i</b> : ignores cases
<br> - <b>grep -v</b> : only displays lines that don't match
<br> - <b>grep -c</b> : only prints the number of lines that include a match
<br> - <b>grep -ivc</b> : all three i, v, and c options at once
<br>
<li><b>wc foo.txt</b> : displays the line count, word count, and character count of foo.txt</li>
- <b>wc -l</b> : line count
<br> - <b>wc -w</b> : word count
<br> - <b>wc -c</b> : character count
</div>
</div>
<div class="col s12 m4 l3">
<div class="cheatbox">
<h5>Wildcards</h5>
<b>*</b> is called a wildcard (sort of like in regular expressions) - it's used in text searches. A <b>*</b> matches against any (or no) characters in a file or directory name.
<li><b>$ ls kittens*</b> : </li> shows all files in the current directory that starts with kittens.
<li><b>$ ls *kittens</b> : </li> shows all files in the current directory that ends with kittens.
The <b>?</b> character matches to any single character.
<li><b>$ ls ?ittens*</b> : could match to mittens, kittens, or mittons.csv, but not, er, lots-of-kittens. </li>
</div>
<div class="cheatbox">
<h5> File Access Rights </h5>
<li><b>$ ls -l</b> : displays a very verbose version of the items in the current directory. Each line represents a file, and there are various bits of information displayed (<b>access rights, owner, group-owner, size of the file, time the file was created, filename</b>).</li>
<br>
<b> Access rights </b> consist of a ten character string. The first letter is either 'd' (if it's a directory), or '-' (if it's not). The next three letters show the read, write, and execution permssions for the user that owns the file. The next three shows the read, right, and execution permissions for the group of people that own the file (group owner), and the last three characters gives the read right and execution permissions for everyone else. If the symbol showing permissions is 'r', 'w', or 'x', that means the user(s) can respectively read, write to, or execute the given file, but if the character is '-', they cannot. So if the permissions are <b>-rw-r--r--</b>, nobody but the owner can write to the file, but everyone can read it.
<br>
The command <b>chmod</b> allows you to change the permissions of a file or directory.<br>
- <b>u</b> stands for user, <b>g</b> stands for group, <b>o</b> stands for other, and <b>a</b> stands for all. <br>
- <b>r</b> stands for read, <b>w</b> stands for write, and <b>x</b> stands for execute. <br>
- <b>+</b> = add the permission, and <b>-</b> = remove a permission.
<li><b>$ chmod go-rwx</b> : remove the read, write, and execute rights for the group and other users.</li>
<li><b>$ chmod a+rw</b> : give the read and write permissions to all users.</li>
</div>
</div>
<div class="col s12 m4 l3">
<div class="cheatbox">
<h5>Other Useful Tips & Tricks</h5>
<li><b>$ df .</b> : shows how much space is left on your computer</li>
<li><b>$ du</b> : shows the amount of space used by each subdirectory. This is usually a super long list though, so instead:</li>
<li><b>$ du -d 1</b> : goes one directory deep </li>
<li><b>$ du -d 2</b> : goes two directories deep, and so on.</li>
<br>
<li><b>$ zip foo foo.txt</b> : compresses foo.txt and saves it as foo.txt.zip. Note that you can zip up whole directories, or use wildcards to zip multiple files in a directory at once.</li>
<li><b>$ unzip foo.txt.zip</b> : unzips it</li>
<br>
<li><b>$ file *</b> : shows the types of objects in your current directory (jpeg, text file, etc...)</li>
<br>
<li><b>$ history</b> : shows a list of the 15 most recent commands that you typed into the terminal. If you type <b>history -k</b>, the last k commands will show up.</li>
</div>
<div class="cheatbox">
<h5>Redirection</h5>
type <b>$ cat > deepest-thoughts</b>. Then type: <br>
<b>
$ I<br>
$ am a mega awesome<br>
$ unixer<br>
</b>
Then enter <b>$ ^D</b>. The text you entered will be routed to a file named deepest-thoughts, because the <b>></b> symbol redirects the output of a command ingto whatever is to the right of the <b>></b> symbol.
<br><br>
Type <b> open deepest-thoughts </b> to open the file or <b>cat deepest-thoughts</b> to see the lines printed to your screen.
<b> >> </b> appends to a file. So: <br>
<b>$ cat >> deepest-thoughts</b><br>
<b>$ seriously</b> <br>
<b>$ ^D </b><br>
Will append the line 'seriously' to your deepest-thoughts file.
<li><b>$ cat foo1 foo2 > megafoo</b> : appends foo1 to foo2 and saves it as megafoo. </li>
<br>
The <b> < </b> symbol redirects the input of a command.
<li><b>$ sort < list.txt > foo.txt</b> : sorts list.txt and saves it to the files sorted.txt</li>
<li><b>$ list.txt | sort </b> : the<b> | </b>symbol pipes list.txt into the sort command. So <b>$ list.txt | sort </b> is equivalent to <b>$ sort list.txt</b>, which is the same as <b>sort < list.txt</b></li>
</div>
</div>
<div class="col s12 m4 l3">
<div class="cheatbox">
<h5>Jobs</h5>
<li><b>$ ps</b> : shows the the currently running jobs</li>
<li><b>$ sleep 10</b> : sleeps the terminal for 10 seconds</li>
<li><b>$ sleep 100 &</b> : sleeps the terminal for 100 seconds, but in the background due to the ampersand. The unqiue job identifier (PID) is also printed. You can type <b>ps</b> before the 100 seconds is up to see the job running.</li>
<li><b>$^Z bg</b> : <b>^Z</b> suspends a currently running process, abd <b>bg</b> restarts the process but puts it in the background.</li>
<li><b>$ jobs</b> : displays a list of currently running jobs (many processes can be contained in one job)</li>
<li><b>$ fg %i</b> : restarts the ith job in the list of jobs, where i is an integer.</li>
<li><b>$ kill %i</b> : kills the ith job if it is suspended or a background process.</li>
<li><b>$ ^C</b> : kills a job that is currently running in the foreground.
</li>
<li><b>$ kill 1234</b> : kills a process with PID number 1234</li>
</div>
<div class="cheatbox">
<h5> Manuals </h5>
<li><b>$ man some-command</b> : shows the manual page for some-command. (Press q to quit)</li>
<li><b>$ apropos keyword | head</b> : returns the first few commands that have the word 'keyword' in their header. So, if you type </li>
</div>
</div>
</div>
<!-- Scripts-->
<script src="js/jquery-2.2.3.min.js"></script>
<script src="js/materialize.js"></script>
<script src="js/init.js"></script>
</body>
</html>