HP-UX provides a number of useful commands to help users work with data and text, perform system administration tasks, and find information. Most commands are easy to enter, that is, these commands take no arguments (WhoAmI), or only a filename parameter (mkdir projects). The HP-UX command also has a more complex name that can be accompanied by options, parameters, or both.
Use options to change the behavior of the command. For example, in chapter 2nd, "Working with files and directories," using the-a option changes the behavior of the LS command, so you can list hidden file names. Typically, there is a dash (-) before the command option. Parameter provides additional information required by the command, such as the name of the file in which the command is run.
Examples of option usages
If you do not use any options, the RM command does not ask the user if they are sure that they want to delete the file when they delete it. For example, suppose the current working directory contains the following files: MyFile, Myfile1, Myfile2, Myfile3, and Myfile4. Type the following command to delete all of these files:
$ rm my*
$ 这样,所有文件均会被删除,并且不出现任何提示。
To have RM prompt the user for confirmation before deleting each file, use the-I (interactive) option:
$ rm -i my*
myfile1: ? (y/n) y 键入 y 删除该文件。
myfile2: ? (y/n) y
myfile3: ? (y/n) y
myfile4: ? (y/n) n 或者,键入 n 保留该文件。
$ ls
myfile4 myfile4 未被删除。
If RM is used interactively and does not have write permissions to the file (such as the-r--r--r--permissions listed using the LL command), the following message is displayed:
filename:444 mode? (yes/no)
If you want to delete the file, answer Y.
Example of parameter usage
The CAL command is used to display the English calendar for the month. If you use more than one command parameter, you can also specify the month and year you want to display in your calendar. For example, to display the calendar for February 1998, type the CAL command as follows:
Cal (1)
$ cal 2 1998 February 1998 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 1415 16 17 18 19 20 2122 23 24 25 26 27 28
Be sure to enter the number representing the century 19. If you use 98 as a parameter, you will get the calendar for 98 A.D.
Use single quotes for parameters
If a single command parameter contains embedded spaces, it must be enclosed in quotation marks (' Word1 word2 '). For example, the following grep command displays each row in the MyFile file that contains "I am":
grep (1)
$ grep 'I am' myfileThe text I am typing will be stored in "myfile".
To run multiple commands on the same command line
Sometimes, you may find it useful to run two or more commands on the same command line. To do this, separate the commands with semicolons, as shown in the following example:
Use ";"
$ whoami ; date
leslie whoami 的输出结果
1997 年 9 月 16 日 星期二,12:01:55 date 的输出结果
You can also connect commands by using the output of one command as input to another command.