summaryrefslogtreecommitdiffstats
path: root/chapter_04.xml
blob: 96cb46c3010158baf2f62af690d1feaa95f2cda7 (plain)
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
<?xml version="1.0"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  "/usr/share/xml/docbook/xml-dtd-4.5/docbookx.dtd">

<chapter>
<title>Basic Shell Commands</title>

<!-- ls, cd, mkdir, touch, rmdir, rm, file -->

<para>
So you've installed Slackware and you're staring at a terminal prompt,
what now?  Now would be a good time to learn about the basic command
line tools.  And since you're staring at a blinking curser, you
probably need a little assistance in knowing how to get around, and
that is what this chapter is all about.
</para>

<section>
<title>System Documentation</title>

<para>
Your Slackware Linux system comes with lots of built-in documentation
for nearly every installed application.  Perhaps the most common method
of reading system documentation is by using the
<application>man</application>(1).  <application>man</application>
(short for manual) will bring up the included man-page for any
application, system call, configuration file, or library you tell it
too.  For example, <userinput>man man</userinput> will bring up the
man-page for <application>man</application> itself.
</para>

<para>
Unfortunately, you may not always know what application you need to use
for the task at hand.  Thankfully, <application>man</application> has
built-in search abilities.  Using the <arg>-k</arg> switch
will cause <application>man</application> to search for every man-page
that matches your search terms.
</para>

<para>
The man-pages are organized into groups or sections by their content
type.  For example, section 1 is for user applications.
<application>man</application> will search each section in order and
display the first match it finds.  Sometimes you will find that a
man-page exists in more than one section for a given entry.  In that
case, you will need to specify the exact section to look in.  In this
book, all applications and a number of other things will have a number
on their right-hand side in parenthesis.  This number is the man page
section where you will find information on that tool.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>man -k printf</userinput>
printf               (1)  - format and print data
printf               (3)  - formatted output conversion
<prompt>darkstar:~$ </prompt><userinput>man 3 printf</userinput>
</screen>

<table pgwide="0" frame="none">
<title>Man Page Sections</title>
<tgroup cols="2">
  <thead>
    <row>
      <entry>Section</entry>
      <entry align="right">Contents</entry>
    </row>
  </thead>
  <tbody>
    <row>
      <entry>1</entry>
      <entry align="right">User Commands</entry>
    </row>
    <row>
      <entry>2</entry>
      <entry align="right">System Calls</entry>
    </row>
    <row>
      <entry>3</entry>
      <entry align="right">C Library Calls</entry>
    </row>
    <row>
      <entry>4</entry>
      <entry align="right">Devices</entry>
    </row>
    <row>
      <entry>5</entry>
      <entry align="right">File Formats / Protocols</entry>
    </row>
    <row>
      <entry>6</entry>
      <entry align="right">Games</entry>
    </row>
    <row>
      <entry>7</entry>
      <entry align="right">Conventions / Macro Packages</entry>
    </row>
    <row>
      <entry>8</entry>
      <entry align="right">System Administration</entry>
    </row>
    <row>
      <entry>9</entry>
      <entry>Kernel API Descriptions</entry>
    </row>
    <row>
      <entry>n</entry>
      <entry>"New" - typically used to Tcl/Tk</entry>
    </row>
  </tbody>
</tgroup>
</table>

</section>

<section>
<title>Dealing with Files and Directories</title>


<section>
<title><application>Listing Files and Directory Contents</application></title>

<para>
<application>ls</application>(1) is used to list files and directories,
their permissions, size, type, inode number, owner and group, and
plenty of additional information.  For example, let's list what's in
the <filename>/</filename> directory for your new Slackware Linux system.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>ls /</userinput>
bin/   dev/  home/  lost+found/  mnt/  proc/  sbin/  sys/  usr/
boot/  etc/  lib/   media/       opt/  root/  srv/   tmp/  var/
</screen>

<para>Notice that each of the listings is a directory.  These are
easily distinguished from regular files due to the trailing /; standard
files do not have a suffix.  Additionally, executable files will have an
asterisk suffix.  But <application>ls</application> can do so much
more.  To get a view of the permissions of a file or directory, you'll
need to do a "long list".
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>ls -l /home/alan/Desktop</userinput>
-rw-r--r-- 1 alan users 15624161 2007-09-21 13:02 9780596510480.pdf
-rw-r--r-- 1 alan users  3829534 2007-09-14 12:56 imgscan.zip
drwxr-xr-x 3 alan root       168 2007-09-17 21:01 ipod_hack/
drwxr-xr-x 2 alan users      200 2007-12-03 22:11 libgpod/
drwxr-xr-x 2 alan users      136 2007-09-30 03:16 playground/
</screen>

