Book Image

Linux Utilities Cookbook

By : James Kent Lewis
Book Image

Linux Utilities Cookbook

By: James Kent Lewis

Overview of this book

<p>Linux is a stable, reliable and extremely powerful operating system. It has been around for many years, however, most people still don't know what it can do and the ways it is superior to other operating systems. Many people want to get started with Linux for greater control and security, but getting started can be time consuming and complicated. <br /><br />A practical, hands-on guide that provides you with a number of clear step-by-step examples to help you solve many of the questions that crop up when using an operating system you may not be familiar with.</p> <p>Presenting solutions to the most common Linux problems in a clear and concise way, this helpful guide starts with spicing up the terminal sessions by command retrieval and line editing, and shell prompt variables. We will then get to know the different desktops (GUIs) available for Linux systems and which is the best fit for you. We will then explore the world of managing files and directories, connectivity, and what to do when it goes wrong. We will also learn a range of skills, from creating and managing user accounts to securing your system, managing and limiting processes, and letting information flow from one process to another using pipes. Later, we will master disk management, working with scripts and automating tasks quickly, and finally, understand the need for a custom kernel and tips on how to build one.</p> <p><br />Based on the author's extensive experience, there is a section on best practices that every Linux user should be familiar with.</p>
Table of Contents (19 chapters)
Linux Utilities Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Other environment variables


The PS1 variable is only one of literally hundreds of environment variables. Don't worry, you don't have to know them all! The following are a few very useful ones:

  • PS1: It shows and sets the command line prompt

  • USER: It shows the current user

  • HOSTNAME: It shows the current hostname for this machine

  • HOME: It shows the home directory of the current user

  • SHELL: It shows the current shell this terminal is running in

  • TERM: It shows which terminal type is being used

  • PATH: It shows and sets the directories where programs are searched for

  • PWD: It shows the current working directory

  • EDITOR: It can be set to the full path to your desired text editor for use with certain commands such as crontab -e

  • TZ: It shows and sets the time zone variable

  • HISTSIZE: It shows and sets the size of the history buffer

Most of these are self-explanatory; however, a few need more discussion. The PATH environment variable is where commands are searched for in the filesystem.

The echo command is used to display the contents of a variable:

How to do it...

  1. Prepending a dot to the PATH means the program will be looked for in the current directory first, before searching the rest of the path. This is very useful during the code development for example. Do this by running:

    export PATH=".:$PATH"
    
  2. The EDITOR variable can be set to your favorite text editor. Most people use vi (or vim); however, you can point it to the one you want. If you change this, be sure to use the full path. To change the EDITOR variable do this:

    export EDITOR=/lewis/bin64/kw
    
  3. An export can be removed by setting it to nothing:

    export EDITOR=
    
  4. By convention, environment variables are usually written in uppercase. View the man pages and/or search Google for more information on these variables.

How it works...

Think of these environment variables just as you would if you were using a programming language. In this case, the type of the variable is determined by the OS. For example, you could type A=1 or A="This is a string".

The OS knows the difference. Also, there is variable scope. Notice I did not use export above. That means this A is local to this shell. Only exporting a variable will make it available to other shells (after sourcing the file).