Archive for April, 2007

67Chapter 2Running Commands from the (Top ten web hosting) ShellThe nine bits

Monday, April 30th, 2007

67Chapter 2Running Commands from the ShellThe nine bits assigned to each file for permissions define the access that you andothers have to your file. Permission bits appear as rwxrwxrwx. The first three bitsapply to the owner s permission, the next three apply to the group assigned to thefile, and the last three apply to all others. The rstands for read,the w stands forwrite,and the x stands for execute permissions. If a dash appears instead of the let- ter, it means that permission is turned off for that associated read, write, or execute. Because files and directories are different types of elements, read, write, and executepermissions on files and directories mean different things. Here s what you can dowith each of them: PermissionFileDirectoryReadView what s in the file.See what files and subdirectories it contains. WriteChange the file s content, Add files or subdirectories to the directory. rename it, or delete it. ExecuteRun the file as a program.Change to that directory as the currentdirectory, search through the directory, orexecute a program from the directory. You can see the permission for any file or directory by typing the ls -ldcommand. The named file or directory appears as those shown in this example: $ ls -ld ch3 test-rw-rw-r– 1 chris sales 4983 Jan 18 22:13 ch3drwxr-xr-x 2 chris sales 1024 Jan 24 13:47 testThe first line shows that the ch3file has read and write permission for the owner andthe group. All other users have read permission, which means they can view the filebut cannot change its contents or remove it. The second line shows the testdirec- tory (indicated by the letter dbefore the permission bits). The owner has read, write, and execute permission, while the group and other users have only read andexecute permissions. As a result, the owner can add, change, or delete files in thatdirectory, and everyone else can only read the contents, change to that directory, and list the contents of the directory. If you own a file, you can use the chmodcommand to change the permission on it asyou please. In one method of doing this, each permission (read, write, and execute), is assigned a number r=4, w=2, and x=1 and you use each set s total number toestablish the permission. For example, to make permissions wide open for yourselfas owner, you d set the first number to 7 (4+2+1), and to give the group and othersonly read permission, you d set both the second and third numbers to 4 (4+0+0), sothat the final number is 744. Any combination of permissions can result from 0 (nopermission) through 7 (full permission).
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services

66Part ILinux First StepsIn the (Java web server) first example, any

Monday, April 30th, 2007

66Part ILinux First StepsIn the first example, any file beginning with a, b, or wis matched. In the second, anyfile that begins with a, g, or wand also ends with either nor eis matched. You canalso include ranges within brackets. For example: $ ls [a-g]* apple banana grape grapefruitHere, any filenames beginning with a letter from athrough gis matched. Using File-Redirection MetacharactersCommands receive data from standard input and send it to standard output. Usingpipes (described earlier), you can direct standard output from one command to thestandard input of another. With files, you can use less-than (<) and greater-than (>) signs to direct data to and from files. Here are the file redirection characters: .< Direct the contents of a file to the command. .> Direct the output of a command to a file, deleting the existing file. .>> Direct the output of a command to a file, adding the output to the end ofthe existing file. Here are some examples of command lines where information is directed to andfrom files: $ mail root < ~/.bashrc$ man chmod | col -b > /tmp/chmod$echo I finished the project on $(date) >> ~/projectsIn the first example, the contents of the .bashrcfile in the home directory are sentin a mail message to the computer s root user. The second command line formatsthe chmodman page (using the mancommand), removes extra back spaces (col -b) and sends the output to the file /tmp/chmod (erasing the previous /tmp/chmodfile, if it exists). The final command results in the following text being added to the user sproject file: I finished the project on Sat Jan 22 13:46:49 PST 2005Understanding File PermissionsAfter you ve worked with Linux for a while, you are almost sure to get a Permissiondenied message. Permissions associated with files and directories in Linux weredesigned to keep users from accessing other users private files and to protectimportant system files.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision personal web hosting services

65Chapter 2Running Commands from (Professional web hosting) the ShellTry out some

Monday, April 30th, 2007

