forked from SciLifeLab/courses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunix1.html
186 lines (181 loc) · 9.57 KB
/
unix1.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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> UNIX Tutorial One</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Copyright" content="Michael Stonebank, 1995-2003" />
<link href="unixtut2.css" rel="stylesheet" type="text/css" />
<link href="unixtut2-print.css" rel="stylesheet" type="text/css" media="print" />
</head>
<body>
<div id="container">
<h2>A copy from <a href="http://www.ee.surrey.ac.uk/Teaching/Unix/"><font color="lightgrey">UNIX Tutorial for Beginners</font></a> with modified paths<br>Please use <a href="http://www.uppnex.se/emu/"><font color="lightgrey">this terminal emulator</font></a> when doing the exercises!</h2>
<h1>UNIX Tutorial One </h1>
<h2>1.1 Listing files and directories </h2>
<p>
<span style="color:red">
<b>NOTE:</b>
Terminals can have many different appearances, which can be confusing in the beginning.
The thing all the appearances have in common is that they have 'strange character' as indicator of the line where you type stuff.
In this exercises they use the percent character, %, and in the terminal emulator they have chosen the brackets character, # .
Most commonly used is the dollar character, $ .
</span>
</p>
<h3>ls (list) </h3>
<p> When you first login, your current working directory is your home directory.
Your home directory has the same name as your user-name, for example, <b>ee91ab</b>,
and it is where your personal files and subdirectories are saved. </p>
<p> To find out what is in your home directory, type </p>
<p class="cli">% ls </p>
<p>The <span class="command">ls</span> command ( lowercase L and lowercase S ) lists the contents of your current working directory.</p>
<p align="center"> <img src="media/unix-xterm1.gif" alt="Unix Terminal - running the ls command" width="491" height="269" /></p>
<p>There may be no files visible in your home directory, in which case, the UNIX
prompt will be returned. Alternatively, there may already be some files inserted
by the System Administrator when your account was created. </p>
<p><span class="command">ls</span> does not, in fact, cause all the files in your home directory
to be listed, but only those ones whose name does not begin with a dot (.) Files
beginning with a dot (.) are known as hidden files and usually contain important
program configuration information. They are hidden because you should not change
them unless you are very familiar with UNIX!!! </p>
<p> To list all files in your home directory including those whose names begin
with a dot, type </p>
<p class="cli">% ls -a</p>
<p>As you can see, <span class="command">ls -a</span> lists files that are normally hidden. </p>
<p align="center"><img src="media/unix-xterm2.gif" alt="Unix Terminal - running the ls command" width="491" height="269" /> </p>
<p><span class="command">ls</span> is an example of a command which can take options: <b>-a</b>
is an example of an option. The options change the behaviour of the command.
There are online manual pages that tell you which options a particular command
can take, and how each option modifies the behaviour of the command. (See later
in this tutorial) </p>
<h2>1.2 Making Directories </h2>
<h3>mkdir (make directory) </h3>
<p> We will now make a subdirectory in your home directory to hold the files you
will be creating and using in the course of this tutorial. To make a subdirectory
called unixstuff in your current working directory type </p>
<p class="cli">% mkdir unixstuff </p>
<p> To see the directory you have just created, type </p>
<p class="cli">% ls </p>
<h2>1.3 Changing to a different directory </h2>
<h3>cd (change directory)</h3>
<p> The command <span class="command">cd <var>directory</var></span> means change the current
working directory to <i>'directory'</i>. The current working directory may be thought
of as the directory you are in, i.e. your current position in the file-system
tree. </p>
<p> To change to the directory you have just made, type </p>
<p class="cli">% cd unixstuff </p>
<p> Type <span class="command">ls</span> to see the contents (which should be empty) </p>
<h3>Exercise 1a</h3>
<p>Make another directory inside the <strong>unixstuff</strong> directory called
<strong>backups</strong> </p>
<h2>1.4 The directories . and .. </h2>
<p>Still in the <strong>unixstuff</strong> directory, type </p>
<p class="cli"> % ls -a </p>
<p> As you can see, in the <strong>unixstuff</strong> directory (and in all other
directories), there are two special directories called (<strong>.</strong>)
and (<strong>..</strong>)</p>
<h3>The current directory (.) </h3>
<p>In UNIX, (<strong>.</strong>) means the current directory, so typing </p>
<p class="cli"> % cd . </p>
<p class="hint">NOTE: there is a space between cd and the dot</p>
<p> means stay where you are (the <strong>unixstuff</strong> directory). </p>
<p>This may not seem very useful at first, but using (<strong>.</strong>) as the
name of the current directory will save a lot of typing, as we shall see later
in the tutorial. </p>
<h3>The parent directory (..) </h3>
<p> (<strong>..</strong>) means the parent of the current directory, so typing
</p>
<p class="cli"> % cd .. </p>
<p> will take you one directory up the hierarchy (back to your home directory).
Try it now. </p>
<p> Note: typing <span class="command">cd</span> with no argument always returns you to your home
directory. This is very useful if you are lost in the file system. </p>
<h2>1.5 Pathnames </h2>
<h3>pwd (print working directory) </h3>
<p> Pathnames enable you to work out where you are in relation to the whole file-system.
For example, to find out the absolute pathname of your home-directory, type
<span class="command">cd</span> to get back to your home-directory and then type </p>
<p class="cli"> % pwd </p>
<p> The full pathname will look something like this - </p>
<p class="output"> <strong>/home/its/ug1/ee51vn</strong></p>
<p> which means that <b>ee51vn</b> (your home directory) is in the sub-directory <b>ug1</b> (the group directory),which in turn is located in the <b>its</b> sub-directory, which is in the <b>home</b> sub-directory, which is in the top-level root directory called " <i>/ " </i>. </p>
<p align="center"><img src="media/unix-tree.png" alt="Unix File structure" width="560" height="316" /></p>
<h3>Exercise 1b</h3>
<p>Use the commands <span class="command">cd,</span> <span class="command">ls</span> and <span class="command">pwd</span> to explore
the file system. </p>
<p> (Remember, if you get lost, type <span class="command">cd</span> by itself to return to your
home-directory) </p>
<h2>1.6 More about home directories and pathnames </h2>
<h3>Understanding pathnames</h3>
<p>First type cd to get back to your home-directory, then type</p>
<p class="cli"> % ls unixstuff</p>
<p>to list the conents of your unixstuff directory.</p>
<p>Now type </p>
<p class="cli"> % ls backups</p>
<p> You will get a message like this - </p>
<p class="output"> backups: No such file or directory </p>
<p> The reason is, <strong>backups</strong> is not in your current working directory.
To use a command on a file (or directory) not in the current working directory
(the directory you are currently in), you must either <span class="command">cd</span> to the
correct directory, or specify its full pathname. To list the contents of your
backups directory, you must type </p>
<p class="cli"> % ls unixstuff/backups </p>
<p> </p>
<h3>~ (your home directory) </h3>
<p>Home directories can also be referred to by the tilde <strong>~</strong> character.
It can be used to specify paths starting at your home directory. So typing </p>
<p class="cli"> % ls ~/unixstuff</p>
<p> will list the contents of your unixstuff directory, no matter where you currently
are in the file system. </p>
<p> What do you think </p>
<p class="cli"> % ls ~</p>
<p> would list? </p>
<p> What do you think </p>
<p class="cli"> % ls ~/.. </p>
<p> would list? </p>
<h2>Summary </h2>
<table border="1" align="center" cellpadding="5" cellspacing="0">
<tr>
<th>Command</th>
<th>Meaning</th>
</tr>
<tr>
<td class="command">ls</td>
<td>list files and directories</td>
</tr>
<tr>
<td class="command">ls -a</td>
<td>list all files and directories</td>
</tr>
<tr>
<td class="command">mkdir</td>
<td>make a directory</td>
</tr>
<tr>
<td class="command">cd <i>directory</i></td>
<td>change to named directory</td>
</tr>
<tr>
<td class="command">cd</td>
<td>change to home-directory</td>
</tr>
<tr>
<td class="command">cd ~</td>
<td>change to home-directory</td>
</tr>
<tr>
<td class="command">cd ..</td>
<td>change to parent directory</td>
</tr>
<tr>
<td class="command">pwd</td>
<td>display the path of the current directory</td>
</tr>
</table>
<p align="center" class="navbar"><a href="unixintro.html"><img src="media/left.gif" alt="Previous" width="37" height="39" border="0" /></a>
<a href="index.html"><img src="media/home.gif" alt="Home" width="81" height="39" border="0" /></a><a href="unix2.html"><img src="media/right.gif" alt="Next" width="37" height="39" border="0" /></a></p>
<p align="center"><iframe src="http://rcm.amazon.com/e/cm?t=unixtutorialf-20&o=1&p=13&l=ur1&category=home&banner=1KCJXE8FXDSDTBZ6SWG2&f=ifr" width="468" height="60" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe></p>
<p class="date">M.Stonebank@surrey.ac.uk, © 9th October 2000 </p>
</div>
</body>
</html>