Archive for April, 2007

Medical web site - Chapter 2 . Running Commands from the Shell

Monday, April 30th, 2007

Chapter 2 . Running Commands from the Shell 59 Managing Background and Foreground Processes If you are using Linux over a network or from a dumb terminal (a monitor that allows only text input with no GUI support), your shell may be all that you have. You may be used to a windowing environment where you have a lot of programs active at the same time so that you can switch among them as needed. This shell thing can seem pretty limited. Although the bash shell doesn t include a GUI for running many programs, it does let you move active programs between the background and foreground. In this way, you can have a lot of stuff running, while selectively choosing the one you want to deal with at the moment. There are several ways to place an active program in the background. One mentioned earlier is to add an ampersand (&) to the end of a command line. Another way is to use the at command to run commands in a way in which they are not connected to the shell. To stop a running command and put it in the background, press Ctrl+Z. After the command is stopped, you can either bring it to the foreground to run (the fg command) or start it running in the background (the bg command). Starting Background Processes If you have programs that you want to run while you continue to work in the shell, you can place the programs in the background. To place a program in the background at the time you run the program, type an ampersand (&) at the end of the command line, like this: $ find /usr > /tmp/allusrfiles & This example command finds all files on your Linux system (starting from /usr), prints those filenames, and puts those names in the file /tmp/allusrfiles. The ampersand (&) runs that command line in the background. To check which commands you have running in the background, use the jobs command, as follows: $ jobs [1] Stopped (tty output) vi /tmp/myfile [2] Running find /usr -print > /tmp/allusrfiles & [3] Running nroff -man /usr/man2/* >/tmp/man2 & [4]- Running nroff -man /usr/man3/* >/tmp/man3 & [5]+ Stopped nroff -man /usr/man4/* >/tmp/man4 The first job shows a text-editing command (vi) that I placed in the background and stopped by pressing Ctrl+Z while I was editing. Job 2 shows the find command I just ran. Jobs 3 and 4 show nroff commands currently running in the background. Job 5 had been running in the shell (foreground) until I decided too many processes were running and pressed Ctrl+Z to stop job 5 until a few processes had completed.
Note: In case you are looking for affordable webhost to host and run your web application check Vision http web server services

Web domain - 58 Part I . Linux First Steps To

Monday, April 30th, 2007

58 Part I . Linux First Steps To set an environment variable temporarily, you can simply type a variable name and assign it to a value. Here s an example: $ AB=/usr/dog/contagious/ringbearer/grind ; export AB This example causes a long directory path to be assigned to the AB variable. The export AB command says to export the value to the shell so that it can be propagated to other shells you may open. With AB set, you go to the directory by typing the following: $ cd $AB The problem with setting environment variables in this way is that as soon as you exit the shell in which you set the variable, the setting is lost. To set variables permanently, add variable settings to a bash configuration file, as described later in this section. If you want to have other text right up against the output from an environment variable, you can surround the variable in braces. This protects the variable name from being misunderstood. For example, if you want to add a command name to the AB variable shown earlier, you can type the following: $ echo ${AB}/adventure /usr/dog/contagious/ringbearer/grind/adventure Remember that you must export the variable so that it can be picked up by other shell commands. You must add the export line to a shell configuration file for it to take effect the next time you log in. The export command is fairly flexible. Instead of running the export command after you set the variable, you can do it all in one step, as follows: $ export XYZ=/home/xyz/bin You can override the value of any environment variable. This can be temporary, by simply typing the new value, or you can add the new export line to your $HOME/.bashrc file. One useful variable to update is PATH: $ export PATH=$PATH:/home/xyz/bin In this example, the /home/xyz/bin directory is added to the PATH, a useful technique if you want to run a bunch of commands from a directory that is not normally in your PATH, without typing the full or relative path each time. If you decide that you no longer want a variable to be set, you can use the unset command to erase its value. For example, you can type unset XYZ, which causes XYZ to have no value set. (Remember to remove the export from the $HOME/.bashrc file if you added it there or it will return the next time you open a shell.)
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web design programs services

Photoshop web design - Chapter 2 . Running Commands from the Shell

Monday, April 30th, 2007

Chapter 2 . Running Commands from the Shell 57 Variable Description PATH The colon-separated list of directories used to find commands that you type. The default value for regular users is /bin:/usr/ bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:~/ bin. You need to type the full path or a relative path to a command you want to run that is not in your PATH. For the root user, the value also includes /sbin, /usr/sbin, and /usr/local/sbin. PPID The process ID of the command that started the current shell (for example, its parent process). PROMPT_COMMAND Can be set to a command name that is run each time before your shell prompt is displayed. Setting PROMPT_COMMAND=date lists the current date/time before the prompt appears. PS1 Sets the value of your shell prompt. There are many items that you can read into your prompt (date, time, username, host name, and so on). Sometimes a command requires additional prompts, which you can set with the variables PS2, PS3, and so on. PWD This is the directory that is assigned as your current directory. This value changes each time you change directories using the cd command. RANDOM Accessing this variable causes a random number to be generated. The number is between 0 and 99999. SECONDS The number of seconds since the time the shell was started. SHLVL The number of shell levels associated with the current shell session. When you log in to the shell, the SHLVL is 1. Each time you start a new bash command (by, for example, using su to become a new user, or by simply typing bash), this number is incremented. TMOUT Can be set to a number representing the number of seconds the shell can be idle without receiving input. After the number of seconds is reached, the shell exits. This is a security feature that makes it less likely for unattended shells to be accessed by unauthorized people. (This must be set in the login shell for it to actually cause the shell to log out the user.) UID The user ID number assigned to your username. The user ID number is stored in the /etc/password file. Set Your Own Environment Variables Environment variables can provide a handy way to store bits of information that you use often from the shell. You can create any variables that you want (avoiding those that are already in use) so that you can read in the values of those variables as you use the shell. (The bash man page lists variables already in use.)
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

56 Part I (Web hosting company) . Linux First Steps Common

Monday, April 30th, 2007

56 Part I . Linux First Steps Common Shell Environment Variables When you start a shell (by logging in or opening a Terminal window), a lot of environment variables are already set. Table 2-8 shows some variables that are either set when you use a bash shell or that can be set by you to use with different features. Table 2-8 Common Shell Environment Variables Variable Description BASH Contains the full path name of the bash command. This is usually /bin/bash. BASH_VERSION A number representing the current version of the bash command. EUID This is the effective user ID number of the current user. It is assigned when the shell starts, based on the user s entry in the /etc/ passwd file. FCEDIT If set, this variable indicates the text editor used by the fc command to edit history commands. If this variable isn t set, the vi command is used. HISTFILE The location of your history file. It is typically located at $HOME/.bash_history. HISTFILESIZE The number of history entries that can be stored. After this number is reached, the oldest commands are discarded. The default value is 1000. HISTCMD This returns the number of the current command in the history list. HOME This is your home directory. It is your current working directory each time you log in or type the cd command with any options. HOSTTYPE A value that describes the computer architecture on which the Linux system is running. For Intel-compatible PCs, the value is i386, i486, i586, i686, or something like i386-linux. For AMD 64-bit machines, the value is x86_64. MAIL This is the location of your mailbox file. The file is typically your username in the /var/spool/mail directory. OLDPWD The directory that was the working directory before you changed to the current working directory. OSTYPE A name identifying the current operating system. For Fedora Core Linux, the OSTYPE value is either linux or linux-gnu, depending on the type of shell you are using. (Bash can run on other operating systems as well.)
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

Chapter 2 . Running Commands from the Shell (Web proxy server)

Sunday, April 29th, 2007

Chapter 2 . Running Commands from the Shell 55 You could make that your current directory by typing cd $M. You could run a program from that directory called hotdog by typing $M/hotdog. You could edit a file from there called bun by typing vi $M/bun. Adding Aliases Setting aliases can save you even more typing than setting environment variables. With aliases, you can have a string of characters execute an entire command line. You can add and list aliases with the alias command. Here are some examples: alias p= pwd ; ls CF alias rm= rm -i alias p= pwd ; ls -CF alias rm= rm -i In the first example, the letter p is assigned to run the command pwd, and then to run ls -CF to print the current working directory and list its contents in column form. The second runs the rm command with the -i option each time you simply type rm. (This is an alias that is often set automatically for the root user, so that instead of just removing files, you are prompted for each individual file removal. This prevents you from removing all the files in a directory by mistakenly typing something such as rm *.) While you are in the shell, you can check which aliases are set by typing the alias command. If you want to remove an alias, type unalias. (Remember that if the alias is set in a configuration file, it will be set again when you open another shell.) Using Shell Environment Variables Every active shell stores pieces of information that it needs to use in what are called environment variables. An environment variable can store things such as locations of configuration files, mailboxes, and path directories. They can also store values for your shell prompts, the size of your history list, and type of operating system. To see the environment variables currently assigned to your shell, type the declare command. (It will probably fill more than one screen, so type declare | more.) You can refer to the value of any of those variables by preceding it with a dollar sign ($) and placing it anywhere on a command line. For example: $ echo $USER chris This command prints the value of the USER variable, which holds your username (chris). Substitute any other value for USER to print its value instead.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services

54 Part I . Linux First Steps (Web hosting rating) If

Sunday, April 29th, 2007

54 Part I . Linux First Steps If you are setting your prompt temporarily by typing at the shell, you should put the value of PS1 in quotes. For example, you could type export PS1= [t w]$ to see a prompt that looks like this: [20:26:32 /var/spool]$. To make a change to your prompt permanent, add the value of PS1 to your .bashrc file in your home directory (assuming that you are using the bash shell). There may already be a PS1 value in that file that you can modify. Adding Environment Variables You may consider adding a few environment variables to your .bashrc file. These can help make working with the shell more efficient and effective: . TMOUT Sets how long the shell can be inactive before bash automatically exits. The value is the number of seconds for which the shell has not received input. This can be a nice security feature, in case you leave your desk while you are still logged in to Linux. So as not to be logged off while you are working, you may want to set the value to something like TMOUT=1800 (to allow 30 minutes of idle time). . PATH As described earlier, the PATH variable sets the directories that are searched for commands you use. If you often use directories of commands that are not in your PATH, you can permanently add them. To do this, add a PATH variable to your .bashrc file. For example, to add a directory called /getstuff/bin, add the following: PATH=$PATH:/getstuff/bin ; export PATH This example first reads all the current path directories into the new PATH ($PATH), adds the /getstuff/bin directory, and then exports the new PATH. Some people add the current directory to their PATH by adding a directory identified simply as a dot (.), as follows: PATH=.:$PATH ; export PATH This lets you always run commands in your current directory (which people may be used to if they have used DOS). However, the security risk with this procedure is that you could be in a directory that contains a command that you don t intend to run from that directory. For example, a hacker could put an ls command in a directory that, instead of listing the content of your directory, does something devious. . WHATEVER You can create your own environment variables to provide shortcuts in your work. Choose any name that is not being used and assign a useful value to it. For example, if you do a lot of work with files in the /work/time/ files/info/memos directory, you could set the following variable: M=/work/time/files/info/memos ; export M Caution Tip
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

Chapter 2 . Running Commands from the Shell (Web hosting india)

Sunday, April 29th, 2007

Chapter 2 . Running Commands from the Shell 53 If you change directories, the bin name would change to the name of the new directory. Likewise, if you were to log in as a different user or to a different host, that information would change. You can use several special characters (indicated by adding a backslash to a variety of letters) to include different information in your prompt. These can include your terminal number, the date, and the time, as well as other pieces of information. Table 2-7 provides some examples (you can find more on the bash man page): Table 2-7 Characters to Add Information to bash Prompt Special Character Description ! Shows the current command history number. This includes all previous commands stored for your username. # Shows the command number of the current command. This includes only the commands for the active shell. $ Shows the user prompt ($) or root prompt (#), depending on which user you are. W Shows only the current working directory base name. For example, if the current working directory was /var/spool/mail, this value simply appears as mail. [ Precedes a sequence of nonprinting characters. This can be used to add a terminal control sequence into the prompt for such things as changing colors, adding blink effects, or making characters bold. (Your terminal determines the exact sequences available.) ] Follows a sequence of nonprinting characters. \ Shows a backslash. d Displays the day name, month, and day number of the current date. For example: Sat Jan 23. h Shows the host name of the computer running the shell. n Causes a newline to occur. nnn Shows the character that relates to the octal number replacing nnn. s Displays the current shell name. For the bash shell, the value would be bash. t Prints the current time in hours, minutes, and seconds (for example, 10:14:39). u Prints your current username. w Displays the full path to the current working directory.
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services

52 Part I . Linux First Steps Table (Web hosting colocation)

Saturday, April 28th, 2007

52 Part I . Linux First Steps Table 2-6 Bash Configuration Files File Description /etc/profile Sets up user environment information for every user. It is executed when you first log in. This file provides values for your path, as well as setting environment variables for such things as the location of your mailbox and the size of your history files. Finally, /etc/profile gathers shell settings from configuration files in the /etc/profile.d directory. /etc/bashrc Executes for every user who runs the bash shell, each time a bash shell is opened. It sets the default prompt and may add one or more aliases. Values in this file can be overridden by information in each user s ~/.bashrc file. ~/.bash_profile Used by each user to enter information that is specific to his or her own use of the shell. It is executed only once, when the user logs in. By default it sets a few environment variables and executes the user s .bashrc file. ~/.bashrc Contains the information that is specific to your bash shells. It is read when you log in and also each time you open a new bash shell. This is the best location to add environment variables and aliases so that your shell picks them up. ~/.bash_logout Executes each time you log out (exit the last bash shell). By default, it simply clears your screen. The following sections provide ideas about items to add to your shell configuration files. In most cases, you add these values to the .bashrc file in your home directory. However, if you administer a system, you may want to set some of these values as defaults for all of your Linux system s users. Setting Your Prompt Your prompt consists of a set of characters that appear each time the shell is ready to accept a command. The PS1 environment variable sets what the prompt contains. If your shell requires additional input, it uses the values of PS2, PS3, and PS4. When your Linux system is installed, often a prompt is set to contain more than just a dollar sign or pound sign. For example, in Linux systems from Red Hat, your prompt is set to include the following information: your username, your host name, and the base name of your current working directory. That information is surrounded by brackets and followed by a dollar sign (for regular users) or a pound sign (for the root user). Here is an example of that prompt: [chris@myhost bin]$
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web and email hosting services

Chapter 2 . Running Commands from the Shell (Web hosting directory)

Saturday, April 28th, 2007

Chapter 2 . Running Commands from the Shell 51 $ echo I am $[2006 - 1957] years old. I am 49 years old. The shell interprets the arithmetic expression first (2005 - 1957), and then passes that information to the echo command. The echo command displays the text, with the results of the arithmetic (48) inserted. Here s an example of the other form: $ echo There are $(ls | wc -w) files in this directory. There are 14 files in this directory. This lists the contents of the current directory (ls) and runs the word count command to count the number of files found (wc -w). The resulting number (14 in this case) is echoed back with the rest of the sentence shown. Expanding Environment Variables Environment variables that store information within the shell can be expanded using the dollar sign ($) metacharacter. When you expand an environment variable on a command line, the value of the variable is printed instead of the variable name itself, as follows: $ ls -l $BASH -rwxr-xr-x 1 root root 625516 Dec 5 11:13 /bin/bash Using $BASH as an argument to ls -l causes a long listing of the bash command to be printed. The following section discusses shell environment variables. Creating Your Shell Environment You can tune your shell to help you work more efficiently. Your prompt can provide pertinent information each time you press Enter. You can set aliases to save your keystrokes and permanently set environment variables to suit your needs. To make each change occur when you start a shell, add this information to your shell configuration files. Configuring Your Shell Several configuration files support how your shell behaves. Some of the files are executed for every user and every shell, while others are specific to the user who creates the configuration file. Table 2-6 shows the files that are of interest to anyone using the bash shell in Linux. To change the /etc/profile or /etc/bashrc files, you must be the root user. Users can change the information in the $HOME/.bash_profile, $HOME/.bashrc, and $HOME/.bash_logout files in their own home directories.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision mysql hosting services

Web host 4 life - 50 Part I . Linux First Steps Background

Saturday, April 28th, 2007

50 Part I . Linux First Steps Background Commands Some commands can take a while to complete. Sometimes you may not want to tie up your shell waiting for a command to finish. In those cases, you can have the commands run in the background by using the ampersand (&). Text formatting commands (such as nroff and troff, described earlier) are examples of commands that are often run in the background to format a large document. You also might want to create your own shell scripts that run in the background to check continuously for certain events to occur, such as the hard disk filling up or particular users logging in. Here is an example of a command being run in the background: $ troff -me verylargedocument | lpr & Other ways to manage background and foreground processes are described in the Managing Background and Foreground Processes section later in this chapter. Expanding Commands With command substitution, you can have the output of a command interpreted by the shell instead of by the command itself. In this way, you can have the standard output of a command become an argument for another command. The two forms of command substitution are $(command) and `command` (backticks, not single quotes). The command in this case can include options, metacharacters, and arguments. Here is an example of using command substitution: $ vi $(find /home | grep xyzzy) In this example, the command substitution is done before the vi command is run. First, the find command starts at the /home directory and prints out all files and directories below that point in the file system. The output is piped to the grep command, which filters out all files except for those that include the string xyzzy. Finally, the vi command opens all filenames for editing (one at a time) that include xyzzy. This particular example is useful if you want to edit a file for which you know the name but not the location. As long as the string is uncommon, you can find and open every instance of a filename existing beneath a point you choose in the file system. (In other words, don t use grep a from the root file system or you ll match and try to edit several thousand files.) Expanding Arithmetic Expressions There may be times when you want to pass arithmetic results to a command. There are two forms you can use to expand an arithmetic expression and pass it to the shell: $[expression] or $(expression). Here is an example:
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision virtual web hosting services