<para>
A long listing lets you view the permisions, user and group ownership,
file size, last modified date, and of course, the file name itself.
Notice that the first two entires are files, and the last three are
directories.  This is denoted by the very first character on the line.
Regular files get a "-"; directories get a "d".  There are several
other file types with their own denominators.  Symbolic links for
example will have an "l".
</para>

<para>
Lastly, we'll show you how to list dot-files, or hidden files.  Unlike
other operating systems such as Microsoft Windows, there is no special
property that differentiates "hidden" files from "unhidden" files.  A
hidden file simply begins with a dot.  To display these files along
with all the others, you just need to pass the <arg>-a</arg> argument to
<application>ls</application>.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>ls -a</userinput>
.xine/    .xinitrc-backup  .xscreensaver  .xsession-errors  SBo/
.xinitrc  .xinitrc-xfce    .xsession      .xwmconfig/       Shared/
</screen>

<para>
You also likely noticed that your files and directories appear in
different colors.  Many of the enhanced features of
<application>ls</application> such as these colors or the trailing
characters indicating file-type are special features of the
<application>ls</application> program that are turned on by passing
various arguments.  As a convienience, Slackware sets up
<application>ls</application> to use many of these optional arguments
by default.  These are controlled by the LS_OPTIONS and LS_COLORS
environment variables.  We will talk more about environment variables
in chapter 5.
</para>

</section>

<section>
<title>Moving Around the Filesystem</title>

<para>
<application>cd</application> is the command used to change
directories.  Unlike most other commands, <application>cd</application>
is actually not it's own program, but is a shell built-in.  Basically,
that means <application>cd</application> does not have its own man
page.  You'll have to check your shell's documentation for more details
on the <application>cd</application> you may be using.  For the most
part though, they all behave the same.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>cd /</userinput>
<prompt>darkstar:/$</prompt><userinput>ls</userinput>
bin/   dev/  home/  lost+found/  mnt/  proc/  sbin/  sys/  usr/
boot/  etc/  lib/   media/       opt/  root/  srv/   tmp/  var/
<prompt>darkstar:/$</prompt><userinput>cd /usr/local</userinput>
<prompt>darkstar:/usr/local$</prompt>
</screen>

<para>
Notice how the prompt changed when we changed directories?  The default
Slackware shell does this as a quick, easy way to see your current
directory, but this is not actually a function of
<application>cd</application>.  If your shell doesn't operate in this
way, you can easily get your current working directory with the
<application>pwd</application>(1) command.  (Most UNIX shells have
configurable prompts that can be coaxed into providing this same
functionality.  In fact, this is another convience setup in the default
shell for you by Slackware.)
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>pwd</userinput>
/usr/local
</screen>

</section>

<section>
<title>File and Directory Creation and Deletion</title>

<para>
While most applications can and will create their own files and
directories, you'll often want to do this on your own.  Thankfully,
it's very easy using <application>touch</application>(1) and
<application>mkdir</application>(1).
</para>

<para>
<application>touch</application> actually modifies the timestamp on a
file, but if that file doesn't exist, it will be created.
</para>

<screen><prompt>darkstar:~/foo$ </prompt><userinput>ls -l</userinput>
-rw-r--r-- 1 alan users 0 2008-01-18 15:01 bar1
<prompt>darkstar:~/foo$ </prompt><userinput>touch bar2</userinput>
-rw-r--r-- 1 alan users 0 2008-01-18 15:01 bar1
-rw-r--r-- 1 alan users 0 2008-01-18 15:05 bar2
<prompt>darkstar:~/foo$ </prompt><userinput>touch bar1</userinput>
-rw-r--r-- 1 alan users 0 2008-01-18 15:05 bar1
-rw-r--r-- 1 alan users 0 2008-01-18 15:05 bar2
</screen>

<para>
Note how <filename>bar2</filename> was created in our second command,
and the third command simpl updated the timestamp on
<filename>bar1</filename>
</para>

