-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasicUNIX.html
309 lines (287 loc) · 9 KB
/
basicUNIX.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic UNIX Commands</title>
</head>
<body>
<center>
<h1>Basic UNIX Commands</h1>
</center>
<p>
This file contains a few basic UNIX commands to enable you to create
directories and files, move around to find specific files, and run a
few simple commands.
</p>
<p>
<hr>
</p>
<h2>General</h2>
<ul>
<dl>
<dt><code>passwd</code></dt>
<dd>change my password (on some systems it is <code>yppasswd</code> or
something different, so ask around)
</dd>
<dt><code>man</code></dt>
<dd>read the manual page, e.g.,
<table>
<tr><td><code>man chmod</code></td>
<td>read about the UNIX <code>chmod</code> command</td></tr>
<tr><td><code>man man</code></td>
<td>read about the <code>man</code> command</td></tr>
<tr><td><code>man fopen</code></td>
<td>read about the Standard C library <code>fopen</code> command</td></tr>
</table>
</dd>
</dl>
</ul>
<h2>Directories and Files</h2>
<h3>General information about file names</h3>
<ul>
<dl>
<dt>Absolute pathname:</dt>
<dd>Fully specifies a directory, starting at the root.
For example, <code>/home/www/CS400/index.html</code> is an
absolute pathname.
Absolute pathnames always start with / (which is
the name of the root directory), with one exception:
a tilde in front of a username represents the absolute pathname
of that user's home directory. For example,
<code>~abrady/ProgLang</code> is an absolute name because the
system will expand <code>~abrady</code> to <code>/home/abrady</code>.
<p>
<dt>Relative pathname:</dt>
<dd>the name of a file or directory relative to the current directory;
e.g.,
<table>
<tr><td width="30%"><code>myfile.c</code></td>
<td>file in current directory</td></tr>
<tr><td><code>progLang/myfile.c</code></td>
<td>file in <code>progLang</code> directory, which is a subdirectory
of the current directory</td></tr>
<tr><td><code>../myfile.c</code></td>
<td>file in parent directory (<code>..</code> means directory above
current directory)</td></tr>
<tr><td><code>../progLang/myfile.c</code></td>
<td>file in <code>progLang</code> directory, which is at same level
in hierarchy as the current directory (it is a child of my
parent directory)</td></tr>
</table>
</dd>
</dl>
</ul>
<h3>Commands for files and directories</h3>
<ul>
<dl>
<dt><strong>Moving Around the Directory Hierarchy</strong></dt>
<dt><code>pwd</code></dt>
<dd>show me where I am (print working directory)
</dd>
<dt><code>cd dirname</code></dt>
<dd>change to directory <code>dirname</code>, e.g., <code>cd ProgLang</code>
or <code>cd ../ProgLang</code> or <code>cd ~abrady/ProgLang</code>
</dd>
<p>
<dt><strong>Creating and Removing Directories</strong></dt>
<dt><code>mkdir dirname</code></dt>
<dd>make a subdirectory under the current directory; call it
<code>dirname</code>
</dd>
<dt><code>rmdir dirname</code></dt>
<dd>remove the directory named <code>dirname</code> (must be empty)
</dd>
<p>
<dt><strong>Listing Files in a Directory</strong></dt>
<dt><code>ls</code></dt>
<dd>list the files in the directory (does not include files whose
names start with a dot, e.g., <code>.profile</code>, which are also
known as <em>hidden</em> files)
</dd>
<dt><code>ls -aF</code></dt>
<dd>better looking listing; lists all files (including dot files),
indicating directories, executables and links
</dd>
<dt><code>ls *.html *.c</code></dt>
<dd>only list files ending in <code>.html</code> or <code>.c</code>
</dd>
<p>
<dt><strong>Moving, Copying, and Removing Files</strong></dt>
<dt><code>mv oldname newname</code></dt>
<dd>rename file <code>oldname</code> to <code>newname</code>
</dd>
<dt><code>mv oldname ProgLang/newname</code></dt>
<dd>move file <code>oldname</code> to directory <code>ProgLang</code>,
giving it name <code>newname</code>
</dd>
<dt><code>cp oldfile newfile</code></dt>
<dd>make a copy of <code>oldfile</code>, calling the copy
<code>newfile</code>
</dd>
<dt><code>cp oldfile ProgLang/newfile</code></dt>
<dd>make a copy of <code>oldfile</code>; put in the
<code>ProgLang</code> directory
</dd>
<dt><code>rm filename</code></dt>
<dd>remove filename (does not ask you to confirm this!)
</dd>
<dt><code>rm *</code></dt>
<dd>remove all the files in the directory (don't do this!)
</dd>
<p>
<dt><strong>Looking at the Contents of Files</strong></dt>
<dt><code>cat filename</code></dt>
<dd>display filename to the screen (<code>cat</code> = concatenate)
</dd>
<dt><code>cat f1 f2 >f3</code></dt>
<dd>concatenate <code>f1</code> and <code>f2</code>, calling combination <code>f3</code>
</dd>
<dt><code>more filename</code></dt>
<dd>display <code>filename</code> to screen one page at a time (use
spacebar to go to next page; <code>b</code> to back up)
</dd>
<dt><code>lpr filename</code></dt>
<dd>print a file
(<code>pr filename</code> on some systems)
</dd>
<dt><code>vi filename</code></dt>
<dd>edit <code>filename</code> (but learning vi is another lesson!)
</dd>
<dt><code>emacs filename</code></dt>
<dd>edit <code>filename</code> (but learning emacs is another lesson!)
</dd>
<p>
<dt><strong>Looking for a Specific Word or Phrase in One or More Files</strong></dt>
<dt><code>grep string *.c</code></dt>
<dd>find which <code>.c</code> files contain <code>string</code>, e.g.,
<code>grep fcn3 *.c</code>
</dd>
<p>
<dt><strong>Compiling Programs</strong></dt>
<dt><code>cc, CC</code></dt>
<dd>C and C++ compilers
</dd>
<dt><code>gcc, g++</code></dt>
<dd>GNU C and C++ compilers
</dd>
<dt><code>gcc -Wall -Wextra -Wpedantic -Wformat -Wshadow
-Wredundant-decls -Wstrict-prototypes</code></dt>
<dd>The <code>-W</code> options generate warnings about questionable
constructions; these sometimes indicate programmer confusion or actual
logic errors. (You can also use <code>-Wtraditional</code> to catch
some non-traditional C constructs that GCC allows, or
<code>-Wmissing-prototypes</code> to find functions that do not have
prototypes in header files.)
</dd>
<!--
<dt><code>cb</code></dt>
<dd>C beautifier (does pretty printing)
</dd>
-->
<dt><code>cflow, dbx, gdb</code></dt>
<dd>for C debugging; different debuggers have been available on different
systems
</dd>
</dl>
</ul>
<p>
<h3>Others that might be useful (see <code>man</code> page for details):</h3>
<ul>
<dl>
<dt><code>chmod</code></dt> <dd>change the permissions on a file or directory</dd>
<dt><code>head</code></dt> <dd>display the top few lines of a file</dd>
<dt><code>tail</code></dt> <dd>display the last few lines of a file</dd>
</dl>
</ul>
<h3>Other handy, simple commands:</h3>
<ul>
<dl>
<dt><code>banner word</code></dt>
<dd>make a word big
</dd>
<dt><code>cal</code></dt>
<dd>show a calendar, e.g., <code>cal 9 1752</code>
</dd>
<dt><code>clear</code></dt>
<dd>clear the screen
</dd>
<dt><code>date</code></dt>
<dd>show the date and time
</dd>
<dt><code>echo</code></dt>
<dd>print to screen, e.g., <code>echo Hi!</code> or <code>echo $PATH</code>
</dd>
<dt><code>exit, logout</code></dt>
<dd>exit a UNIX shell, log out of UNIX
</dd>
<!--
<dt><code>finger</code></dt>
<dd>display info. about users, e.g.,
<code>finger [email protected]</code>
or <code>finger Spaulding</code>
</dd>
<dt><code>look</code></dt>
<dd>find words in system dictionary, e.g., <code>look viti</code>
</dd>
<dt><code>spell</code></dt>
<dd>spell checker
</dd>
<dt><code>mail</code></dt>
<dd>send or receive email (very old, unsophisticated application)
</dd>
<dt><code>msgs</code></dt>
<dd>show system messages
</dd>
-->
<dt><code>wc</code></dt>
<dd>word count (also counts lines and characters)
e.g., <code>wc myfile</code> or
<code>wc -l myfile</code>
</dd>
<dt><code>who</code></dt>
<dd>who is logged in to the system
</dd>
</dl>
</ul>
<p>
<h3>More powerful commands that might be useful (see <code>man</code>
page for details):</h3>
<ul>
<dl>
<dt><code>type command</code></dt>
<dd>where/what is <code>command</code>? (could be a command or an
alias) e.g., <code>type diff</code> or <code>type l</code>
</dd>
<dt><code>whereis command</code></dt>
<dd>where does this UNIX command live? e.g., <code>whereis man</code>
</dd>
<dt><code>grep</code></dt>
<dd>look for a pattern in file(s), e.g., <code>grep pat myfile</code>
</dd>
<dt><code>diff</code></dt>
<dd>show differences between two files, e.g., <code>diff old new</code>
</dd>
<dt><code>sort</code></dt>
<dd>sort and collate lines of a file
</dd>
<dt><code>find</code></dt>
<dd>find files by name or other characteristics
<dt><code>ftp</code></dt>
<dd>file transfer protocol
</dd>
<dt><code>ssh</code></dt>
<dd>remote login (secure shell)
</dd>
<dt><code>scp</code></dt>
<dd>secure copy (remote file copy); uses <code>ssh</code>
</dd>
<dt><code>ps</code></dt>
<dd>show process status of running processes
</dd>
<dt><code>kill</code></dt>
<dd>kill a process, e.g., <code>kill -9 14238</code>
</dd>
</dl>
</ul>
</body>
</html>