UNIX Command Structure

UNIX servers and hosts are managed using files. To manage the files, you need to be aware of the UNIX command structure.

A UNIX command contains three basic parts:

Figure 6-1 displays the parts of a UNIX command.

Figure 6-1 Three Parts of a UNIX Command

Flags rh cp -i -r oldfile newfile

1 1 , 1 Command Arguments

Figure 6-1 displays the copy request command (cp). Notice that most UNIX commands are abbreviations of English words. For example, the copy command is defined by cp. The first part of any UNIX command tells the device to run a specific program or process, such as the copy function. The second part identifies any flags, which directly follow the UNIX process commands; dashes (-) identify flags. The flags in Figure 6-1 are defined as the -i flag, telling the UNIX host to confirm before it overwrites any files in this process, and the -r flag, telling the UNIX host to copy any files in subdirectories if you are copying directories.

Finally, the last part is the argument, which, in most cases, is the name of a file or directory. In Figure 6-1, for example, the old filename and the new filename must be specified.

Table 6-2 displays some common UNIX commands and their meanings.

Table 6-2 Common UNIX Commands

Table 6-2 displays some common UNIX commands and their meanings.

Table 6-2 Common UNIX Commands

Command

Description

Example

cp -i/-r oldfile newfile

Makes a copy of a file. You must specify the name of the file to be copied and the name of the new file to be created.

The -i flag tells the computer to ask before it overwrites any files in this process.

The -r flag copies any files in subdirectories if you are copying directories.

cp -i simon.doc henry.doc

rm -i/-r filename

Erases the specified file.

The -i flag asks you for confirmation before a file is deleted.

The -r flag erases directories/ subdirectories and all the files they might contain.

rm -i cisco

Table 6-2 Common UNIX Commands (Continued)

Command

Description

Example

rmdir -p directoryname

Erases directories.

The -p flag allows you to erase a directory and all its contents. Without this flag, the directory must be empty before you erase it.

rmdir -ptomll

mv -i filename1 filename2

Renames a file.

The -i flag asks for confirmation before overwriting a file if you attempt to use a filename that is already taken. Without the flag, the original file with the same name is automatically erased.

mv 2002ccie 10000ccie

mv -i filename directoryname/filename

Moves a file to another directory. The flag serves the same purpose as in the other mv command.

mv index.html index1.html

man command

Displays a description and usage instructions for a specified command. This command is similar to help in a Windows environment.

man ls

grep -i

Allows you to search for a string in files. The flag -i tells the UNIX server to ignore upper- or lowercase.

grep -i myword *.txt

Searches for the keyword myword in all files that end in .txt.

netstat -s

Displays a description and usage instructions for a specified command. The netstat -s displays statistics for network interfaces and protocols, such as TCP.

netstat -s

ifconfig -a

Displays the current interfaces that are configured. Displays the IP address and subnet mask.

ifconfig -a

NOTE All UNIX commands are in lowercase and are case-sensitive. For a free tutorial on UNIX, visit www.ee.surrey.ac.uk/Teaching/Unix/.

0 0

Post a comment