Archive for April, 2007

57Chapter 2Running Commands from the ShellVariableDescriptionPS1Sets the value (Msn web hosting)

Saturday, April 28th, 2007

57Chapter 2Running Commands from the ShellVariableDescriptionPS1Sets the value of your shell prompt. There are many items that youcan read into your prompt (date, time, username, host name, andso on). Sometimes a command requires additional prompts, whichyou can set with the variables PS2, PS3, and so on. PWDThis is the directory that is assigned as your current directory. Thisvalue changes each time you change directories using the cdcommand. RANDOMAccessing this variable causes a random number to be generated. The number is between 0 and 99999. SECONDSThe number of seconds since the time the shell was started. SHLVLThe number of shell levels associated with the current shell session. When you log in to the shell, the SHLVLis 1. Each time you start anew bashcommand (by, for example, using suto become a newuser, or by simply typing bash), this number is incremented. TMOUTCan be set to a number representing the number of seconds the shellcan be idle without receiving input. After the number of seconds isreached, the shell exits. This is a security feature that makes it lesslikely for unattended shells to be accessed by unauthorized people. (This must be set in the login shell for it to actually cause the shellto log out the user.) UIDThe user ID number assigned to your username. The user IDnumber is stored in the /etc/passwordfile. Set Your Own Environment VariablesEnvironment variables can provide a handy way of storing bits of information thatyou use often from the shell. You can create any variables that you want (avoidingthose that are already in use) so that you can read in the values of those variablesas you use the shell. (The bash manpage lists variables already in use.) To set an environment variable temporarily, you can simply type a variable nameand assign it to a value. Here s an example: $ AB=/usr/dog/contagious/ringbearer/grind ; export ABThis example causes a long directory path to be assigned to the ABvariable. Theexport ABcommand says to export the value to the shell so that it can be propa- gated to other shells you may open. With ABset, you go to the directory by typingthe following: $cd $AB07_
Note: If you are looking for high quality webhost to host and run your jsp application check Vision christian web host services

56Part ILinux First StepsVariableDescriptionBASHContains the full path name (Graphic web design)

Friday, April 27th, 2007

56Part ILinux First StepsVariableDescriptionBASHContains the full path name of the bashcommand. This is usually/bin/bash. BASH_VERSIONA number of the current version of the bashcommand. EUIDThis is the effective user ID number of the current user. It isassigned when the shell starts, based on the user s entry in the/etc/passwdfile. FCEDITIf set, this variable indicates the text editor used by the fccommandto edit historycommands. If this variable isn t set, the vicom- mand is used. HISTFILEThe location of your history file. It is typically located at $HOME/. bash_history. HISTFILESIZEThe number of history entries that can be stored. After this numberis reached, the oldest commands are discarded. The default valueis1000. HISTCMDThis returns the number of the current command in the history list. HOMEThis is your home directory. It is your current working directory eachtime you log in or type the cdcommand with any options. HOSTTYPEA value that describes the computer architecture on which the Linuxsystem 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. MAILThis is the location of your mailbox file. The file is typically yourusername in the /var/spool/mail directory. OLDPWDThe directory that was the working directory before you changed tothe current working directory. OSTYPEA name identifying the current operating system. For Fedora CoreLinux, the OSTYPE value is either linux or linux-gnu, depending onthe type of shell you are using. (Bash can run on other operatingsystems as well.) PATHThe colon-separated list of directories used to find commands thatyou 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 youwant to run that is not in your PATH. For the root user, the valuealso includes /sbin, /usr/sbin, and /usr/local/sbin. PPIDThe process ID of the command that started the current shell(forexample, its parent process). PROMPT_COMMANDCan be set to a command name that is run each time before yourshell prompt is displayed. Setting PROMPT_COMMAND=datelists thecurrent date/time before the prompt appears.
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

55Chapter 2Running Commands from the ShellAdding AliasesSetting (Post office web site) aliases

Friday, April 27th, 2007

