Linux Web Hosting

Linux Operating Sistem

92 Hour 6 PATH=$PATH:$HOME/bin:/sbin If you re the root

Filed under: Linux Web Hosting — webmaster @ 5:37 pm

Linux Operating Sistem

Using the Shell 89 One of the existing

Filed under: Learn Linux in 24 hours — webmaster @ 9:46 am

Using the Shell 91 There are many different environment variables. Use the printenv command to see a list of the variables currently in use: # printenv … PATH=/usr/local/bin:/bin:/usr/bin:.:/usr/X11R6/bin:/home/bball/bin HOME=/home/bball SHELL=/bin/bash … This hour doesn t list all of the environment variables, but you should know that one of the most important is the $PATH variable. This variable tells the shell where to find executable programs. Without this variable, you d have to type the complete path, or directory hierarchy of a command, to run a program. For example, if you want to run the ifconfig command to check the status of your network connections, you might at first try to type its name on the command line: # ifconfig bash: ifconfig: command not found # whereis ifconfig ifconfig: /sbin/ifconfig As you can see, this doesn t mean that the ifconfig command doesn t exist, or isn t installed on your system, it s just that your shell doesn t know where to find the program. To run the ifconfig command, you can type the full pathname before the command, but if you need to use this program repeatedly, include its directory in the list of known paths in your shell s $PATH environment variable. Do this at the command line by adding the /sbindirectory to your $PATH variable, using the bash shell s export command: # ifconfig bash: ifconfig: command not found # PATH=$PATH:/sbin ; export PATH # ifconfig lo Link encap:Local Loopback inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0 UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1 RX packets:436 errors:0 dropped:0 overruns:0 TX packets:436 errors:0 dropped:0 overruns:0 As you can see, your shell now knows where to find the ifconfig command. But this is only temporary, and only lasts as long as you re logged in, or running a particular terminal. Make this change effective for each time you log in by adding the path to the file .bash_profile in your home directory, or if you re the root operator and want all users to benefit, to the file profile under the /etc directory. Look for the line PATH=$PATH:$HOME/bin in the .bash_profile file, and add the /sbin directory. 6

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Unix Web Hosting services

Linux Operating Sistem

Using the Shell 89 One of the existing

Filed under: Learn Linux in 24 hours — webmaster @ 9:46 am

Using the Shell 89 One of the existing files has been deleted, but the input file, trashfiles.txt, which still contains the list of files has not been changed. When you try to use the list as a valid input to build an archive, the cpiocommand complains and sends an error message to your screen (but still builds the archive). Each input and output also has an assigned file number in your shell. For the standard input, the number is zero (0). For the standard output, the number is one (1), and for the standard error, the number is two (2). Knowing this, you can run cpiosilently, and can cause any errors to be sent to a file. Do this by combining the standard output redirection operator and the standard error s file number, as shown in the following example. # cpio -o < trashfiles.txt >trash.cpio 2>cpio.errors # cat cpio.errors cpio: /tmp/trash/file3: No such file or directory 1 block As you can see, the cpio command sent its errors, which normally would be sent to the standard error output (your display), to a file called cpio.errors. Normally, each time you redirect output to a file, either the named file is created, or if it exists, the named file is overwritten and its previous contents are irrevocably lost. You should use file redirection carefully. If you redirect output to an existing file, you lose the original file, which may not be what you want. CAUTION If you d like to retain the original contents of a file, you can append the output of a program to a file by using the concatenate (>>), or append redirection operator: # cpio -o < trashfiles.txt >trash.cpio 2>>cpio.errors This command line saves the previous contents of the cpio.errorsfile, and appends any new errors to the end of the file. This approach keeps a log of errors when you run the cpio command. This method is used if you ve enabled system logging for Linux. Take a look at the contents of the file called messages, found under the /var/log directory. If you recall the simple cat command text editor example from Hour 4, Reading and Navigation Commands, you ll remember that the standard output redirection operator was used with the cat command to read input from the terminal to create a text file: # cat >file.txt this is a line this is another line EOF # cat file.txt this is a line this is another line 6

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Unix Web Hosting services

