Linux Web Hosting

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

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

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

80 Hour 5 extract mydir/mydir2/file23?y mydir/mydir2/file23 Here, I ve

Filed under: Learn Linux in 24 hours — webmaster @ 8:36 am

80 Hour 5 extract mydir/mydir2/file23?y mydir/mydir2/file23 Here, I ve gone through the archive, interactively extracting files. If you want just a single file from an archive, you can specify the file on the command line. For this example, the original mydir has been removed, and I m using an empty directory: # tar -xf mydir.tar mydir/mydir2/file23 # tree mydir mydir `– mydir2 `– file23 1 directory, 1 file As you can see, only one file was extracted. Be careful, though! The tar command won t overwrite whole directories, but it will overwrite files with the same name. Try experimenting with tarbefore you start building archives. Some other features to try are selectively deleting files from an archive, or adding a file to an existing archive, which is something the next program, cpio, can do, too. Creating cpio Archives The cpio command copies files in and out of tar or cpio archives. Because it is compatible with tar, this section won t go into all the details of how it works, but it has some features that tar does not, such as Support for both cpio and tar archives Support for a number of older tape formats The ability to read filenames from a pipe (which you ll learn about in the next hour) Very few, if any, software packages for Linux are distributed in cpioformat. Chances are you won t run across any cpio archives in your search for new software across the Internet. But if you re interested in the details about cpio, see its man page. Compressing Files with the gzip Command The gzip command compresses files. This program is not only handy for saving disk space by compressing large, less often used files, but could be, in combination with tar, the most popular compressed file format for Linux. You ll often find files with the .tgz or .tar.gz format while searching for new Linux software across the Internet. You ll also find that much of the documentation under your /usr/doc directory has been compressed with gzip. This can save a lot of space. According the Free Software Foundation folks in gzip s manual page, gzip has a 60 to 70 percent compression rate for text files. 5

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

Linux Operating Sistem

Manipulation and Searching Commands 77 This pattern works

Filed under: Learn Linux in 24 hours — webmaster @ 2:16 am

78 Hour 5 magnetic tape, so one of the first programs to run on computers was a tape reader. Over time, the tar program has proved its merit as a convenient way to transport files, and many programs you ll find for Linux come packaged in tararchives (your Red Hat CD-ROM uses the rpm program to package files; see Hour 22, Red Hat Tools ). Using tar, you can create an archive file containing multiple directories and multiple files. The version of tarinstalled on your system also supports a -zoption to use the gzipprogram to compress your archive (gzip is discussed later in this chapter). The tarcommand has a bewildering array of options, but it s not hard to use. You can quickly and easily create an archive of any desired directory. First, you ll create a directory with three files, and then create a subdirectory with another three files: # mkdir mydir # cd mydir # touch file1 file2 file3 # mkdir mydir2 # cd mydir2 # touch file21 file22 file23 # cd ../.. # tree mydir mydir |– file1 |– file2 |– file3 `– mydir2 |– file21 |– file22 `– file23 1 directory, 6 files Now that you have built a directory, create a tar archive with this command: # tar -c mydir > mydir.tar # ls -l total 11 drwxrwxr-x 3 bball bball 1024 Nov 14 16:48 mydir -rw-rw-r–1 bball bball 10240 Nov 14 16:58 mydir.tar Notice that your original directory is left untouched. By default, tar will not delete the original directories or files. You can use the –remove-files if you d like to do this, but it s not recommended. If you d like to see what s going on, you can use the -v option, like this: # tar -cv mydir > mydir.tar mydir/ mydir/file1 mydir/file2 mydir/file3 mydir/mydir2/ 5

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

Linux Operating Sistem

Manipulation and Searching Commands 77 This pattern works

Filed under: Learn Linux in 24 hours — webmaster @ 2:16 am

Manipulation and Searching Commands 79 mydir/mydir2/file21 mydir/mydir2/file22 mydir/mydir2/file23 The tarcommand will show you what directories and files are being added. Does this mean you have to add all of the files in your directories? No! You can use the -w, or interactive option, and have tar ask you if you want each file added. This can be handy for selectively backing up small directories, for example: # tar -cw mydir > mydir.tar add mydir?y add mydir/file1?n add mydir/file2?y add mydir/file3?n add mydir/mydir2?y add mydir/mydir2/file21?y add mydir/mydir2/file22?n add mydir/mydir2/file23?y Here I ve left out file1, file3, and file22 from this archive. But how can you make sure? One way is to use two tar options, -t to list an archive s contents, and -f, to specify a tar archive to use, for example: # tar tf mydir.tar mydir/ mydir/file2 mydir/mydir2/ mydir/mydir2/file21 mydir/mydir2/file23 Note that the order of the options is important (like the grepexample), or tarwill complain and quit. Now that you know how to create and see the contents of an archive, you can learn how to extract the whole archive or a single file. To extract everything, you can use the -x, or extract option with -f. Just so you know what s going on, include the -v option, too: # tar -xvf mydir.tar mydir/ mydir/file2 mydir/mydir2/ mydir/mydir2/file21 mydir/mydir2/file23 If you want only a few files from your archive, you can again use the -w option: # tar -xvwf mydir.tar extract mydir/?y mydir/ extract mydir/file2?y mydir/file2 extract mydir/mydir2/?y mydir/mydir2/ extract mydir/mydir2/file21?y mydir/mydir2/file21 5

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