55Chapter 2Running Commands from the ShellAdding AliasesSetting 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 aliascommand. 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 pis assigned to run the command pwdand then torun ls -CFto print the current working directory and list its contents in columnform. The second runs the rmcommand with the -ioption each time you simplytype rm. (This is an alias that is often set automatically for the root user, so thatinstead 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 typingsomething such as rm *.) While you are in the shell, you can check which aliases are set by typing the aliascommand. If you want to remove an alias, type unalias. (Remember that if the aliasis set in a configuration file, it will be set again when you open another shell.) Using Shell Environment VariablesEvery active shell stores pieces of information that it needs to use in what are calledenvironment variables. An environment variable can store things such as locations ofconfiguration files, mailboxes, and path directories. It can also store values for yourshell prompts, the size of your history list, and type of operating system. To see the environment variables currently assigned to your shell, type the declarecommand. (It will probably fill more than one screen, so type declare | more.) Youcan 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 $USERchrisThis command prints the value of the USERvariable, which holds your username(chris). Substitute any other value for USERto print its value instead. Common Shell Environment VariablesWhen you start a shell (by logging in or opening a Terminal window), a lot of envi- ronment variables are already set. Here are some variables that are either set whenyou use a bash shell or that can be set by you to use with different features.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

Windows 2003 server web - 54Part ILinux First StepsTo make a change to

Friday, April 27th, 2007

54Part ILinux First StepsTo make a change to your prompt permanent, add the value of PS1to your .bashrcfile in your home directory (assuming that you are using the bash shell). There mayalready be a PS1value in that file that you can modify. Adding Environment VariablesYou may consider adding a few environment variables to your .bashrcfile. Thesecan help make working with the shell more efficient and effective: .TMOUT Sets how long the shell can be inactive before bash automaticallyexits. The value is the number of seconds for which the shell has not receivedinput. This can be a nice security feature, in case you leave your desk while youare still logged in to Linux. So as not to be logged off while you are working, youmay want to set the value to something like TMOUT=1800(to allow 30 minutesof idle time). .PATH As described earlier, the PATHvariable sets the directories that aresearched for commands you use. If you often use directories of commandsthat are not in your PATH, you can permanently add them. To do this, add aPATHvariable to your .bashrcfile. For example, to add a directory called/getstuff/bin, add the following: PATH=$PATH:/getstuff/bin ; export PATHThis example first reads all the current path directories into the new PATH($PATH), adds the /getstuff/bindirectory, and then exports the new PATH. Some people add the current directory to their PATHby adding a directory identi- fied simply as a dot (.), as follows: PATH=.:$PATH ; export PATHThis lets you always run commands in your current directory (which people may beused to if they have used DOS). However, the security risk with this procedure is thatyou could be in a directory that contains a command that you don t intend to runfrom that directory. For example, a hacker could put an lscommand in a directorythat, instead of listing the content of your directory, does something devious. .WHATEVER You can create your own environment variables to provide short- cuts in your work. Choose any name that is not being used and assign a usefulvalue to it. For example, if you do a lot of work with files in the /work/time/ files/info/memosdirectory, you could set the following variable: M=/work/time/files/info/memos ; export MYou could make that your current directory by typing cd $M. You could run aprogram from that directory called hotdog by typing $M/hotdog. You couldedit a file from there called bun by typing vi $M/bun. Caution07_
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

53Chapter 2Running Commands from the ShellIf you change (Virtual web hosting)

Friday, April 27th, 2007

53Chapter 2Running Commands from the ShellIf 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 vari- ety of letters) to include different information in your prompt. These can includeyour terminal number, the date, and the time, as well as other pieces of information. Here are some examples (you can find more on the bash man page): Special DescriptionCharacter! Showsthe current command history number. This includes all previouscommands stored for your username. # Shows the command number of the current command. This includes only thecommands 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 thecurrent working directory was /var/spool/mail, this value would simplyappear as mail. [ Precedes a sequence of nonprinting characters. This could be used to add aterminal control sequence into the prompt for such things as changing colors, adding blink effects, or making characters bold. (Your terminal determines theexact sequences available.) ] Follows a sequence of nonprinting characters. \ Shows a backslash. d Displays the day, month, and number of the date. For example: Sat Jan 23. h Shows the host name of the computer running the shell. n Causes a new line to occur. nnnShows 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. If you are setting your prompt temporarily by typing at the shell, you should putthe value of PS1in quotes. For example, you could type export PS1= [t w]$ to see a prompt that looks like this: [20:26:32 /var/spool]$. Tip07_
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services

