intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Networking: A Beginner’s Guide Fifth Edition- P71

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:5

49
lượt xem
2
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Networking: A Beginner’s Guide Fifth Edition- P71:I have run into many people over the years who have gained good even impressive working knowledge of PCs, operating systems, applications, and common problems and solutions. Many of these people are wizards with desktop computers.

Chủ đề:
Lưu

Nội dung Text: Networking: A Beginner’s Guide Fifth Edition- P71

  1. 332 Networking: A Beginner’s Guide TIP Before you get into a “which interface is better” holy war with someone, remember that both types of interfaces serve a purpose, with each having weaknesses as well as benefits. In the end, the person who chooses to master both will come out ahead. This section covers some of the Linux command-line tools that are most crucial for day-to-day work. All of the commands discussed in this section are to be performed in a terminal window. You can open a terminal window by opening the Applications menu and choosing System Tools, then Terminal. This window displays a prompt that looks something like [root@hostname /root]#, where hostname is the name of your machine. Working from the Command Line One of the difficulties in moving to the Linus command-line interface, especially if you are used to using Windows command-line tools such as cmd.exe, is dealing with a shell that has a great number of shortcuts that might surprise you if you’re not careful. This section reviews the most common of these shortcuts. Filename Expansion Under UNIX-based shells such as bash, you expand wildcards seen on the command line before passing them as a parameter to the application. This is in sharp contrast to the default mode of operation for DOS-based tools, which often need to perform their own wildcard expansion. This also means that you must be careful where you use the wildcard characters. The wildcard characters themselves are identical to those in cmd.exe. The asterisk (*) matches against all filenames, and the question mark (?) matches against single characters. If you need to use these characters as part of another parameter, you can “escape” them by placing a backslash (\) in front of them. This character will cause the shell to interpret a wildcard as just another character. Environment Variables as Parameters You can use environment variables as parameters on the command line. This means that issuing the parameter $FOO will result in passing the value of the FOO environment variable instead of the string “$FOO.” Multiple Commands Under the bash shell, it is possible to execute multiple commands on the same line by separating them with a semicolon (;). For example, suppose that you want to execute the following sequence of commands on a single line: [root@ford /root]# ls -l [root@ford /root]# cat /etc/hosts
  2. Chapter 21: Introduction to Linux Systems Administration 333 You could instead type the following: [root@ford /root]# ls -l ;cat /etc/hosts Backticks How’s this for wild: you can make the output of one program the parameter of another program. Sound bizarre? Well, it’s time to get used to it—this is one of the most creatively used features available in all UNIX shells. A backtick (`) enables you to embed commands as parameters to other commands. A common instance of the use of this character is to pass a number sitting in a file as a parameter to the kill command. A typical instance of this occurs with the DNS server named. When this server starts, it writes its process identification number into the file /var/run/named.pid. Thus, the generic way of killing the named process is to look at the number in /var/run/named.pid using the cat command, and then issue the kill command with that value, as in the following example: root@ford /root]# cat /var/run/named.pid 253 [root@ford /root]# kill 253 One problem with killing the named process this way is that you cannot automate the killing, so you are counting on the fact that a human will read the value in /var/ run/ named.pid and then kill the number. The second problem isn’t so much a problem as it is a nuisance—it takes two steps to stop the DNS server. Using backticks, however, you can combine the steps into one and do so in a way that you can automate. Here’s the backticks version: [root@ford # kill'cat /var/run/named.pid' When the bash shell sees this command, it will first run cat /var/run/named.pid and store the result. It will then run the kill command and pass the stored result to it—all in one graceful step. Environment Variables The concept of environment variables is almost the same under Linux as it is under Windows. The only difference is in how you set, view, and remove the variables. Printing Environment Variables To list all of your environment variables, use the printenv command, as in the following example: [root@ford /root]# printenv
  3. 334 Networking: A Beginner’s Guide To show a specific environment variable, specify the variable as a parameter to printenv. For example, to see the environment variable USER, type the following: [root@ford /root]# printenv USER Setting Environment Variables To set an environment variable, use the following format: [root@ford /root]# variable=value where variable is the variable name, and value is the value that you want to assign the variable. For example, to set the environment variable FOO with the value BAR, type the following: [root@ford /root]# FOO=BAR After setting the value, use the export command to finalize it. The format of the export command is as follows: [root@ford /root]# export variable where variable is the name of the variable. In the example of setting FOO, type the following: [root@ford /root]# export FOO You can combine the steps of setting the environment variable with the export command, as follows: [root@ford /root]# export FOO=BAR If the value of the environment variable you want to set has spaces in it, you need to surround the variable with quotation marks. For example, to set FOO to “Welcome to the BAR of FOO,” type the following: [root@ford /root]# export FOO="Welcome to the BAR of FOO." Clearing Environment Variables To remove an environment variable, use the unset command: [root@ford /root]# unset variable where variable is the name of the variable you want to remove. For example, to remove the environment variable FOO, type the following: [root@ford]# unset FOO
  4. Chapter 21: Introduction to Linux Systems Administration 335 Documentation Tools Linux comes with two tremendously useful tools for making documentation accessible: man and info. Currently, the two documentation systems have a great deal of overlap between them, as many applications are moving their documentation to the info format. Info is considered superior to man because it allows the documentation to be hyperlinked together in a web-like way, without actually being written in HTML format. The man format, on the other hand, has been around for decades. Thousands of utilities have only man pages as their source of documentation. Furthermore, many applications continue to release their documentation in man format since many other UNIX-like operating systems such as Sun Solaris default to the man format for their documentation. As a result, both of these documentation systems will be around for a long while to come. Becoming comfortable with both of them is highly advisable. man: View Man Pages Man (short for manual) pages are documents found online covering the usage of tools and their corresponding configuration files. The format of the man command is as follows: [root@ford /root]# man program_name where program_name is the name of the program for which you want to read the manual page. Here’s an example: [root@ford /root]# man ls While reading about UNIX and UNIX-related sources for information (such as newsgroups), you might find references to commands followed by numbers in parentheses, as in ls(1). The number represents the section of the manual pages; each section covers various subject areas. The section numbers are handy for some tools, such as printf, that are commands in the C programming language as well as command-line commands. Thus, two entries would exist for such a command under two different sections. To refer to a specific section, simply specify the section number as the first parameter and the command as the second parameter. For example, to get the C programmers’ information on printf (assuming that the C programming man files are installed), enter the following: [root@ford /root]# man 3 printf To get the command-line information, enter the following: [root@ford /root]# man 1 printf By default, the manual page for the lowest section number is printed first. The section numbers’ meanings are shown in Table 21-1.
  5. 336 Networking: A Beginner’s Guide Section Number Meaning 1 User tools 2 System calls 3 C library calls 4 Device driver-related information 5 Configuration files 6 Games 7 Packages 8 System tools Table 21-1. Manual Page Section Numbers A handy option to the man command is -k. With this option, man will search the summary information of all the man pages and list which pages have a match along with their section number. For example, the following command will find pages matching the search criteria “printf”: [root@ford /root]# man -k printf info: View info Pages In addition to man pages, info pages are another common form of documentation. Established as the GNU standard, info is a documentation system that more closely resembles the Web in the sense that documents can be hyperlinked together, whereas man pages are single, static documents. Thus, info pages tend to be easier to read and understand. To read the info documents on a specific tool or application, simply invoke info with the parameter specifying the tool’s name. For example, to read about emacs, simply type the following: [root@ford /root]# info emacs Usually, you will first want to check if there is a man page. This is because a great deal more information is still available in the man format than in info format. However, some man pages will explicitly state that the info pages are more authoritative and should be read instead.
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2