Archive for April, 2007

47Chapter 2Running Commands from the ShellCommand-Line RecallAfter you (Windows 2003 server web)

Wednesday, April 25th, 2007

47Chapter 2Running Commands from the ShellCommand-Line RecallAfter you type a command line, that entire command line is saved in your shell shistory list. The list is stored in a history file, from which any command can berecalled to run again. After it is recalled, you can modify the command line, asdescribed earlier. To view your history list, use the historycommand. Type the command withoutoptions or followed by a number to list that many of the most recent commands. For example: $ history 8382 date383 ls /usr/bin | sort -a | more384 man sort385 cd /usr/local/bin386 man more387 useradd -m /home/chris -u 101 chris388 passwd chris389 history 8A number precedes each command line in the list. There are several ways to run acommand immediately from this list, including: .!n Run command number. Replace the nwith the number of the commandline, and that line is run. For example, here s how to repeat the datecommandshown as command number 382 in the preceding history listing: $ !382dateThu May 13 21:30:06 PDT 2004 .!! Run previous command. Runs the previous command line. Here s howyou d immediately run that same datecommand: $ !! dateThu May 13 21:30:39 PDT 2004 .!?string? Run command containing string. This runs the most recentcommand that contains a particular stringof characters. For example, you canrun the datecommand again by just searching for part of that command lineas follows: $ !?dat? dateWed Oct 13 21:32:41 PDT 200407_
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

46Part ILinux First StepsThe first example causes $OSto (Ipower web hosting)

Wednesday, April 25th, 2007

46Part ILinux First StepsThe first example causes $OSto expand to the $OSTYPEvariable. In the next exam- ple, ~ro expands to the root user s home directory (~root/). Next, fingexpandsto the fingercommand. Finally, the address of root@locexpands to computername localhost. Of course, there will be times when there are several possible completions for thestring of characters you have entered. In that case, you can check the possible waystext can be expanded by pressing Esc+? (or by pressing Tab twice) at the point whereyou want to do completion. This shows the result you would get if you checked forpossible completions on $P: $ echo $P $PATH $PPID $PS1 $PS2 $PS4 $PWD$ echo $PIn this case, there are six possible variables that begin with $P. After possibilitiesare displayed, the original command line returns, ready for you to complete it asyou choose. If text you want to complete is not preceded by a $, ~, or @, you can still try to com- plete the text with a variable, username, or host name. Press Key ToCombinationAlt+~Complete the text before this point as a username. Alt+$Complete the text before this point as a variable. Alt+@Complete the text before this point as a host name. Alt+!Complete the text before this point as a command name (alias, reservedword, shell function, shell built-in command, and filenames are checked inthat order). In other words, complete this key sequence with a commandthat you previously ran. Ctrl+X+/List possible username text completions. Ctrl+X+$List possible environment variable completions. Ctrl+X+@List possible host name completions. Ctrl+X+!List possible command name completions.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision virtual web hosting services

Web page design - 45Chapter 2Running Commands from the ShellTable 2-3Keystrokes for

Tuesday, April 24th, 2007

45Chapter 2Running Commands from the ShellTable 2-3Keystrokes for Cutting and Pasting Text in Command LinesKeystrokeFull NameMeaningCtrl+KCut end of lineCut text to the end of the line. Ctrl+UCut beginning of lineCut text to the beginning of the line. Ctrl+WCut previous wordCut the word located behind the cursor. Alt+DCut next wordCut the word following the cursor. Ctrl+YPaste recent textPaste most recently cut text. Alt+YPaste earlier textRotate back to previously cut text and paste it. Ctrl+CDelete whole lineDelete the entire line. Command-Line CompletionTo save you a few keystrokes, the bash shell offers several different ways of com- pleting partially typed values. To attempt to complete a value, type the first fewcharacters, and then press Tab. Here are some of the values you can type partially: .Environment variable If the text begins with a dollar sign ($), the shellcompletes the text with an environment variable from the current shell. .Username If the text begins with a tilde (~), the shell completes the textwith a username. .Command, alias, or function If the text begins with regular characters, theshell tries to complete the text with a command, alias, or function name. .Host name If the text begins with an at (@) sign, the shell completes the textwith a host name taken from the /etc/hostsfile. To add host names from an additional file, you can set the HOSTFILEvariable tothe name of that file. The file must be in the same format as /etc/hosts. Here are a few examples of command completion. (When you see , it meansto press the Tab key on your keyboard.) Type the following: $ echo$OS $ cd ~ro $ fing $mail root@loc Tip07_
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services

44Part ILinux First StepsTable 2-1Keystrokes for Navigating Command (Free web design)