Php web hosting - 52Part ILinux First StepsFileDescription/etc/profileSets up user environment information

Thursday, April 26th, 2007

52Part ILinux First StepsFileDescription/etc/profileSets up user environment information for every user. It is executedwhen you first log in. This file provides values for your path, aswell as setting environment variables for such things as thelocation of your mailbox and the size of your history files. Finally, /etc/profilegathers shell settings from configuration files inthe /etc/profile.ddirectory. /etc/bashrc Executes for every user who runs the bash shell each time a bashshell is opened. It sets the default prompt and may add one ormore aliases. Values in this file can be overridden by informationin each user s ~/.bashrcfile. ~/.bash_profileUsed by each user to enter information that is specific to theirown use of the shell. It is executed only once, when the user logsin. By default it sets a few environment variables and executes theuser s .bashrcfile. ~/.bashrcContains the information that is specific to your bash shells. It isread when you log in and also each time you open a new bashshell. This is the best location to add environment variables andaliases so that your shell picks them up. ~/.bash_logoutExecutes each time you log out (exit the last bash shell). Bydefault, it simply clears your screen. To change the /etc/profileor /etc/bashrcfiles, you must be the root user. Users can change the information in the $HOME/.bash_profile, $HOME/.bashrc, and $HOME/.bash_logoutfiles in their own home directories. The following sections provide ideas about items to add to your shell configurationfiles. In most cases, you add these values to the .bashrcfile in your home directory. However, if you administer a system, you may want to set some of these values asdefaults for all of your Linux system s users. Setting Your PromptYour prompt consists of a set of characters that appears each time the shell is readyto accept a command. The PS1environment 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 justa dollar sign or pound sign. For example, in Linux systems from Red Hat, your promptis set to include the following information: your username, your host name, and thebase name of your current working directory. That information is surrounded bybrackets and followed by a dollar sign (for regular users) or a pound sign (for theroot user). Here is an example of that prompt: [chris@myhost bin]$
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

51Chapter 2Running Commands from the Shell$ echo I (Web server address)

Thursday, April 26th, 2007

51Chapter 2Running Commands from the Shell$ echo I am $[2005 - 1957] years old. I am 48 years old. The shell interprets the arithmetic expression first (2005 - 1957) and then passesthat information to the echocommand. The echocommand displays the text, withthe 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 VariablesEnvironment variables that store information within the shell can be expandedusing the dollar sign ($) metacharacter. When you expand an environment variableon a command line, the value of the variable is printed instead of the variable nameitself, as follows: $ ls -l $BASH-rwxr-xr-x 1 root root 625516 Dec 5 11:13 /bin/bashUsing $BASHas an argument to ls -lcauses a long listing of the bashcommand tobe printed. The following section discusses shell environment variables. Creating Your Shell EnvironmentYou can tune your shell to help you work more efficiently. Your prompt can providepertinent information each time you press Enter. You can set aliases to save yourkeystrokes and permanently set environment variables to suit your needs. To makeeach change occur when you start a shell, add this information to your shell config- uration files. Configuring Your ShellSeveral configuration files support how your shell behaves. Some of the files areexecuted for every user and every shell, whereas others are specific to the userwho creates the configuration file. Here are the files that are of interest to anyoneusing the bash shell in Linux:
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision mysql hosting services

50Part ILinux First StepsBackground CommandsSome commands can take (Ipower web hosting)

Thursday, April 26th, 2007