Linux Operating Sistem

Using the Shell 89 One of the existing

Filed under: Linux Web Hosting — webmaster @ 9:46 am

90 Hour 6 The end-of-file, or EOF character, is used to close the file, and is entered by holding down the Ctrl key and pressing the d key. Add a new feature to this simple editor by using the << redirection operator, which tells the shell that the end of the input immediately follows the << operator: # cat >file.txt <<. This is a line of text This is another line of text . # cat file.txt This is a line of text. This is another line of text. You ll notice that the file is closed after typing a period (.) on a line by itself, which is handier than using a control key combination to close the file. Try this approach to build a simple, self-contained database file by combining the grep command (discussed in Hour 5, Manipulation and Searching Commands ) and input redirection. If you have a list of addresses, wrap the list by putting the grepcommmand at the beginning, and the end of input character string at the end of the file. Call this database db. See the following example. # cat >db <<. egrep -i $1 <

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Unix Web Hosting services

Linux Operating Sistem

86 Hour 6 The bash shell also has

Filed under: Linux Web Hosting — webmaster @ 1:17 am

88 Hour 6 These files are parsed if the zsh shell cannot find equivalent files, but with a leading period, such as .zlogin, in your home directory. This shell also has more command-line prompt options than other shells, such as bash or tcsh. You ll find that this shell has features similar to all other shells, and can emulate the sh or ksh shells when called as a symbolic link (although your Red Hat Linux system has the sh shell linked to the bash shell). There s a lot of information for this shell: 10 manual page files, along with a /usr/doc directory filled with help files, examples, and other up-to-date and useful information. Understanding the Shell Command Line When you use the shell to start a program at the command line, the shell interprets your command and the command echoes its output back to your screen. Using the shell, you can have the program s output sent elsewhere, such as to a file. The shell also can feed the program s input from another program or even another file. For example, you can redirect the standard output of the ls command to a file: # touch /tmp/trash/file1 /tmp/trash/file2 /tmp/trash/file3 /tmp/trash/file4 # ls -w 1 /tmp/trash/* >trashfiles.txt The first command line creates four files in the /tmp/trash directory. The second command line creates a text file, using the lscommand s output, containing the names of the files under the /tmp/trash directory. The greater-than (>) character is called a standard output redirection operator, and is used to redirect the output of a command somewhere else. You also can use the less-than (<) character, or standard input redirection operator, to feed information to other programs. As a trivial example, you can use the file containing filenames created to build an archive using the cpio command. You can do this by using the standard input to feed the file names into the cpio command. # cpio -o
trash.cpio 1 block This command line causes the cpio command to read a list of files from the standard input, the trashfiles.txt file, and then creates an archive by sending its output through the standard output to a file called trash.cpio. Generally, most programs you run from the shell command line have the ability to read from the standard input and write to the standard output. Along with the standard input and standard output, there is also a standard error output (which almost always prints to your display). Using the previous example, if the list of files fed into the cpio command contains an error, the cpio command should complain, and send an error message to your screen: # rm -fr /tmp/trash/file3 # cpio -o < trashfiles.txt >trash.cpio cpio: /tmp/trash/file3: No such file or directory 1 block 6

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Unix Web Hosting services

Linux Operating Sistem

86 Hour 6 The bash shell also has

Filed under: Learn Linux in 24 hours — webmaster @ 1:17 am