Tuesday, April 24th, 2007

44Part ILinux First StepsTable 2-1Keystrokes for Navigating Command LinesKeystrokeFull NameMeaningCtrl+FCharacter forwardGo forward one character. Ctrl+BCharacter backwardGo backward one character. Alt+FWord forwardGo forward one word. Alt+BWord backwardGo backward one word. Ctrl+ABeginning of lineGo to the beginning of the current line. Ctrl+EEnd of lineGo to the end of the line. Ctrl+LClear screenClear screen and leave line at the top of the screen. The keystrokes in Table 2-2 can be used to edit command lines. Table 2-2Keystrokes for Editing Command LinesKeystrokeFull NameMeaningCtrl+DDelete currentDelete the current character. Backspace Delete previousDelete the previous character. or RuboutCtrl+TTranspose characterSwitch positions of current and previous characters. Alt+TTranspose wordsSwitch positions of current and previous characters. Alt+UUppercase wordChange the current word to uppercase. Alt+LLowercase wordChange the current word to lowercase. Alt+CCapitalize wordChange the current word to an initial capital. Ctrl+VInsert special Add a special character. For example, to add a Tab charactercharacter, press Ctrl+V+Tab. Use the keystrokes in Table 2-3 to cut and paste text on a command line.
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services

Web site design - 43Chapter 2Running Commands from the ShellBy default, the

Tuesday, April 24th, 2007

43Chapter 2Running Commands from the ShellBy default, the bash shell uses command-line editing that is based on the emacstext editor. (Type man emacsto read about it, if you care to.) If you are familiarwith emacs, you probably already know most of the keystrokes described here. If you prefer the vicommand for editing shell command lines, you can easilymake that happen. Add the lineset -o vito the .bashrcfile in your home directory. The next time you open a shell, youcan use vicommands (as described in the tutorial later in this chapter) to edityour command lines. To do the editing, you can use a combination of control keys, meta keys, and arrowkeys. For example, Ctrl+F means to hold the Ctrl key and type F. Alt+F means tohold the Alt key and type F. (Instead of the Alt key, your keyboard may use a Metakey or the Esc key. On a Windows keyboard, you can use the Windows key.) To try out a bit of command-line editing, type the following: $ ls /usr/bin | sort -f | lessThis command lists the contents of the /usr/bindirectory, sorts the contents inalphabetical order (regardless of case), and pipes the output to less. The lesscommand displays the first page of output, after which you can go through the restof the output a line (press Enter) or a page (press spacebar) at a time (press Q whenyou are done). Now, suppose you want to change /usr/binto /bin. You can usethe following steps to change the command: 1.Press Ctrl+A. This moves the cursor to the beginning of the command line. 2.Press Ctrl+F or the right arrow (.) key. Repeat this command a few times toposition the cursor under the first slash (/). 3.Press Ctrl+D. Type this command four times to delete /usr. 4.Press Enter. This executes the command line. As you edit a command line, at any point you can type regular characters to addthose characters to the command line. The characters appear at the location of yourcursor. You can use right (.) and left (.) arrows to move the cursor from one endto the other on the command line. You can also press the up (.) and down (.) arrowkeys to step through previous commands in the history list to select a commandline for editing. (See the discussion on command recall for details on how to recallcommands from the history list.) There are many keystrokes you can use to edit your command lines. Table 2-1 liststhe keystrokes that you can use to move around the command line. Tip07_
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services

42Part ILinux First StepsRerunning CommandsIt s (Web hosting india) annoying, after typing

Monday, April 23rd, 2007

42Part ILinux First StepsRerunning CommandsIt s annoying, after typing a long or complex command line, to learn that you mis- typed something. Fortunately, some shell features let you recall previous commandlines, edit those lines, or complete a partially typed command line. The shellhistoryis a list of the commands that you have entered before. Using thehistorycommand in a bash shell, you can view your previous commands. Then, using various shell features, you can recall individual command lines from that listand change them however you please. The rest of this section describes how to do command-line editing, how to com- plete parts of command lines, and how to recall and work with the history list. Command-Line EditingIf you type something wrong on a command line, the bash shell ensures that youdon t have to delete the entire line and start over. Likewise, you can recall a previ- ous command line and change the elements to make a new command. Getting Help Using the ShellWhen you first start using the shell, it can be intimidating. All you see is a prompt. How do youknow which commands are available, which options they use, or how to use advanced fea- tures? Fortunately, lots of help is available. Here are some places you can look to supplementwhat you learn in this chapter: .Check the PATH Type echo $PATH. You see a list of the directories containing com- mands that are immediately accessible to you. Listing the contents of those directoriesdisplays most standard Linux commands. .Use the helpcommand Some commands are built into the shell, so they do notappear in a directory. The helpcommand lists those commands and shows optionsavailable with each of them. (Type help | lessto page through the list.) For help witha particular built-in command, type help command, replacing commandwith thename that interests you. The helpcommand only works with the bash shell. .Use –helpwith the command Many commands include a –helpoption thatyou can use to get information about how the command is used. For example, typedate –help | less. The output shows not only options, but also time formats youcan use with the datecommand. .Use the mancommand To learn more about a particular command, type mancommand. (Replace commandwith the command name you want.) A descriptionof the command and its options appears on the screen.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