<para>
<application>mkdir</application> is used for (obviously enough) making
directories.  <userinput>mkdir foo</userinput> will create the
directory "foo" within the current working directory.  Additionally,
you can use the <arg>-p</arg> argument to create any
missing parent directories.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>mkdir foo</userinput>
<prompt>darkstar:~$ </prompt><userinput>mkdir /slack/foo/bar/</userinput>
mkdir: cannot create directory `/slack/foo/bar/': No such file or directory
<prompt>darkstar:~$ </prompt><userinput>mkdir -p /slack/foo/bar/</userinput>
</screen>

<para>
In the latter case, <application>mkdir</application> will first create
"/slack", then "/slack/foo", and finally "/slack/foo/bar".  If you
failed to use the <arg>-p</arg> argument,
<application>man</application> would fail to create "/slack/foo/bar"
unless the first two already existed, as you saw in the example.
</para>

<para>
Removing a file is as easy as creating one.  The
<application>rm</application>(1) will remove a file (assuming of course
that you have permission to do this).  There are a few very common
arguments to <application>rm</application>.  The first is
<arg>-f</arg> and is used to force the removal of a file
that you may lack explicit permission to delete.  The
<arg>-r</arg> argument will remove directories and their
contents recursively.
</para>

<para>
There is another tool to remove directories, the humble
<application>rmdir</application>(1).  <application>rmdir</application>
will only remove directories that are empty, and complain noisely about
those that contain files or sub-directories.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>ls</userinput>
foo_1/ foo_2/
<prompt>darkstar:~$ </prompt><userinput>ls foo_1</userinput>
bar_1
<prompt>darkstar:~$ </prompt><userinput>rmdir foo_1</userinput>
rmdir: foo/: Directory not empty
<prompt>darkstar:~$ </prompt><userinput>rm foo_1/bar</userinput>
<prompt>darkstar:~$ </prompt><userinput>rmdir foo_1</userinput>
<prompt>darkstar:~$ </prompt><userinput>ls foo_2</userinput>
bar_2/
<prompt>darkstar:~$ </prompt><userinput>rm -fr foo_2</userinput>
<prompt>darkstar:~$ </prompt><userinput>ls</userinput>
</screen>

</section>

</section>

<section>
<title>Archive and Compression</title>

<para>
Everyone needs to package a lot of small files together for easy
storage from time to time, or perhaps you need to compress very large
files into a more manageable size? Maybe you want to do both of those
together? Thankfully there are several tools to do just that.
</para>

<section>
<title>zip and unzip</title>

<para>
You're probably familiar with .zip files. These are compressed files
that contain other files and directories. While we don't normally use
these files in the Linux world, they are still commonly used by other
operating systems, so we occasionally have to deal with them.
</para>

<para>
In order to create a zip file, you'll (naturally) use the
<application>zip</application>(1) command. You can compress either
files or directories (or both) with <application>zip</application>, but
you'll have to use the <arg>-r</arg> argument for recursive action in
order to deal with directories.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>zip -r /tmp/home.zip /home</userinput>
<prompt>darkstar:~$ </prompt><userinput>zip /tmp/large_file.zip
/tmp/large_file</userinput></screen>

<para>
The order of the arguments is very important. The first filename must
be the zip file to create (if the .zip extension is ommitted,
<application>zip</application> will add it for you) and the rest are
files or directories to be added to the zip file.
</para>

<para>
Naturally, <application>unzip</application>(1) will decompress a zip
archive file.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>unzip /tmp/home.zip</userinput></screen>

</section>

<section>
<title>gzip</title>

<para>
One of the oldest compression tools included in Slackware is
<application>gzip</application>(1), a compression tool that is only
capable or operating on a single file at a time. Whereas
<application>zip</application> is both a compression and an archival
tool, <application>gzip</application> is only capable of compression.
At first glance this seems like a draw-back, but it is really a
strength. The UNIX philosophy of making small tools that do their small
jobs well allows them to be combined in myriad ways. In order to
compress a file (or multiple files), simply pass them as arguments to
<application>gzip</application>. Whenever
<application>gzip</application> compresses a file, it adds a .gz
extension and removes the original file.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>gzip /tmp/large_file</userinput></screen>

<para>
Decompressing is just as straight-forward with
<application>gunzip</application> which will create a new uncompressed
file and delete the old one.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>gunzip /tmp/large_file.gz</userinput>
<prompt>darkstar:~$ </prompt><userinput>ls /tmp/large_file*</userinput>
/tmp/large_file</screen>

<para>
But suppose we don't want to delete the old compressed file, we just
want to read its contents or send them as input to another program?
The <application>zcat</application> program will read the gzip file,
decompress it in memory, and send the contents to the standard output
(the terminal screen unless it is redirected, see the next chapter for
more details on output redirection).
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>zcat /tmp/large_file.gz</userinput>
Wed Aug 26 10:00:38 CDT 2009
Slackware 13.0 x86 is released as stable!  Thanks to everyone who helped
make this release possible -- see the RELEASE_NOTES for the credits.
The ISOs are off to the replicator.  This time it will be a 6 CD-ROM
32-bit set and a dual-sided 32-bit/64-bit x86/x86_64 DVD.  We're taking
pre-orders now at store.slackware.com.  Please consider picking up a copy
to help support the project.  Once again, thanks to the entire Slackware
community for all the help testing and fixing things and offering
suggestions during this development cycle.
</screen>

</section>

<section>
<title>bzip2</title>

<para>
One alternative to <application>gzip</application> is the
<application>bzip2</application>(1) compression utility which works in
almost the exact same way.  The advantage to
<application>bzip2</application> is that it boasts greater compression
strength. Unfortunately, achieving that greater compression is a slow
process, so <application>bzip2</application> takes longer to run than
other alternatives.
</para>

</section>

<section>
<title>LZMA</title>

<para>
The latest compression utility added to Slackware is
<application>xz</application>, which impliments the LZMA compression
algorithm. This is faster than <application>bzip2</application> and
often compresses better as well. In fact, its blend of speed and
compression strength caused it to replace
<application>gzip</application> as the compression scheme of choice for
Slackware.  Unfortuantely, <application>xz</application> does not have
a man page at the time of this writing, so to view available options,
use the <arg>--help</arg> argument.  Compressing files is accomplished
with the <arg>-z</arg> argument, and decompression with <arg>-d</arg>.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>xz -z /tmp/large_file</userinput></screen>

</section>

<section>
<title>tar</title>

<para>
So great, we know how to compress files using all sorts of programs,
but none of them can archive files in the way that
<application>zip</application> does.  That is until now.  The Tape
Archiver, or <application>tar</application>(1) is the most frequently
used archival program in Slackware. Like other archival programs,
<application>tar</application> generates a new file that contains other
files and directories. It does not compress the generated file (often
called a "tarball") by default; however, the version of
<application>tar</application> included in Slackware supports a variety
of compression schemes, including the ones mentioned above.
</para>

<para>
Invoking <application>tar</application> can be as easy or as
complicated as you like. Typically, creating a tarball is done with the
<arg>-cvzf</arg> arguments.  Let's look at these in depth.
</para>

<table pgwide="0" frame="none">
<title>tar Arguments</title>
<tgroup cols="2">
  <thead>
    <row>
      <entry>Argument</entry>
      <entry align="right">Meaning</entry>
    </row>
  </thead>
  <tbody>
    <row>
      <entry>c</entry>
      <entry align="right">Create a tarball</entry>
    </row>
    <row>
      <entry>x</entry>
      <entry align="right">Extract the contents of a tarball</entry>
    </row>
    <row>
      <entry>t</entry>
      <entry align="right">Display the contents of a tarball</entry>
    </row>
    <row>
      <entry>v</entry>
      <entry align="right">Be more verbose</entry>
    </row>
    <row>
      <entry>z</entry>
      <entry align="right">Use gzip compression</entry>
    </row>
    <row>
      <entry>j</entry>
      <entry align="right">Use bzip2 compression</entry>
    </row>
    <row>
      <entry>J</entry>
      <entry align="right">Use LZMA compression</entry>
    </row>
    <row>
      <entry>p</entry>
      <entry align="right">Preserve permissions</entry>
    </row>
  </tbody>
</tgroup>
</table>

<para>
<application>tar</application> requires a bit more precision than other
applications in the order of its arguments.  The <arg>-f</arg> argument
must be present when reading or writing to a file for example, and the
very next thing to follow must be the filename. Consider the following
examples.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>tar -xvzf /tmp/tarball.tar.gz</userinput>
<prompt>darkstar:~$ </prompt><userinput>tar -xvfz /tmp/tarball.tar.gz</userinput></screen>

<para>
Above, the first example works as you would expect, but the second
fails because <application>tar</application> has been instructed to
open the <filename>z</filename> file rather than the expected
<filename>/tmp/tarball.tar.gz</filename>.
</para>

<para>
Now that we've got our arguments straightened out, lets look at a few
examples of how to create and extract tarballs. As we've noted, the
<arg>-c</arg> argument is used to create tarballs and <arg>-x</arg>
extracts their contents. If we want to create or extract a compressed
tarball though, we also have to specify the proper compression to use.
Naturally, if we don't want to compress the tarball at all, we can
leave these options out. The following command creates a new tarball
using the <application>gzip</application> compression alogrithm. While
it's not a strict requirement, it's also good practice to add the .tar
extension to all tarballs as well as whatever extension is used by the
compression algorithm.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>tar -czf /tmp/tarball.tar.gz /tmp/tarball/</userinput></screen>

</section>

</section>

<section>
<title>Reading Documents</title>

<para>
Traditionally, UNIX and UNIX-like operating systems are filled with
text files that at some point in time the system's users are going to
want to read.  Naturally, there are plenty of ways of reading these
files, and we'll show you the most common ones.
</para>

<para>
In the early days, if you just wanted to see the contents of a file
(any file, whether it was a text file or some binary program) you would
use <application>cat</application>(1) to view them.
<application>cat</application> is a very simple program, which takes
one or more files, concatenates them (hence the name) and sends them to
the standard output, which is usually your terminal screen.  This was
fine when the file was small and wouldn't scroll off the screen, but
inadequate for larger files as it had no built-in way of moving within
a document and reading it a paragraph at a time.  Today,
<application>cat</application> is still used quite extensively, but
predominately in scripts or for joining two or more files into one.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>cat /etc/slackware-version</userinput>
Slackware 12.0.0
</screen>

<para>
Given the limitations of <application>cat</application> some very
intelligent people sat down and began to work on an application to let
them read documents one page at a time.  Naturally, such applications
began to be known as "pagers".  One of the earliest of these was
<application>more</application>(1), named because it would let you see
"more" of the file whenever you wanted.  <application>more</application>
will display the first few lines of a text file until your screen is
full, then pause.  Once you've read through that screen, you can
proceed down one line by pressing ENTER, or an entire screen by
pressing SPACE.  <application>more</application> is also capable of
searching through a text file for keywords.  Once you've displayed a
file in <application>more</application>, simply press the / key and
enter a keyword.  Upon pressing ENTER, the text will scroll until it
finds the next match.  This is clearly a big improvement over
<application>cat</application>, but still suffers from a serious flaw:
<application>more</application> is not able to scroll back up through
the file to allow you to read something you might have missed.  Clearly
a better solution is called for.
</para>

<para>
In order to address the short-comings of
<application>more</application>, a new pager was developed and
ironically dubbed <application>less</application>(1).
<application>less</application> is a very powerful pager that supports
all of the functions of <application>more</application> while adding
lots of additional features.  To begin with,
<application>less</application> allows you to use your arrow keys to
controll movement within the document.  Due to its popularity, many
Linux distributions have begun to exclude
<application>more</application> in favor of
<application>less</application>.  Slackware includes both.  Moreover,
Slackware also includes a handy little pre-processor for
<application>less</application> called
<filename>lesspipe.sh</filename>.  This allows a user to exectute
<application>less</application> on a number of non-text files.
<filename>lesspipe.sh</filename> will generate text output from running
a command on these files, and display it in
<application>less</application>.
</para>

</section>

<section>
<title>Linking</title>

<para>
Links are a method of referring to one file by more than one name.  By
using the <application>ln</application>(1) application, a user can
reference one file with more than one name.  The two files are not
carbon-copies of one another, but rather are the exact same file, just
with a different name.  To remove the file entirely, all of its names
must be deleted.  (This is actually the result of the way that
<application>rm</application> and other tools like it work.  Rather
than remove the contents of the file, they simply remove the reference
to the file, freeing that space to be re-used.
<application>ln</application> will create a second reference or "link"
to that file.)
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>ln /etc/slackware-version foo</userinput>
<prompt>darkstar:~$ </prompt><userinput>cat foo</userinput>
Slackware 12.0.0
<prompt>darkstar:~$ </prompt><userinput>ls -l /etc/slackware-version foo</userinput>
-rw-r--r-- 1 root root 17 2007-06-10 02:23 /etc/slackware-version
-rw-r--r-- 1 root root 17 2007-06-10 02:23 foo
</screen>

<para>
Another type of link exists, the symlink.  Symlinks, rather than being
another reference to the same file, are actually a special kind of file
in their own right.  These symlinks point to another file or directory.
The primary advantage of symlinks is that they can refer to directories
as well as files, and they can span multiple filesystems.  These are
created with the <arg>-s</arg> argument.
</para>

<screen><prompt>darkstar:~$ </prompt><userinput>ln -s /etc/slackware-version foo</userinput>
<prompt>darkstar:~$ </prompt><userinput>cat foo</userinput>
Slackware 12.0.0
<prompt>darkstar:~$ </prompt><userinput>ls -l /etc/slackware-version foo</userinput>
-rw-r--r-- 1 root root 17 2007-06-10 02:23 /etc/slackware-version
lrwxrwxrwx 1 root root 22 2008-01-25 04:16 foo -> /etc/slackware-version
</screen>

<para>
When using symlinks, remember that if the original file is deleted,
your symlink is useless; it simply points at a file that doesn't exist
anymore.
</para>

</section>

</chapter>