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


Making Shell Options the Default

If you found any of these options useful, more than likely you will want to make them the default. When you run a shell, there are a number of environment variables that control how your shell behaves. For the bash shell, the default shell in Linux, this default information lives on the /etc/profile file.

You can override some of the options by adding entries to the .bashrc file in your home directory. Because this filename starts with a dot, it’s invisible by default (and called a dot file—and you thought Linux names would be difficult!), but it is there. To make ls work in color by default, add an entry like this to the end of your .bashrc file. (Use KEdit because you don’t know how to use a command line editor, yet.) Here are some examples:

     alias ls=’ls --color’

To make ls use the -F option, add a line like this:

     alias ls=’ls -F’

To make ls use both the -F and --color options, add a line like this:

     alias ls=’ls -F --color’

As you can guess, alias associates a name with a command. To make an alias in bash, you use the keyword alias followed the name of the alias followed by an equal (=) sign, followed by the name of the command. If the command is longer than one word (that is, it has arguments), you need to enclose the command and its arguments in apostrophes (). You can use any name for the alias you like. If the name of the alias is the same as some system command, the alias is the command executed.

Check out your .bashrc to see what aliases have already been defined for you.

Changing Directories: cd

Now that you know how to find out where you are and list the files in a directory, it is time to learn how to go somewhere. To do so, you use the cd command. cd stands for change directory. To go somewhere, type the cd command followed by the name of the directory where you want to go:

     [alberto@digital alberto]$ cd /
     [alberto@digital /]$ ls
     amd/         dev/         install@     opt/         tmp/
     auto/        etc/         lib/         proc/        usr/
     bin/         home/        lost+found/  root/        var/
     boot/        initrd/      mnt/         sbin/        vmlinuz

This example takes you to the root (/) directory.

To return to your home directory, type the cd command without any arguments:

     [alberto@digital /]$ cd
     [alberto@digital alberto]$ ls
     Desktop/       images/        linkToImages@  test.txt
     Mail/          kde/           nsmail/        test.txt∼
     html/          lg/            test.rc        todo.txt

Relative and Absolute Paths

If you don’t provide a leading slash (/) in the path you specify, the path is relative. The shell will append the current working directory to the path you specify, as in the following:

      [alberto@digital alberto]$ cd images/anotherdir
     [alberto@digital anotherdir]$ pwd
     /home/alberto/images/anotherdir

If the directory images is located in /home/alberto/images, the first line is equivalent to specifying this:

     cd /home/alberto/images/anotherdir

When specifying a relative path, it is useful to know that the current directory can be specified using a period (.) and the parent directory, the directory containing the current directory, as two periods (..), given a directory structure like this:

      [alberto@digital alberto]$ ls
     Desktop/       images/        linkToImages@  test.txt
     Mail/          kde/           nsmail/        test.txt∼
     html/          lg/            test.rc        todo.txt

     [alberto@digital alberto]$ cd images (goes down to images)
     [alberto@digital images]$ pwd 
     /home/alberto/images
     [alberto@digital images]$ cd ../kde (up one and down kde)
     [alberto@digital kde]$ pwd
     /home/alberto/kde
     [alberto@digital kde]$ cd .. (up one)
     [alberto@digital alberto]$ cd ./kde (down kde in the current dir)
     [alberto@digital kde]$ pwd
     /home/alberto/kde


Techno Talk:  The PATH Environment Variable
The shell looks for commands and programs in a list of file paths stored in the PATH environment variable. An environment variable stores information in a place where other programs and commands can access it. Environment variables store information such as the shell you are using, your login name, and your current working directory. To see a list of all the environment variables currently defined, type set at the prompt.

When you type a command at the shell prompt, the shell will look for that command’s program file in each directory listed in the PATH variable, in order. The first program found matching the command you typed will be run. If the command’s program file is not in a directory listed in your PATH environment variable, the shell returns a “command not found” error.

By default, the shell does not look in your current working directory or your home directory for commands. This is really a security mechanism so that you don’t execute programs by accident. What if a malicious user put a harmful program called ls in your home directory? If you typed ls and the shell looked for the fake program in your home directory before the real program in the /bin directory, what do you think would happen? If you thought bad things, you are on the right track.

Since your PATH doesn’t have the current directory (.) as one of its search places, programs in your current directory must be called with an absolute path or a relative path specified as ./programname.

To see what directories are part of your PATH, enter this command:

  echo $PATH
  
  [alberto@digital alberto]$ echo $PATH
  /bin:/usr/bin:/opt/bin:/usr/local/bin:/usr/X11R6/bin:/opt/kde/bin:

Note that directory paths are separated by a colon (:).



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.