Free web space - 41Chapter 2Running Commands from the ShellNot all the

Monday, April 23rd, 2007

41Chapter 2Running Commands from the ShellNot all the commands that you run are located in directories in your PATHvariable. Some commands are built into the shell. Other commands can be overridden bycreating aliases that define any commands and options that you want the commandto run. There are also ways of defining a function that consists of a stored series ofcommands. Here is the order in which the shell checks for the commands you type: 1.Aliases Names set by the aliascommand that represent a particular com- mand and a set of options. (Type aliasto see what aliases are set.) Often, aliases enable you to define a short name for a long, complicated command. 2.Shell reserved word Words that are reserved by the shell for special use. Many of these are words that you would use in programming-type functions, such as do, while, case, and else. 3.Function A set of commands that are executed together within the currentshell. 4.Built-in command A command that is built into the shell. As a result, thereis no representation of the command in the file system. Some of the most com- mon commands you will use are shell built-in commands, such as cd(to changedirectories), echo(to echo text to the screen), exit(to exit from a shell), fg(to bring a command running in the background to the foreground), history(to see a list of commands that were previously run), pwd(to list the presentworking directory), set(to set shell options), and type(to show the locationof a command). 5.File system command This is a command that is stored in and executedfrom the computer s file system. (These are the commands that are indicatedby the value of the PATHvariable.) To find out where a particular command is taken from, you can use the typecom- mand. (If you are using a shell other than bash, use the whichcommand instead.) For example, to find out where the bash shell command is located, type the following: $ type bashbash is /bin/bashTry these few words with the typecommand to see other locations of commands: which, case, and return. If a command resides in several locations, you can addthe -aoption to have all the known locations of the command printed. Sometimes you run a command and receive an error message that the commandwas not found or that permission to run the command was denied. In the first case, check that you spelled the command correctly and that it is located in your PATHvariable. In the second case, the command may be in the PATHvariable but maynot be executable. Adding execute permissions to a command is described later inthis chapter. Tip07_
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services

40Part ILinux First StepsUnless you specifically change to (Geocities web hosting)

Monday, April 23rd, 2007

40Part ILinux First StepsUnless you specifically change to another shell, the bash shell is the one you usewith most Linux systems. The bash shell contains most of the powerful featuresavailable in other shells. Although the description in this chapter steps you throughmany bash shell features, you can learn more about the bash shell by typing manbash, and the sidebar Getting Help Using the Shell shows you a few other ways tolearn about using the shell. Locating CommandsIf you know the directory that contains the command you want to run, one way torun it is to type the full path to that command. For example, you run the datecom- mand from the /bindirectory by typing$ /bin/dateOf course, this can be inconvenient, especially if the command resides in a directorywith a long path name. The better way is to have commands stored in well-knowndirectories, and then add those directories to your shell s PATHenvironment vari- able. The path consists of a list of directories that are checked sequentially for thecommands you enter. To see your current path, type the following: $ echo $PATH/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:/home/chris/binThe results show the default path for a regular Linux user. Directories in the pathlist are separated by colons. Most user commands that come with Linux are storedin the /bin, /usr/bin, or /usr/local/bindirectories. Although many graphicalcommands (that are used with GUIs) are contained in /usr/bin, there are somespecial X commands that are in /usr/bin/X11and /usr/X11R6/bindirectories. The last directory shown is the bindirectory in the user s home directory. If you want to add your own commands or shell scripts, place them in the bindirectory in your home directory (such as /home/chris/binfor the user namedchris). This directory is automatically added to your path. So as long as you add thecommand to your bin with execute permission (described in the UnderstandingFile Permissions section later in this chapter), you can immediately begin usingthe command by simply typing the command name at your shell prompt. If you are the root user, directories containing administrative commands are typi- cally in your path. These directories include /sbinand /usr/sbin. The path directory order is important. Directories are checked from left to right. So,in this example, if there is a command called foolocated in both the /binand/usr/bindirectories, the one in /binis executed. To have the other foocommandrun, you either type the full path to the command or change your PATHvariable. (Changing your PATHand adding directories to it are described later in this chapter.) Tip07_
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services

