Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Complete Idiot's Guide to Linux
(Publisher: Macmillan Computer Publishing)
Author(s): Manuel Ricart
ISBN: 078971826x
Publication Date: 12/22/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Creating Links: ln

Links are created using the ln command. ln is used to create both soft and hard links. The syntax for the command is

     ln [options] source destination

To create a symbolic (soft) link, you specify the -s option, which stands for symbolic. Here’s an example for listing a directory:

     [alberto@digital alberto]$ ls -l
     total 2
     drwxrwxr-x   3 alberto  alberto      1024 Aug  1 20:41 adir/
     -rw-rw-r--   1 alberto  alberto        57 Aug  2 13:12 file

Here’s an example for creating a hard link:

     [alberto@digital alberto]$ ln file file2

Here’s one for creating a soft link:

     [alberto@digital alberto]$ ln -s file file3

Here is the syntax for listing directory again. Notice that file3 points to file:

     [alberto@digital alberto]$ ls -l
     total 3
     drwxrwxr-x   3 alberto  alberto      1024 Aug  1 20:41 adir/
     -rw-rw-r--   2 alberto  alberto        57 Aug  2 13:12 file
     -rw-rw-r--   2 alberto  alberto        57 Aug  2 13:12 file2
     lrwxrwxrwx   1 alberto  alberto         4 Aug  2 13:15 file3 -> file

Here is the syntax for deleting the original file:

     [alberto@digital alberto]$ rm file

Here is the syntax for listing again. Notice that file3 now points to a file that doesn’t exist!

     [alberto@digital alberto]$ ls -l
     total 2
     drwxrwxr-x   3 alberto  alberto      1024 Aug  1 20:41 adir/
     -rw-rw-r--   1 alberto  alberto        57 Aug  2 13:12 file2
     lrwxrwxrwx   1 alberto  alberto         4 Aug  2 13:15 file3 -> file

Links are used often in Linux to allow files to be placed in many directories at once. For example, the directory /usr/X11R6 contains files used by X Windows. Some older X Windows programs install into /usr/X11R5 or /usr/X11R4 instead. Through a series of symbolic links, Linux can make files from all three directories appear in a more general X Windows directory, /usr/X11, for easy access. This type of organizing is one of the primary uses for symbolic links.

Reading Files

Being able to move and organize files is an important skill. In the end, computers are primarily for storing and retrieving information. Here are a few commands that you can use for reading files when on a terminal:

  cat: Copy the contents of a file to a terminal
  less: Page the contents a screen at a time
  head: Peek at the first few lines in a file
  tail: Peek at the last few lines in a file

Concatenating: cat

The cat command reads one or more files and prints the result to the screen. (It concatenates all files to the screen.) cat is a generic command, and it is used very frequently when chaining multiple commands together. When we explore redirection in Chapter 14, “Putting the Shell to Work,” I’ll show you how the cat is really used.

The basic syntax of cat is

     cat [options] files

Here’s an example of using cat to view the /etc/passwd file (this is the file where information about users is kept):

     [alberto@digital alberto]$ cat /etc/passwd
     root:UGQDnB4s/nDAk:0:0:root:/root:/bin/bash
     bin:*:1:1:bin:/bin:
     daemon:*:2:2:daemon:/sbin:
     adm:*:3:4:adm:/var/adm:
     lp:*:4:7:lp:/var/spool/lpd:
     sync:*:5:0:sync:/sbin:/bin/sync
     shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown
     halt:*:7:0:halt:/sbin:/sbin/halt
     mail:*:8:12:mail:/var/spool/mail:
     news:*:9:13:news:/var/spool/news:
     uucp:*:10:14:uucp:/var/spool/uucp:
     operator:*:11:0:operator:/root:
     games:*:12:100:games:/usr/games:
     gopher:*:13:30:gopher:/usr/lib/gopher-data:
     ftp:*:14:50:FTP User:/home/ftp:
     nobody:*:99:99:Nobody:/:
     postgres:!:100:101:PostreSQL Server:/var/lib/pgsql:/bin/bash
     alberto:YMMhuMSru1hME:501:501:AlbertoRicart:/home/alberto:/bin/bash

As you can see, cat opened the file /etc/passwd and printed every line to the console.

The cat command offers several options; the most useful are listed in Table 12.1.

Table 12.1 cat Command Options

Option Description

-n Number all lines
-s Squeeze multiple blank lines into one
-v Display all characters (invisible characters, too, with the exception of tabs and newlines)
-A Display all characters (invisible characters, too)


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.