65Chapter 2Running Commands from the ShellTry out some of these file-matching metacharacters by first going to an empty direc- tory (such as the testdirectory described in the previous section) and creatingsome empty files: $ touch apple banana grape grapefruit watermelonThe touchcommand creates empty files. The next few commands show you how touse shell metacharacters with the lscommand to match filenames. Try the followingcommands to see if you get the same responses: $ ls a* apple$ ls g* grapegrapefruit$ ls g*tgrapefruit$ ls *e* apple grape grapefruit watermelon$ ls *n* banana watermelonThe first example matches any file that begins with an a(apple). The next examplematches any files that begin with g(grape, grapefruit). Next, files beginning withg and ending in tare matched (grapefruit). Next, any file that contains an ein thename is matched (apple, grape, grapefruit, watermelon). Finally, any file thatcontains an nis matched (banana, watermelon). Here are a few examples of pattern matching with the question mark (?): $ ls ????eapple grape$ ls g???e* grape grapefruitThe first example matches any five-character file that ends in e(apple, grape). Thesecond matches any file that begins with gand has eas its fifth character(grape, grapefruit). Here are a couple of examples using braces to do pattern matching: $ ls [abw]* apple banana watermelon$ ls [agw]*[ne] apple grape watermelon07_
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

64Part ILinux First StepsThis step changes (Java web server) the permissions

Monday, April 30th, 2007

64Part ILinux First StepsThis step changes the permissions of the directory to give you complete access andeveryone else no access at all. (The new permissions should read like rwx——.) 5.Last, make the test directory your current directory as follows: $ cd testUsing Metacharacters and OperatorsTo make efficient use of your shell, the bash shell lets you use certain special char- acters, referred to as metacharacters and operators. Metacharacters can help youmatch one or more files without typing each file completely. Operators let youdirect information from one command or file to another command or file. Using File-Matching MetacharactersTo save you some keystrokes and to be able to refer easily to a group of files, thebash shell lets you use metacharacters. Anytime you need to refer to a file or direc- tory, such as to list it, open it, or remove it, you can use metacharacters to matchthe files you want. Here are some useful metacharacters for matching filenames: .* Matches any number of characters. .? Matches any one character. .[…] Matches any one of the characters between the brackets, which caninclude a dash-separated range of letters or numbers. Identifying DirectoriesWhen you need to identify your home directory on a shell command line, you can use thefollowing: .$HOME This environment variable stores your home directory name. .~ The tilde (~) represents your home directory on the command line. You can also use the tilde to identify someone else s home directory. For example, ~chriswould be expanded to the chrishome directory (probably /home/chris). Other special ways of identifying directories in the shell include the following: .. A single dot (.) refers to the current directory. … Two dots (..) refers to a directory directly above the current directory. .$PWD This environment variable refers to the current working directory. .$OLDPWD This environment variable refers to the previous working directory beforeyou changed to the current one.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services

63Chapter 2Running Commands from the ShellCreating Files and (Cheapest web hosting)

Sunday, April 29th, 2007

63Chapter 2Running Commands from the ShellCreating Files and DirectoriesAs a Linux user, most of the files you save and work with will probably be in yourhome directory. Here are commands to create and use files and directories: CommandResultcdChange to another current working directory. pwdPrint the name of the current working directory. mkdirCreate a directory. chmodChange the permission on a file or directory. lsList the contents of a directory. The following steps lead you through creating directories within your home direc- tory and moving among your directories, with a mention of setting appropriate filepermissions: 1.Go to your home directory. To do this, simply type cd. (For other ways ofreferring to your home directory, see the Identifying Directories sidebar.) 2.To make sure that you got to your home directory, type pwd. When I do this, Iget the following response (yours will reflect your home directory): $ pwd/home/chris3.Create a new directory called testin your home directory, as follows: $ mkdir test4.Check the permissions of the directory: $ ls -ld testdrwxr-xr-x 2 chris sales 1024 Jan 24 12:17 testThis listing shows that test is a directory (d); followed by the permissions(rwxr-xr-x), which are explained later in the Understanding File Permissions section; the owner (chris); the group (sales); and that the file was mostrecently modified on Jan. 24 at 12:17 p.m. In some Linux systems, such as Fedora Core, when you add a new user, the user isassigned to a group of the same name by default. For example, in the precedingtext, the user chriswould be assigned to the group chris. This approach toassigning groups is referred to as the user private group scheme. For more infor- mation on user private groups, see Chapter 4. For now, type the following: $ chmod 700 testNote07_
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

62Part ILinux First Steps ./home Contains directories assigned to (Web site development)

Sunday, April 29th, 2007