Linux Operating Sistem

Manipulation and Searching Commands 77 This pattern works

Filed under: Learn Linux in 24 hours — webmaster @ 2:16 am

Manipulation and Searching Commands 77 This pattern works with grepand fgrep. If you try this pattern with egrep, you ll get the same results as if you tried extended regular expressions with grep (each line with a b). Each grep program accepts nearly the same set of command-line options. One popular option is -n, or line numbering. This is handy because you ll see which lines in the file contain matches. This example works for each grep program: # egrep -n friend guide.txt 1242:large extent by the window manager. This friendly program is in 1942:copy Linux from a friend who may already have the software, or share 5161:(Unfortunately, the system was being unfriendly.) You can see that matches were made on lines 1242, 1942, and 5161. Another feature of these programs is that you don t have to retype your patterns each time you want to search. As a simple example, if you need to repeatedly search files for different words, you can put these into a file for grep to use. First, create a text file, then use the -f option to specify the file: # cat > mywords wonderful Typewriter War # grep -nf mywords guide.txt 574:Typewriter Used to represent screen interaction, as in 617:software since the original Space War, or, more recently, Emacs. It 1998:Now you must be convinced of how wonderful Linux is, and all of the 2549:inanimate object is a wonderful way to relieve the occasional stress 3790: Warning: Linux cannot currently use 33090 sectors of this 7780:to wear the magic hat when it is not needed, despite the wonderful 10091:wonderful programs and configurations are available with a bit of work Because you also used the line-numbering option, you should note that it had to come before the -f, or file option, or grepwould report an error, complain it couldn t find file n, and quit. You can make grepact like fgrepwith the -Foption, or like egrepwith the -Eoption. You ll also find a unique version of grep on your system, called zgrep, which you can use to search compressed files, the topic of the next section. Compressing and Uncompressing Files This section introduces you to the basics of archiving and compressing files. However, for details concerning using these programs for the purpose of system management or backing up your system, see Hour 23, Archiving. Read on, and you ll learn how to build your own archives and save disk space. Creating Archives with the Tape Archive Command The tar (tape archive) program has its roots in the early days of computing before floppy drives, hard disks, and CD-ROMs. Software was distributed and backed up on large reels of 5

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

Linux Operating Sistem

74 Hour 5 What Are Regular Expressions? Regular

Filed under: Learn Linux in 24 hours — webmaster @ 8:20 pm

76 Hour 5 using some of the common options. For specific details about the pattern-matching capabilities of these programs, see the grep manual page. To show you the difference in each program s search pattern syntax, I ll look for different patterns in Matt Welsh s Linux Basic Installation Guide(available athttp://sunsite.unc.edu/ LDP). For example, if you want to find all lines in the guide that begin with a number, use the following syntax: # grep ^[0-9] guide.txt 1 Introduction to Linux 1 2 Obtaining and Installing Linux 40 3 Linux Tutorial 85 4 System Administration 137 … # egrep ^[0-9] guide.txt 1 Introduction to Linux 1 2 Obtaining and Installing Linux 40 3 Linux Tutorial 85 4 System Administration 137 … # fgrep ^[0-9] guide.txt You can see that grep and egrepreturned a search (I ve deleted all the output except the first four lines). Notice, however, that fgrep cannot handle regular expressions. You must use fixed patterns, or strings with the fgrep command, for example: # fgrep friend guide.txt large extent by the window manager. This friendly program is in copy Linux from a friend who may already have the software, or share (Unfortunately, the system was being unfriendly.) Now use egrep to try searching for the pattern of the letter b in parentheses in the file: # egrep ([b]) guide.txt (see Section 1.8 for a list of compatible boards), or (b) there is an connect to the network, or (b) you have a “dynamic IP address, You see that there are exactly two lines in the file that match (b). See what happens when you search with grep: # grep ([b]) guide.txt This is version 2.2.2 of the book, Linux Installation and Getting to PostScript printers. This document was generated by a set of tools from LaTeX source, so there may be a number of formatting problems. This is not the official version of the book! Please see … Whoa! Not exactly what you wanted, is it? As you can see, grepdoes not use the same syntax as the egrep command. But you can use a simpler approach: # grep (b) guide.txt (see Section 1.8 for a list of compatible boards), or (b) there is an connect to the network, or (b) you have a “dynamic IP address, 5

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

Next Page »

Powered by Linux Web Hosting