86 Hour 6 The bash shell also has built-in help, and lists all the built-in commands, as well as help on each command. For example, # help GNU bash, version 1.14.7(1) Shell commands that are defined internally. Type `help’ to see this list. Type `help name to find out more about the function `name . Use `info bash to find out more about the shell in general. A star (*) next to a name means that the command is disabled. %[DIGITS | WORD] [&] . filename : [ arg… ] alias [ name[=value] … ] bg [job_spec] bind [-lvd] [-m keymap] [-f filena break [n] builtin [shell-builtin [arg …]] case WORD in [PATTERN [| PATTERN]. cd [dir] command [-pVv] [command [arg …]] continue [n] declare [-[frxi]] name[=value] … … while COMMANDS; do COMMANDS; done { COMMANDS } To get help with a particular command, type the command name after the help command. For example, to get help with help, type the following: # help help help: help [pattern …] Display helpful information about builtin commands. If PATTERN is specified, gives detailed help on all commands matching PATTERN, otherwise a list of the builtins is printed. For more information about the bash shell, you ll find a manual page, info pages you can browse with the info command, and documentation under the /usr/doc directory. The Public Domain Korn Shell ksh The pdksh, or public-domain Korn shell, originally by Eric Gisin, features 42 built-in commands, and 20 command-line options. This shell is found under the /bindirectory, but a symbolic link also exists under the /usr/bin directory. The pdksh shell is named ksh in your Linux system, and like the bash shell, reads the shell initialization script /etc/profile if a file called .profile does not exist in your home directory. Unfortunately, this shell does not support the same command-line prompts as the bash shell. However, this shell does support job control (discussed later this hour), so you can suspend, background, recall, or kill programs from the command line. This shell is nearly compatible with commercial versions of the Korn shell included with commercial UNIX distributions. Documentation for this shell is in the ksh manual page, and in the pdksh directory under the /usr/doc directory. 6

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Unix Web Hosting services

Linux Operating Sistem

86 Hour 6 The bash shell also has

Filed under: Linux Web Hosting — webmaster @ 1:17 am

Using the Shell 87 Features of the csh-Compatible Shell tcsh The tcsh shell, by William Joy (and 47 other contributors), features 53 built-in commands, and 18 command-line options. This shell emulates the csh shell, but has many more features, including a command-line editor with spelling correction. This shell is not only compatible with the bash shell prompts, it offers more prompt options than bash. Tcsh uses the file csh.cshrcunder the /etc/directory if the .tcshrc or .cshrcfile does not exist in your home directory. Like the bash shell, you can scroll through commands you ve entered and edit the command line. Get a list of the tcsh commands by using the builtinscommand (the tcsh does not have help like the bash shell). # builtins : @ alias alloc bg bindkey break breaksw builtins case cd chdir complete continue default dirs echo echotc else end endif endsw eval exec exit fg filetest foreach glob goto hashstat history hup if jobs kill limit log login logout ls-F nice nohup notify onintr popd printenv pushd rehash repeat sched set setenv settc setty shift source stop suspend switch telltc time umask unalias uncomplete unhash unlimit unset unsetenv wait where which while For more information about this shell, read the tcsh manual page, or look in the tcsh directory under the /usr/doc directory. You ll find a Frequently Asked Questions file and other text files. zsh The zsh shell, originally by Paul Falstad, is one of the largest shells for Linux, and features 84 built-in commands. The zsh shell has more than 50 different command-line options, and also emulates the sh and ksh shell commands. Like the bash and tcsh shells, the zsh shell enables you to scroll through previous commands and complete, edit, or spell check the command line. It also enables you to use job control to manage running programs. This shell features advanced command-line options for searching or matching file patterns. Systemwide startup files for this shell are in the /etc directory: /etc/zlogin /etc/zlogout /etc/zprofile /etc/zshenv /etc/zshrc 6

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Unix Web Hosting services

Linux Operating Sistem

II PART Hour 6 Using the Shell In

Filed under: Learn Linux in 24 hours — webmaster @ 4:07 pm