62Part ILinux First Steps ./home Contains directories assigned to each user with a login account. ./mnt Provides a location for mounting devices, such as remote file systemsand removable media (with directory names of cdrom, floppy, and so on). ./proc Contains information about system resources. ./root Represents the root user s home directory. ./sbin Contains administrative commands and daemon processes. ./sys(A /proc-like file system, new in the Linux 2.6 kernel and intended tocontain files for getting hardware status and reflecting the system s devicetree as it is seen by the kernel. It pulls many of its functions from /proc. ./tmp Contains temporary files used by applications. ./usr Contains user documentation, games, graphical files (X11), libraries(lib), and a variety of other user and administrative commands and files. ./var Contains directories of data used by various applications. In particular, this is where you would place files that you share as an FTP server (/var/ftp) or a Web server (/var/www). It also contains all system log files (/var/log). The file systems in the DOS or Microsoft Windows operating systems differ fromLinux s file structure, as the Linux File Systems Versus Windows-Based File Systems sidebar explains. Linux File Systems Versus Windows-Based File SystemsAlthough similar in many ways, the Linux file system has some striking differences from filesystems used in MS-DOS and Windows operating systems. Here are a few: .In MS-DOS and Windows file systems, drive letters represent different storage devices(for example, A: is a floppy drive and C: is a hard disk). In Linux, all storage devicesare fit into the file system hierarchy. So, the fact that all of /usrmay be on a separatehard disk or that /mnt/rem1is a file system from another computer is invisible tothe user. .Slashes, rather than backslashes, are used to separate directory names in Linux. So, C:homechrisin an MS system is /home/chrisin a Linux system. .Filenames almost always have suffixes in DOS (such as .txtfor text files or .docfor word-processing files). Although at times you can use that convention in Linux, three-character suffixes have no required meaning in Linux. They can be useful foridentifying a file type. .Every file and directory in a Linux system has permissions and ownership associatedwith it. Security varies among Microsoft systems. Because DOS and MS Windowsbegan as single-user systems, file ownership was not built into those systems whenthey were designed. Later releases added features such as file and folder attributesto address this problem.
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services

61Chapter 2Running Commands from the ShellIf you were (Free web hosting music)

Sunday, April 29th, 2007

61Chapter 2Running Commands from the ShellIf you were to map out the files and directories in Linux, it would look like anupside-down tree. At the top is the root directory, which is represented by a singleslash (/). Below that is a set of common directories in the Linux system, such asbin, dev, home, lib, and tmp, to name a few. Each of those directories, as well asdirectories added to the root, can contain subdirectories. Figure 2-1 illustrates how the Linux file system is organized as a hierarchy. Todemonstrate how directories are connected, the figure shows a /homedirectorythat contains subdirectories for three users: chris, mary, and tom. Within thechrisdirectory are subdirectories: briefs, memos, and personal. To refer to afilecalled inventoryin the chris/memosdirectory, you could type the full pathof/home/chris/memos/inventory. If your current directory were /home/ chris/memos, you could refer to the file as simply inventory. Figure 2-1:The Linux file system is organized as a hierarchy of directories. Some of the Linux directories that may interest you include the following: ./bin Contains common Linux user commands, such as ls, sort, date, andchmod. ./boot Has the bootable Linux kernel and boot loader configuration files(GRUB). ./dev Contains files representing access points to devices on your systems. These include terminal devices (tty*), floppy disks (fd*), hard disks (hd*), RAM (ram*), and CD-ROM (cd*). (Users normally access these devices directlythrough the device files.) ./etc Contains administrative configuration files. bin/dev/etc/home/ / root/ chris/mary/tom/ briefs/memos/personal/ tmp/ …
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

Web hosting control panel - 60Part ILinux First StepsUsing Foreground and Background CommandsContinuing

Saturday, April 28th, 2007

60Part ILinux First StepsUsing Foreground and Background CommandsContinuing with the example, you can bring any of the commands on the jobs list tothe foreground. For example, to edit myfileagain, type$fg %1As a result, the vicommand opens again, with all text as it was when you stoppedthe vi job. Before you put a text processor, word processor, or similar program in the back- ground, make sure you save your file. It s easy to forget you have a program in thebackground and you will lose your data if you log out or the computer rebootslater on. To refer to a background job (to cancel or bring it to the foreground), use a percentsign (%) followed by the job number. You can also use the following to refer to abackground job: .% Refers to the most recent command put into the background (indicatedby the plus sign). This action brings the command to the foreground. .%string Refers to a job where the command begins with a particularstringof characters. The stringmust be unambiguous. (In other words, typing%viwhen there are two vicommands in the background results inanerror message.) .%?string Refers to a job where the command line contains a stringat anypoint. The string must be unambiguous or the match will fail. .%– Refers to the previous job stopped before the one most recently stopped. If a command is stopped, you can start it running again in the background using the bgcommand. For example, take job number 5 from the jobs list in the previous example: [5]+ Stopped nroff -man man4/* >/tmp/man4Type the following: $ bg %5After that, the job runs in the background. Its jobs entry appears as follows: [5] Running nroff -man man4/* >/tmp/man4 & Working with the Linux File SystemThe Linux file system is the structure in which all the information on your computeris stored. Files are organized within a hierarchy of directories. Each directory cancontain files, as well as other directories. Caution07_
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services

59Chapter 2Running Commands from the ShellYou can place (Web hosting servers)

Saturday, April 28th, 2007

59Chapter 2Running Commands from the ShellYou can place an active program in the background in several ways. One mentionedearlier is to add an ampersand (&) to the end of a command line. Another way is touse the atcommand to run commands in a way in which they are not connected tothe shell. To stop a running command and put it in the background, press Ctrl+Z. After the com- mand is stopped, you can either bring it to the foreground to run (the fgcommand) or start it running in the background (the bgcommand). Starting Background ProcessesIf you have programs that you want to run while you continue to work in the shell, you can place the programs in the background. To place a program in the backgroundat the time you run the program, type an ampersand (&) at the end of the commandline, like this: $ find /usr > /tmp/allusrfiles & This example command finds all files on your Linux system (starting from /usr), prints those filenames, and puts those names in the file /tmp/allusrfiles. Theampersand (&) runs that command line in the background. To check which com- mands you have running in the background, use the jobscommand, as follows: $ jobs[1] Stopped (tty output) vi /tmp/myfile[2] Running find /usr -print > /tmp/allusrfiles & [3] Running nroff -man /usr/man2/* >/tmp/man2 & [4]- Running nroff -man /usr/man3/* >/tmp/man3 & [5]+ Stopped nroff -man /usr/man4/* >/tmp/man4The first job shows a text-editing command (vi) that I placed in the backgroundand stopped by pressing Ctrl+Z while I was editing. Job 2 shows the findcommandI just ran. Jobs 3 and 4 show nroffcommands currently running in the background. Job 5 had been running in the shell (foreground) until I decided too many processeswere running and pressed Ctrl+Z to stop job 5 until a few processes had completed. The plus sign (+) next to number 5 shows that it was most recently placed inthebackground. The minus sign (-) next to number 4 shows that it was placedinthe background just before the most recent background job. Because job 1requires terminal input, it cannot run in the background. As a result, it is Stoppeduntil it is brought to the foreground again. To see the process ID for the background job, add a -loption to the jobscom- mand. If you type ps, you can use the process ID to figure out which command isfor a particular background job. Tip07_
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

58Part ILinux First StepsThe (Web server address) problem with setting environment

Saturday, April 28th, 2007

58Part ILinux First StepsThe problem with setting environment variables in this way is that as soon as youexit the shell in which you set the variable, the setting is lost. To set variables per- manently, add variable settings to a bash configuration file, as described later inthis section. If you want to have other text right up against the output from an environment vari- able, you can surround the variable with braces. This protects the variable namefrom being misunderstood. For example, if you wanted to add a command name tothe ABvariable shown earlier, you could type the following: $ echo ${AB}/adventure/usr/dog/contagious/ringbearer/grind/adventureRemember that you must export the variable so that it can be picked up by othershell commands. You must add the export line to a shell configuration file for it totake effect the next time you log in. The exportcommand is fairly flexible. Insteadof running the exportcommand after you set the variable, you can do it all in onestep, as follows: $ export XYZ=/home/xyz/binYou can override the value of any environment variable. This can be temporary, bysimply typing the new value, or you can add the new export line to your$HOME/.bashrcfile. One useful variable to update is PATH: $ export PATH=$PATH:/home/xyz/binIn this example the /home/xyz/bindirectory is added to the PATH, a useful tech- nique if you want to run a bunch of commands from a directory that is not normallyin your PATH, without typing the full or relative path each time. If you decide that you no longer want a variable to be set, you can use the unsetcommand to erase its value. For example, you could type unset XYZ, which wouldcause XYZto have no value set. (Remember to remove the export from the $HOME/. bashrcfile if you added it there or it will return the next time you open a shell.) Managing Background and Foreground ProcessesIf you are using Linux over a network or from a dumbterminal (a monitor thatallows only text input with no GUI support), your shell may be all that you have. You may be used to a windowing environment where you have a lot of programsactive at the same time so that you can switch among them as needed. This shellthing can seem pretty limited. Although the bash shell doesn t include a GUI for running many programs, it doeslet you move active programs between the background and foreground. In this way, you can have a lot of stuff running while selectively choosing the one you want todeal with at the moment.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web and email hosting services