39Chapter 2Running (Web hosting comparison) Commands from the ShellUsing the Shell

Monday, April 23rd, 2007

39Chapter 2Running Commands from the ShellUsing the Shell in LinuxWhen you type a command in a shell, you can include other characters that changeor add to how the command works. You can also set sequences of command orredirect input and output of a command by using control characters such as pipes(|), semicolons (;), and greater-than (>) and less-than (<) signs. In addition to the command itself, these are some of the other items that you cantype on a shell command line: .Options Most commands have one or more options you can add to changetheir behavior. Options typically consist of a single letter preceded by a dash. You can also often combine several options after a single dash. For example, the command ls -la lists the contents of the current directory. The -lasksfor a detailed (long) list of information, and the -aasks that files beginning witha dot (.) also be listed. When a single option consists of a word, it is usuallypreceded by a double dash (--). For example, to use the help option on manycommands, you enter --help on the command line. You can use the --helpoption with most commands to see the options andarguments that they support. For example, hostname --help. .Arguments Many commands also accept arguments after certain optionsare entered or at the end of the entire command line. An argument is an extrapiece of information, such as a filename, that can be used by the command. For example, cat /etc/passwddisplays the contents of the /etc/passwdfile on your screen. In this case, /etc/passwd is the argument. .Environment variables The shell itself stores information that may be useful to the user s shell session in what are called environment variables. Examples of environment variables include $SHELL(which identifies the shellyou are using), $PS1(which defines your shell prompt), and $MAIL(whichidentifies the location of your mailbox). See the Using Shell EnvironmentVariables section later in this chapter for more information. You can check your environment variables at any time. Type declareto list the cur- rent environment variables. Or you can type echo$VALUE, where VALUEis replacedby the name of a particular environment variable you want to list. .Metacharacters These are characters that have special meaning to theshell. They can be used to direct the output of a command to a file (>), pipethe output to another command (|), and run a command in the background(&), to name a few. Metacharacters are discussed later in this chapter. To save you some typing, there are shell features that store commands you want toreuse, recall previous commands, and edit commands. You can create aliases thatenable you to type a short command to run a longer one. The shell stores previouslyentered commands in a history list, which you can display and from which you canrecall commands. You ll see how this works a little later in the chapter. TipNote07_
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web design programs services

38Part ILinux First StepsOn this shell (Web and email hosting) session, there

Sunday, April 22nd, 2007

38Part ILinux First StepsOn this shell session, there isn t much happening. The first process shows that theuser named jakelogged in to the login process (which is controlled by the rootuser). The next process shows that jakeis using a bash shell and has just run theps -aucommand. The terminal device ttyp0is being used for the login session. The STATcolumn represents the state of the process, with Rindicating a currentlyrunning process and Srepresenting a sleeping process. The USERcolumn shows the name of the user who started the process. Each processis represented by a unique ID number referred to as a process ID (PID). (You can usethe PID if you ever need to kill a runaway process.) The %CPUand %MEMcolumns showthe percentage of the processor and random access memory, respectively, that theprocess is consuming. VSZ(virtual set size) shows the size of the image process(inkilobytes), and RSS(resident set size) shows the size of the program in memory. STARTshows the time the process began running, and TIMEshows the cumulativesystem time used. (Many commands consume very little CPU time, as is reflectedby 0:00 for processes that haven t even used a whole second of CPU time.) Many processes running on a computer are not associated with a terminal. A normalLinux system has many processes running in the background. Background systemprocesses perform such tasks as logging system activity or listening for data comingin from the network. They are often started when Linux boots up and run continu- ously until it shuts down. To page through all the processes running on your Linuxsystem, add the pipe (|) and the lesscommand to ps aux, like this: $ ps -aux | lessA pipe lets you direct the output of one command to be the input of the next com- mand, so in this example, the output of the pscommand (a list of processes) isdirected to the lesscommand, which lets you page through that information. Usethe spacebar to page through and type qto end the list. You can also use the arrowkeys to move one line at a time through the output. Exiting the ShellTo exit the shell when you are done, either type exitor press Ctrl+D. If you are exitingfrom your login shell (the shell that started when you first logged in), type logouttoexit the shell. You ve just seen a few commands that can help you quickly familiarize yourselfwith your Linux system. There are hundreds of other commands that you can try. You ll find many in the /binand /usr/bindirectories, and you can use lsto seeadirectory s command list: ls /bin, for example, results in a list of commands inthe /bin. Then use the mancommand (for example, man hostname) to see what eachcommand does. There are also administrative commands in /sbinor /usr/sbindirectories.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services