50Part ILinux First StepsBackground CommandsSome commands can take a while to complete. Sometimes you may not want to tieup your shell waiting for a command to finish. In those cases, you can have thecommands run in the background by using the ampersand (&). Text formatting commands (such as nroffand troff, described earlier) are exam- ples 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 tocheck continuously for certain events to occur, such as the hard disk filling up orparticular 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 CommandsWith command substitution, you can have the output of a command interpreted bythe shell instead of by the command itself. In this way, you can have the standard out- put of a command become an argument for another command. The two forms of com- mand substitution are $(command)and `command`(backslashes, 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 vicommand is run. First, the findcommand starts at the /homedirectory and prints out all files anddirectories below that point in the file system. The output is piped to the grepcom- mand, which filters out all files except for those that include the string xyzzy. Finally, the vicommand 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 thename but not the location. As long as the string is uncommon, you can find andopen every instance of a filename existing beneath a point you choose in the filesystem. (In other words, don t use grep afrom the root file system or you ll matchand try to edit several thousand files.) Expanding Arithmetic ExpressionsThere may be times when you want to pass arithmetic results to a command. Thereare two forms you can use to expand an arithmetic expression and pass it to theshell: $[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 tomcat hosting services

Best web hosting site - 49Chapter 2Running Commands from the ShellPiping CommandsThe pipe

Wednesday, April 25th, 2007

49Chapter 2Running Commands from the ShellPiping CommandsThe pipe (|) metacharacter connects the output from one command to the input ofanother command. This lets you have one command work on some data and thenhave the next command deal with the results. Here is an example of a command linethat includes pipes: $ cat /etc/password | sort | lessThis command lists the contents of the /etc/passwordfile and pipes the output tothe sortcommand. The sortcommand takes the usernames that begin each lineof the /etc/passwordfile, sorts them alphabetically, and pipes the output to thelesscommand (to page through the output). Pipes are an excellent illustration of how UNIX, the predecessor of Linux, was createdas an operating system made up of building blocks. A standard practice in UNIXwas to connect utilities in different ways to get different jobs done. For example, before the days of graphical word processors, users created plain-text files thatincluded macros to indicate formatting. To see how the document really appeared, they would use a command such as the following: $ gunzip < /usr/share/man/man1/grep.1.gz | nroff -c -man | lessIn this example, the contents of the grepman page (grep.1.gz) are directed to thegunzipcommand to be unzipped. The output from gunzipis piped to the nroffcommand to format the man page using the manual macro (-man). The output ispiped to the lesscommand to display the output. Because the file being displayedis in plain text, you could have substituted any number of options to work with thetext before displaying it. You could sort the contents, change or delete some of thecontent, or bring in text from other documents. The key is that, instead of all thosefeatures being in one program, you get results from piping and redirecting input andoutput between multiple commands. Sequential CommandsSometimes you may want a sequence of commands to run, with one command completing before the next command begins. You can do this by typing severalcommands on the same command line and separating them with semicolons (;): $ date ; troff -me verylargedocument | lpr ; dateIn this example, I was formatting a huge document and wanted to know how longitwould take. The first command (date) showed the date and time before the for- matting started. The troffcommand formatted the document and then piped theoutput to the printer. When the formatting was done, the date and time was printedagain (so I knew how long the troffcommand took to complete).
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services

48Part ILinux First StepsInstead of just running a (Web page design)

Wednesday, April 25th, 2007

48Part ILinux First StepsInstead of just running a historycommand line immediately, you can recall a partic- ularline and edit it. You can use the following keys or key combinations to do that: Key(s)Function NameDescriptionArrow Keys StepPress the up and down arrow keys to step (.and .)through each command line in your historylist to arrive at the one you want. (Ctrl+P andCtrl+N do the same functions, respectively.) Ctrl+RReverse Incremental SearchAfter you press these keys, you enter a search string to do a reverse search. As you type thestring, a matching command line appears thatyou can run or edit. Ctrl+SForward Incremental SearchSame as the preceding function but forforward search. Alt+PReverse SearchAfter you press these keys, you enter a stringto do a reverse search. Type a string and pressEnter to see the most recent command linethat includes that string. Alt+NForward SearchSame as the preceding function but forforward search. Alt+End of History ListBrings you to the last entry of the history list. Another way to work with your history list is to use the fccommand. Type fcfol- lowed by a history line number, and that command line is opened in a text editor. Make the changes that you want. When you exit the editor, the command runs. Youcan also give a range of line numbers (for example, fc 100 105). All the commandsopen in your text editor, and then run one after the other when you exit the editor. The history list is stored in the .bash_historyfile in your home directory. Up to1,000 history commands are stored for you by default. Connecting and Expanding CommandsA truly powerful feature of the shell is the capability to redirect the input and out- put of commands to and from other commands and files. To allow commands to bestrung together, the shell uses metacharacters. As noted earlier, a metacharacter isa typed character that has special meaning to the shell for connecting commandsor requesting expansion.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services