Using the Shell 85 JUST A MINUTE There are several other shells that also are included with Linux: tclsh, a simple shell and Tcl interpreter; wish, a windowing shell for X11; and rsh, a remote shell for running commands over a network. For details, see the tclsh, wish, and rsh manual pages. Features of ash The ash shell, by Kenneth Almquist, is one of the smallest shells available for Linux. This shell has 24 different built-in commands, and 10 different command-line options. The ash shell supports most of the common shell commands, such as cd, along with most of the normal command-line operators (discussed in the later section, Understanding the Shell Command Line ). Features of the Default Linux Shell bash The bash, or Bourne Again SHell, by Brian Fox and Chet Ramey, is the default Red Hat Linux shell. It features 48 built-in commands and a dozen command-line options. The bash shell works just like the sh shell, and you ll find a symbolic link under the /bin directory, called sh, that points to the bash shell. Not only does bash work like the sh shell, but it also has features of the csh and ksh shells. Because this is the default shell, bash is used for the examples in this hour. Later on you ll be shown how to customize your command-line prompt using the bash shell. The bash shell has many features. You can scroll through your previous commands with the arrow keys, edit a command line, and if you forget the name of program, you can even ask the shell for help by using command-line completion. You do this by typing part of a command and then pressing the Tab key. For example, if you type l and press the Tab key, you d see the following: # l laser less listres locale look lsac last lesskey lkbib localedef lookbib lsattr lastb let lmorph locate lpq lsc latex lex ln lockfile lpr lsl lbxproxy lha lndir logger lprm lynx ld lightning loadkeys login lptest lz ld86 lisa loadunimap logname ls ldd lispmtopgm local logout lsa The bash shell responds by listing all known commands beginning with the letter l. This can be very handy if you can t remember complex command names. 6

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Linux Web Hosting services

Linux Operating Sistem

II PART Hour 6 Using the Shell In

Filed under: Learn Linux in 24 hours — webmaster @ 4:07 pm

84 Hour 6 The shell is a command-line interpreter, and may be used to start, suspend, stop, or even write programs. The shell is an integral part of Linux, and is part of the design of Linux and UNIX. If you imagine the Linux kernel as the center of a sphere, the shell is the outer layer surrounding the kernel. When you pass commands from the shell, or other programs, to Linux, the kernel (usually) responds appropriately. There are many types of shells, but at least five (not counting the visual shell Midnight Commander) are on your CD-ROM. You can determine which shell you ll use when you log in to Linux by either looking at the contents of the /etc/passwd file, or by searching the file for your username. Look at the following example: # fgrep bball /etc/passwd bball:OmB5tToB8fYLQ:500:500:William H. Ball,,,,:/home/bball:/bin/bash Your shell will be listed at the end of your passwd file entry (/bin/bash in the fgrep search example). What Shells Are Available? This section lists the shells available for your system, along with some unique features of each to get you started. Each of these shells runs programs, and you may want to explore each to see how they work. This section highlights some of their differences and points out important files. All of these shells support changing directories with a built-in cd, or the change directory command. Interestingly, the ash and tcsh shells do not have a built-in pwd, or print working directory commands, and must instead rely on the pwd command found under the /bin directory. These shells have many, many features. You ll want to read the manual pages for each in detail. Some of the features to look for and explore include the following: What are the shell s built-in commands? How is job control (or background processes, discussed in a later section, Running Programs in the Background ) handled? Does the shell support command-line editing? Does the shell support command-line history? What are the important startup or configuration files? What environmental variables are important for each shell? What command-line prompts may I use? What programming constructs are supported? 6

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Linux Web Hosting services

Linux Operating Sistem

II PART Hour 6 Using the Shell In

Filed under: Linux Web Hosting — webmaster @ 4:07 pm

II PART Hour 6 Using the Shell In this hour you ll be introduced to the shell. Although the trend in personal computing in the last 10 years has been to move away from the command line to a point-and-click interface, the shell is still very much alive in Linux, and is used by many Linux programs. This hour doesn t go into a detailed history of Linux or UNIX shells, or take sides in a debate over which computing interface is easier or better to use. Nor does this hour delve into shell programming there s also not enough room in this hour (or even this book) to do so. This hour does, however, discuss the different shells you ll find on your CD-ROM, show you how to use the shell to make your Linux experience more enjoyable, and highlight some of the basics of using the shell and its command line. What Is a Shell? If you re not using the X Window System, the shell is one of the most important programs you ll use. The shell provides the interface to Linux so you can run programs. In fact, the shell is just another Linux program. While you can set up and run Linux without a shell (see Hour 20, Basic System Administration, for details), you may find that you ll do a lot of typing at the shell s command line.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Linux Web Hosting services

Next Page »

Powered by Linux Web Hosting