02-b common operations of unix system

51
7/25/2019 02-B Common Operations of UNIX System http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 1/51 M2000 Administrator Guide Contents  Issue 03 (2007-02-07) Huawei Technologies Proprietary i  Contents B Common Operations of the UNIX System .......................................................................... B-1  B.1 Solaris System Common Operations ................................................................ ........................................... B-2 B.1.1 Commands for Browsing and Controlling Folders............................................................................. B-2 B.1.2 Viewing the Current Working Folder – pwd................................................................................... .... B-2 B.1.3 Switching Among Folders -- cd..................................................................... ..................................... B-2 B.1.4 Creating a Folder -- mkdir........... ............................................................................ ........................... B-3 B.1.5 Deleting a Folder-- rmdir................................................................ .................................................... B-3 B.1.6 Listing Folder Content -- ls ................................................................... ............................................. B-4 B.1.7 File Maintenance Commands. ............................................................................ ................................ B-5 B.1.8 Copying a File -- cp......................................................................... ................................................... B-6 B.1.9 Moving or Renaming a File – mv....................................................................................................... B-6 B.1.10 Deleting a File – rm............................................................................. ............................................. B-7 B.1.11 Modifying Protection Mode of a File -- chmod........................................................... ..................... B-8 B.1.12 Modifying the Owner of a File -- chown.................................. ........................................................ B-9 B.1.13 Modifying the User Group of a File – chgrp ................................................................. ................. B-10 B.1.14 Commands for Viewing Text File Content .................................................................... ................. B-11 B.1.15 Sending a Character String to Screen -- echo................................................................................. B-11 B.1.16 Viewing the Content of a File -- cat ........................................................................ ....................... B-12 B.1.17 Viewing a File One Screen at a Time -- more ................................................................. ............... B-13 B.1.18 Viewing the Beginning and End of a Text File -- head & tail ........................................................ B-13 B.1.19 Clearing the Screen -- clear ..................................................................... ....................................... B-14 B.2 UNIX User Management Commands................................. ....................................................................... B-14 B.2.1 Adding a User – useradd ......................................................... ......................................................... B-15 B.2.2 Deleting a User – userdel ................................................................... .............................................. B-16 B.2.3 Modifying User Login Information – usermod ................................................................ ................ B-16 B.2.4 Changing the User Password -- passwd ....................................................................... .................... B-17 B.2.5 Adding a User Group -- groupadd .............................................................. ...................................... B-17 B.2.6 Deleting a User Group -- groupdel .................................................................. ................................. B-18 B.2.7 Modifying User Group Information -- groupmod ........................................................... ................. B-18 B.3 Utility Commands and Programs............................................................................................................... B-18 B.3.1 Searching a File -- find ........................................................... .......................................................... B-19 B.3.2 Searching a Character String -- grep .......................................................................... ...................... B-21 

Upload: dynamicsvt

Post on 28-Feb-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 1/51

M2000

Administrator Guide Contents

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary i

 

Contents

B Common Operations of the UNIX System ..........................................................................B-1 

B.1 Solaris System Common Operations ................................................................ ........................................... B-2 

B.1.1 Commands for Browsing and Controlling Folders............................................................................. B-2 

B.1.2 Viewing the Current Working Folder – pwd................................................................................... .... B-2 

B.1.3 Switching Among Folders -- cd..................................................................... ..................................... B-2 

B.1.4 Creating a Folder -- mkdir........... ............................................................................ ........................... B-3 

B.1.5 Deleting a Folder-- rmdir................................................................ .................................................... B-3 

B.1.6 Listing Folder Content -- ls ................................................................... ............................................. B-4 

B.1.7 File Maintenance Commands............................................................................. ................................ B-5 

B.1.8 Copying a File -- cp......................................................................... ................................................... B-6 

B.1.9 Moving or Renaming a File – mv....................................................................................................... B-6 

B.1.10 Deleting a File – rm............................................................................. ............................................. B-7 

B.1.11 Modifying Protection Mode of a File -- chmod........................................................... ..................... B-8 

B.1.12 Modifying the Owner of a File -- chown.................................. ........................................................ B-9 

B.1.13 Modifying the User Group of a File – chgrp ................................................................. ................. B-10 

B.1.14 Commands for Viewing Text File Content.................................................................... ................. B-11 

B.1.15 Sending a Character String to Screen -- echo.......... ..................................................................... .. B-11 

B.1.16 Viewing the Content of a File -- cat ........................................................................ ....................... B-12 

B.1.17 Viewing a File One Screen at a Time -- more ................................................................. ............... B-13 

B.1.18 Viewing the Beginning and End of a Text File -- head & tail ........................................................ B-13 

B.1.19 Clearing the Screen -- clear ..................................................................... ....................................... B-14 

B.2 UNIX User Management Commands................................. ....................................................................... B-14 

B.2.1 Adding a User – useradd ......................................................... ......................................................... B-15 B.2.2 Deleting a User – userdel ................................................................... .............................................. B-16 

B.2.3 Modifying User Login Information – usermod................................................................ ................ B-16 

B.2.4 Changing the User Password -- passwd ....................................................................... .................... B-17 

B.2.5 Adding a User Group -- groupadd.............................................................. ...................................... B-17 

B.2.6 Deleting a User Group -- groupdel.................................................................. ................................. B-18 

B.2.7 Modifying User Group Information -- groupmod ........................................................... ................. B-18 

B.3 Utility Commands and Programs............................................................................................................... B-18 

B.3.1 Searching a File -- find........................................................... .......................................................... B-19 

B.3.2 Searching a Character String -- grep .......................................................................... ...................... B-21 

Page 2: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 2/51

Contents

M2000

Administrator Guide

 

ii Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

B.3.3 Backing Up and Restoring a File – tar .............................................................. ............................... B-22 

B.3.4 Compressing/Decompressing a File -- compress/uncompress ......................................................... B-23 

B.3.5 Sending a File Package to the System -- pkgadd............................................................ .................. B-24 

B.3.6 Removing a Package from the System -- pkgrm.................................... .......................................... B-24 

B.3.7 Calculation Command -- bc ............................................................................ ................................. B-25 

B.3.8 Basic Features of the vi Editor ..................................................................... .................................... B-25 

B.4 System Resource Commands .................................................................. .................................................. B-27 

B.4.1 Viewing Online Help About Commands -- man.............................................................................. . B-27 

B.4.2 Viewing the Free Disk Space -- df.................................................................................................... B-28 

B.4.3 Viewing the Disk Space Used by Each File System -- du ................................................................ B-29 

B.4.4 Viewing the Status of the Active Process -- ps ....................................................... .......................... B-31 

B.4.5 Terminating a Process -- kill................................................................................................... .......... B-32 

B.4.6 Viewing Information About Current Login Users -- who................................................................. B-33 

B.4.7 Viewing the Command Location -- whereis.................................................................... ................. B-34 

B.4.8 Viewing the Path of a Specific Command -- which.......................................................................... B-34 

B.4.9 Viewing or Setting the Host Name -- hostname .......................................................................... ..... B-35 

B.4.10 Viewing Information About the Operating System -- uname......................................................... B-35 

B.4.11 Viewing the Host IP Address -- ifconfig................ ......................................................................... B-36 

B.4.12 Recording Screen I/O Activities – script .............................................................. .......................... B-37 

B.4.13 Viewing the Current Date and Time -- date................... ................................................................. B-38 

B.5 Network Communication Commands ............................................................... ........................................ B-39 

B.5.1 TCP/IP Protocols .................................................................... .......................................................... B-39 

B.5.2 Network Communication Commands ................................................................. ............................. B-39 B.5.3 Testing the Physical Network Connection -- ping.......... .................................................................. B-40 

B.5.4 Logging In to a Remote Computer Through Network Connection—telnet ..................................... B-40 

B.5.5 Transferring Files Through Network Connection -- ftp.................................................................... B-41 

B.5.6 Viewing Information About Online Users -- finger......................... ................................................. B-43 

B.5.7 Viewing Network Status -- netstat.................................................................... ................................ B-44 

B.5.8 Modifying and Maintaining the Routing Table -- route ................................................................... B-46 

Page 3: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 3/51

M2000

Administrator Guide Tables

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary iii

 

Tables

Table B-1 Commands for browsing and controlling folders.............................................................................. B-2 

Table B-2 File maintenance commands.................. ................................................................ ........................... B-5 

Table B-3 System commands for viewing and browsing the content of text files..................................... ...... B-11 

Table B-4 UNIX user management commands ............................................................... ................................ B-15 Table B-5 Utility commands and programs ............................................................... ...................................... B-18 

Table B-6 Conditions for file search.............. ............................................................................ ...................... B-19 

Table B-7 Logical operators of conditions....................................................................................................... B-20 

Table B-8 Operations in the text input mode ....................................................................... ............................ B-25 

Table B-9 Operations related to moving the cursor in the text input mode ..................................................... B-26 

Table B-10 Operation for exiting the text input mode and switching to the command mode.......................... B-26 

Table B-11 Operations related to deleting characters in the command mode............................ ...................... B-26 

Table B-12 Commands for exiting the vi editor ........................................................................ ...................... B-26 

Table B-13 System resource report and management commands provided by the UNIX system................... B-27 

Table B-14 Format of the command output .......................................................................... ........................... B-38 

Table B-15 Network communication commands.................................................................................. ........... B-39 

Table B-16 Common ftp commands .............................................................. ................................................. B-42 

Table B-17 Examples of finger commands............................................................. ........................................ B-44 

Page 4: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 4/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-1

 

B Common Operations of the UNIX System

About This Chapter

The following table lists the contents of this chapter.

Title Description

B.1 Solaris System CommonOperations 

Describes the routine operations under the Solarisoperating system.

B.2 UNIX User ManagementCommands 

Describes the commands used for managing UNIX users.

B.3 Utility Commands andPrograms  Describes UNIX commands and applications.

B.4 System ResourceCommands 

Describes the system resource report and managementcommands provided by the UNIX operating system.

B.5 Network CommunicationCommands 

Describes the commands used for network communicationunder the UNIX operating system.

Page 5: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 5/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-2 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

B.1 Solaris System Common Operations

B.1.1 Commands for Browsing and Controlling FoldersThe root directory in the UNIX system starts with /. System and user folders are organizedunder the root directory. When a user logs in, the user enters the corresponding Home folder.The user can create subfolders under the home folder. Table B-1 shows the commandscommonly used for browsing and controlling folders.

Table B-1 Commands for browsing and controlling folders

Command Description

pwd  To view the current working folder

cd [ Folder ] To switch among folders

mkdir [ Folder ] To create a folder

rmdir [ Folder ] To delete a folder

ls [Option] [ Folder or File] To list the folder content or file information

B.1.2 Viewing the Current Working Folder – pwd

Unlike DOS, the UNIX system does not always display the folder name. You must execute thepwd command from time to time to view the current working folder.

Description

View the current working folder.

Example

To view the current working folder, execute the following command:

$ pwd

/export/home/sybase

B.1.3 Switching Among Folders -- cd

Description

Switch to another folder from the current one.

Page 6: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 6/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-3

 

This command applies to both absolute and relative paths.

Example

  To return to the home folder, execute the following command:

$ cd

  To switch to the system root directory, execute the following command:

$ cd /

  To switch back one folder, execute the following command:

$ cd ..

  To switch back two folders, execute the following command:

$ cd ../..

  To switch to the /export/home/sybase folder by the absolute path, execute the following

command:

$ cd /export/home/Sybase 

The cd command without any parameter, as shown below, means to switch back to the home folder of theuser.

$ cd

B.1.4 Creating a Folder -- mkdir

Description

Create a subfolder.

When the path for the created folder is determined, both absolute and relative paths can be used.

Example

To create a subfolder data in the /home1/omc, execute the following command:

$ mkdir/home1/omc/data

If the current folder is /home1/omc, the above command can be simplified to:

$ mkdir data

B.1.5 Deleting a Folder-- rmdirDescription

Delete an empty folder.

If the folder to be deleted is not empty, you must delete the files in the folder before you executethe rmdir command. To delete the current working folder, you must switch to the upper levelfolder.

Example

  To delete the data subfolder in the /home1/omc folder, execute the following command:

$ rmdir/home1/omc/data 

Page 7: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 7/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-4 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

  If the current folder is /home1/omc, the above command can be simplified to:

$ rmdir data 

B.1.6 Listing Folder Content -- ls

Description

List the files and subfolders in a folder.

Execute the ls command without any parameter to list the content of the current folder. Executethe ls command with parameters to list information about the size, type, privileges of the file,and the date when the file was created and modified.

Command Format

ls [Option] [ Directory or File] 

Option Description

Many options and combination of options can be used for the ls command. Remember, however,to put the prefix - before the options. Some common options are described as follows:

  -a: to list all files including the hidden files, that is, the files starting with a dot; for

example, the .login file

  -F : to specify the type of the file by suffix signs

The meaning of the suffixes are:

−  /: for folder files

−  =: for pipe files

−  @: for sign-linking files

−  *: for executable files

  -l : to list the detailed information about a file, such as the file type, privileges, number oflinks, owner, file group, file size, file name, and the date of the last modificationIf the file is a sign-linking file, the -> sign is added at the end of the file name for pointingto the linked file.

Example

To view the long-form content of the files in the current folder, execute the followingcommand:

$ ls -l |more

total 11094632

drwxr-xr-x 2 sybase staff 1024 Sep 5 2001 bin

drwxr-xr-x 14 sybase staff 512 Sep 5 2001 charsets

drwxr-xr-x 3 sybase staff 512 Sep 5 2001 collate

drwxr-xr-x 2 sybase staff 512 Sep 5 2001 config

-rw-r--r-- 1 sybase staff 2048000000 Mar 6 09:50 data_dev.dat

drwxr-xr-x 2 sybase staff 512 Sep 5 2001 devlib

drwxr-xr-x 7 sybase staff 512 Sep 5 2001 diag

drwxr-xr-x 2 sybase staff 512 Sep 5 2001 hs_data

drwxr-xr-x 2 sybase staff 512 Sep 5 2001 include

drwxr-xr-x 7 sybase staff 512 Sep 5 2001 init

Page 8: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 8/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-5

 

drwxr-xr-x 3 sybase staff 512 Sep 5 2001 install

-rw-r--r-- 1 sybase staff 268 Sep 5 2001 interf.old

-rw-r--r-- 1 sybase staff 402 Oct 29 15:25 interfaces

drwxr-xr-x 2 sybase staff 1024 Sep 5 2001 lib

drwxr-xr-x 2 sybase staff 512 Sep 5 2001 license

drwxr-xr-x 6 sybase staff 512 Sep 5 2001 locales

-rw-r--r-- 1 sybase staff 2048000000 Mar 6 10:51 log_dev.dat

-rw-r--r-- 1 sybase staff 2048000000 Mar 6 10:36 log_dev1.dat

drwxr-xr-x 5 sybase staff 512 Sep 5 2001 pad

-rw-r--r-- 1 sybase staff 5242880 Feb 19 10:10 phase2.dat

drwxr-xr-x 8 sybase staff 512 Sep 5 2001 sample

--More--

After you execute the ls –l command, the displayed file content may take up several screens. Toview the files on one screen at a time, execute either of the following two commands:

$ ls -la | more

$ ls -la>ccc

Save the command output to the ccc file, and then execute the more ccc command to view theoutput on one screen at a time. 

After you execute the ls -l command, seven columns of information are displayed, which aredescribed as follows:

  The first column includes 10 characters. The first character indicates the file type; forexample, the character - refers to a common file and the character d refers to a folder. Thefollowing nine characters are three triplets indicating the access privileges of the fileowner: The first triplet pertains to the owner, the middle triplet pertains to members of theuser group, and the rightmost pertains to everyone else in the system; for example, thecharacters r, w, and x indicate that the user has the privileges to read, write, and execute afile, while the character - indicates that the user does not have any relevant privileges forthe file.

  The second column indicates the number of hard links of the file.

  The third and fourth columns display information such as the owner of the file, and the

user group to which the file belongs.

  The fifth column shows the size of the file in byte.

  The sixth column shows the time and date when the file is modified the last time.

  The seventh column shows the file name.

B.1.7 File Maintenance Commands

Table B-2 lists the commands for maintaining a file; for example, for creating, copying,deleting, and modifying a file.

Table B-2 File maintenance commands

Command Description

cp [Option] [ file1] [f ile2] To copy a file

mv [ file1] [f ile2] To move or rename a file

rm [Option] [ file] To delete a file

Page 9: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 9/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-6 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

Command Description

chmod [Option] [ file] To modify privileges of a file

chown [Option] [owner file] To modify the owner of a file

chgrp [Option] [group file] To modify the group of a file

B.1.8 Copying a File -- cp

Description

Copy the content of a file to another file.

Command Formatcp [option] [ source file] [object file]

Option Description

-r : to recursively copy a folder.

In other words, when copying a folder, copy the files and subfolders included in the folder, andfiles and subfolders in the subfolders, so on and so forth until the last level of the folder.

Example

To copy the old_filename file in the current folder to a new file named new_filename, executethe following command:

$ cp old_filename new_filename

B.1.9 Moving or Renaming a File – mv

The difference between the mv command and the cp command is as follows:

After you execute the mv command, only the object file exists. After you execute the cp command, a copy of the file is created, that is, both the source file and the copy file exist.

Description

Move or rename a file.

  When the source file and the object file are in the same folder, execute the mv command to

rename the file.

  When the source file and the object file are not in the same folder, execute the mv 

command to move the file.

Page 10: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 10/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-7

 

Command Format

mv [ source file] [object file]

Example

  To rename the old_filename file in the current folder to new_filename, execute thefollowing command:

$ mv old_filename new_filename 

  To move the old_filename file in the root directory to the /home1/omc folder, execute thefollowing command:

$ mv /old_filename /home1/omc 

B.1.10 Deleting a File – rm

In the UNIX system, a file, once deleted, cannot be restored. Therefore use the -i option to avoiddeletion by mistake.

To delete a folder, execute either of the following commands: rmdir or rm  –r.The difference between the two commands is:

  rmdir deletes only empty folders.

  rm –r  deletes any folders.

Description

Delete a file.

Command Format

rm [Option] [ file]

Option Description

  -i: to refer to interactive operations

Your confirmation is required before a command is executed.

  -r : to recursively delete a folder

In other words, when deleting a folder, delete the files and subfolders included in the folder,and files and subfolders in the subfolders, so on and so forth until the last level of thefolder.

Example

To delete the old_filename file in the current folder, execute the following command:

$ rm -i old_filename

Page 11: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 11/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-8 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

B.1.11 Modifying Protection Mode of a File -- chmod

Description

Modify the protection mode of a folder.

Command Format

chmod [Option] [ file] 

Depending on the different expressions of the option, execute this command in the followingtwo modes:

  Sign mode

chmod [object] [operational character] [privilege] [file]

  Digit mode

chmod [lmn] [ file] 

Option Description

  Sign mode

Object: can be one of the following options

u: owner of a file

 g : group members

o: other users in the system

a: all users

Operational character : can be one of the following options. +: to add privileges

-:  to cancel privileges

=: to set privileges

  Digit mode

The option lmn  has three numbers, representing privileges of the file owner, the groupmembers, and other users in the system respectively. The value of each number is the sumof the numbers indicating "r" (to read) , "w" (to write), "x"  (to execute) and "-"  (no privilege) , among which:

r  = 4, w = 2,  x = 1, - = 0

For example,-rwxr-xr-- 1 rms sbsrms 46098432 May 12 16:02 sdh*

The privilege of the sdh file is expressed by rwxr-xr--, which is composed of three triplets:the first pertains to the owner of the file, the middle triplet pertains to the members of theuser’s group, and the rightmost pertains pertains to the other users in the system. The valuethat indicates the privilege is 754 (7=4+2+1, 5=4+0+1, 4=4+0+0).

Parameter Description

 File: the name of the file of which the privilege is to be modified

Page 12: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 12/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-9

 

Example

  Sign mode

To set priviliges of file1, execute the following command:

$ chmod u=rwx,go=rx file1 Set the privileges of file1 as follows: Set the read, write, and execution privileges for itsowner; set the read and execution privileges for the other users in the group; set the readand execution privileges for the other users in the system.

To set the read and write privileges of file2 for all users, execute the following command:

$ chmod a=rw file2

  Digit mode

To set privileges of file1, execute the following command:

$ chmod 755 file1

Set the privileges of file1 as follows: Set the read, write, and execution privileges for its

owner; set the read and execution privileges for the other users in the group; set the readand execution privileges for the other users in the system.

To set the read and write privileges of file2 to all users, execute the following command:

$ chmod 666 file2

  In the sign mode, to set the privileges for the group members and the other users in the system, thefolder in which the file is stored must be executable. To set the privileges, execute either the chmod u=rw,+ x . or chmod u=rwx,go=x . command in the folder where the privileges are to be modified.

  The symbol . in the command stands for the current folder.

  In the digit mode, r=4, w=2, x=1, -=0 is based on the binary system. To the three digits representingthe privileges to read, write, and execute in the same group, specify the value of the digit to 1 when therelevant privilege is available to that digit, and specify the value 0 when the relevant privilege is notavailable. Take the sdh file as an example. The privilege rwxr-xr-- is 111101100 according to the binary system, in which each triplet represents the privilege for the three types of users respectively.The weighted sums of the binary values in each triplet equal to the decimal value 7, 5, and 4 respectively.

B.1.12 Modifying the Owner of a File -- chown

Description

Modify the owner of a file.

In most UNIX systems, this command can only be executed by the super user. In other words,

the users other than the super user cannot modify the owner of files.

Command Format

chown [Option] [owner file]

Option Description

  -f : to execute the command forcibly without errors displayed

  -R: recursive folder

Page 13: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 13/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-10 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

Parameter Description

  Owner : the modified owner

   File: the file whose owner is to be modified 

Example

  To modify the owner of a file to new_owner, execute the following command:

# chown new_owner file 

  To modify the owner of all files in the /export/home/sybase folder and the subfolders toM2000, execute the following command:

# chown -R M2000 /export/home/sybase

B.1.13 Modifying the User Group of a File – chgrp

  The new user group to which a file is moved to must have already been created. Execute the

groups command to list the groups to which you belong. For details on how to create a usergroup, see section 1.2 “UNIX User Management Commands."

  After the owner or group of a folder is changed, the folder does not belong to that user or

user group any more. The attributes of the subfolders and files in the folder, however, remainunchanged.

  Execute the chown command to modify the owner and the user group of a file at the same

time:# chown omc:staff file1For example, execute the command to modify the owner of file1 to omc and the group tostaff .

Description

Move all files from the user group to which you belong, to another user group.

In other words, you belong to at least two user groups at the same time.

Commond format

chgrp [Option] [ group file] 

Option Description

  -f : to execute the command forcibly without errors displayed

  -R: recursive folder

Parameter Description  Group : the modified user group

   File: the file the user group of which is to be modified

Page 14: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 14/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-11

 

Example

To modify the user group file to new_ group, execute the following command:

$ chgrp new_group file

B.1.14 Commands for Viewing Text File Content

Table B-3 describes the system commands used for viewing and browsing the content of textfiles.

Table B-3 System commands for viewing and browsing the content of text files

Command Description

echo [character string ] [option] To send a character string to the screen

cat [option] [ file] To view the content of a file

more [option] [ file] To view a file on one screen at a time

head [value] [ file] To view the beginning of a file

tail [value] [ file] To view the end of a file

clear  To clear the screen

B.1.15 Sending a Character String to Screen -- echo

Description

Send a character string to a standard output device such as the monitor screen.

Command Format

echo [character string ] [option]

Option Description

  \c: The RETURN character is not displayed.

 

\0n: n is an 8-digit ASCII character code.  \t : The TAB character is displayed.

  \n: The RETURN character is displayed.

  \v: The vertical TAB character is displayed.

Example

To send a character string to the screen, execute the following command:

$ echo $HOME

/export/home/sybase

/export/home/sybase displayed on the screen is the meaning of the character string $HOME.

Page 15: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 15/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-12 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

To avoid displaying RETURN, execute the following command:

$ echo Hello Class "\c"

Hello Class $

Or:

$ echo "Hello Class \c"

Hello Class $

The options \c, \0n, \t, \n, and \v are displayed in the character string enclosed in quotation marks. Thequotation marks can quote either an option or multiple options.

B.1.16 Viewing the Content of a File -- cat

DescriptionView the content of a text file.

Command Format

cat [option] [ file]

Option Description

  -n: number of each line of the displayed text

  -v: to view nonprinting characters other than TAB and RETURN

Example

View the content of the M2000_Table.txt file.

Execute the following command:

$ cat M2000_Table.txt

Name Owner

Object_type

------------------------------ ------------------------------

----------------------

tbl128Addr m2000

user table

tbl128IP m2000

user table

tbl128Name m2000

user table

tblAdapterIP m2000

user table

tblAdjCell m2000

user table

..............................

To view several files at the same time, execute the following cat command:

Page 16: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 16/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-13

 

$ cat [file1] [file2] [file3]

B.1.17 Viewing a File One Screen at a Time -- more

DescriptionView a file one screen at a time. You can also execute this command to browse the previousscreens and to search for character strings.

Command Format

more [option] [ file]

Option Description

  -c: to clear the screen before the content is displayed

 

-w: not to exit at the end of the input, but to wait for the prompt

  -lines: the number of lines displayed on each screen

  +/mode: to search files in the given mode

Example

View the content of the M2000_Table.txt file on one screen at a time.

Execute the following command:

$ more M2000_table.txt

Name Owner

Object_type

------------------------------ ------------------------------

tbl128Addr m2000

user table

tblAucFunction m2000

user table

--More--(15%)

  To view a file on one screen at a time, use the following keys to perform relevant operations:Space key: to view the next screenReturn key: to view the next lineq: to exit

h: to view the online help b: to switch back to the previous screen/word: to search for the character string word backward

  Due to the concatenated execution of multiple UNIX commands, |more can be added at the end ofother commands to view the relevant results on several screens. For example, after you execute the ls

-la |more  command, the results of ls –la  are displayed on several screens.

B.1.18 Viewing the Beginning and End of a Text File -- head & tail

Description

  Execute the head command to view the first few lines of a text file.

By default, the first 10 lines are displayed.

Page 17: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 17/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-14 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

  Execute the tail command to view the last few lines of a text.

By default, the last 10 lines are displayed.

Command Format

  head [value] [ file]

  tail [value] [ file]

Example

  View the first three lines of the M2000_Table.txt file.

Execute the following command:

$ head -3 M2000_Table.txt

 Name Owner

Object_type

------------------------------ ------------------------------

  View the last three lines of the M2000_Table.txt file.

Execute the following command:

$ tail -3 M2000_Table.txt

user table

tblVlrFunction m2000

user table

A special function of the tail command is to view the latest changes of a log file, because all the latestchanges are added at the end of the log file. The command format is as follows:

$ tail -f commdrv.log

The option -f  refers to the function of monitoring the file.

B.1.19 Clearing the Screen -- clear

Description

Clear the content on the screen.

Example

Clear the screen.

Execute the following command:

$ clear

B.2 UNIX User Management Commands

Table B-4 shows the user management commands that are commonly used in the UNIX system.Only the root user and authorized users can add, modify, or delete users and user groups.

Page 18: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 18/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-15

 

Table B-4 UNIX user management commands

Command Description

useradd [option] [user name]  To add a user

userdel [user name]  To delete a user

usermod [option] [user name]  To modify the user login information

passwd [user name]  To modify the user password

groupadd [user group name]  To add a user group

groupdel [user group name]  To delete a user group

groupmod [option] [user group name]  To modify user group information

B.2.1 Adding a User – useradd

After a user is added, set the password for the added user immediately. For details, see partB.2.4 "Changing the User Password -- passwd." After the password is set, the user can log in asa new user.

Description

Add a user in the UNIX system.

Command Format

useradd [option] [user name]

Option Description

  -c comment : the comment

 

-d folder : the home folder

  -m: to create a home folder automatically if the home folder does not exist

  -g group: the user group that you belong to

  -s shell : the shell you use

Example

Add a user named omc1 in the UNIX system. The user omc1 belongs to the staff  user group,the home folder is /home1/omc (created automatically), the comment is Test User, and B shellis used.

Execute the following command:

Page 19: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 19/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-16 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

# useradd -c "Test User" -d /home1/omc -m -g staff -s/usr/bin/sh omc1

B.2.2 Deleting a User – userdel

When a user has logged in, do not execute the userdel command to delete the user. Otherwise,the error message “UX: userdel: ERROR: omc1 is in use. Cannot remove it.” is displayed.

Description

Delete a user.

Some UNIX systems do not allow deleting users completely. Execute the userdel command torevoke the privileges granted to the user.

Command Format

userdel [user name] 

Example

Delete omc1 created in section B.2.1 “Adding a User – useradd”.

Execute the following command:

# userdel omc1

B.2.3 Modifying User Login Information – usermod

Do not execute the usermod command to modify a user when the user has logged in; otherwise,the error message “UX: usermod: ERROR: omc1 is in use. Cannot change it.” is displayed.

Description

Modify the user login information.

Command Format

usermod [option] [user name]

Option Description

  -c comment : the modified comment

  -d folder : the modified home folder

Page 20: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 20/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-17

 

  -g group: the modified user group

  -m: to create a home folder automatically if the home folder does not exist

  -l new_logname: the modified user name

  -s shell : the shell you use

Example

Modify the login information of omc1 as follows: Modify the user name to test, user group tonew_group, home folder to /home1, and comment to Tester.

Execute the following command:

# usermod -c "Tester" -d /home1 -g new_group -l test omc1

B.2.4 Changing the User Password -- passwd

Description

Set the password for an added user or to change the user password.

Command Format

passwd [user name] 

Example

Change the password of omc1.

Execute the following command:

# passwd omc1

B.2.5 Adding a User Group -- groupadd

Description

Add a user group in the UNIX system.

Command Format

groupadd [user group name] 

Example

Add the user group staff1 in the UNIX system.

Execute the following command:

# groupadd staff1

Page 21: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 21/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-18 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

B.2.6 Deleting a User Group -- groupdel

Description

Delete a user group.

Command Format

groupdel [user group name] 

Example

Delete the user group staff1.

Execute the following command:

# groupdel staff1

B.2.7 Modifying User Group Information -- groupmod

Description

Modify the information about a user group.

Command Format

groupmod  [option] [user group name]

Parameter Description

-n name: the name of the modified user group

Example

Modify the name of the user group staff1 to staff2.

Execute the following command:

# groupmod -n staff2 staff1

B.3 Utility Commands and Programs

Table B-5 shows the utility commands offered by the UNIX system.

Table B-5 Utility commands and programs

Command Description

find [ folder ] [condition] To search for files

grep [character ] [ string   file] To search for special character strings

Page 22: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 22/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-19

 

Command Description

tar [function optios[modify option]] [ file] Utility program, to back up and restore files

compress/uncompress [ file] 

pack/unpack [ file]

To compress/decompress files

pkgadd [option] [ file] [ package name]  To send a file package to the system

pkgrm [option] [ file] [ package name]  To remove a file package from the system

bc  Calculator

B.3.1 Searching a File -- find

Description

Search for a file that meets the preset conditions in the specified folders and subfolders.

With this command, you can find the file even when you forget the correct path of the file.

Command Format

find [ folder ] [condition] 

Parameter Description

   Folder : the folder where the file search startsYou can enter multiple folder names. Separate the folder names with space.

  Condition: conditions for file search, such as the file name, owner, and time of the last

modification

Table B-6 describes the conditions for file search.

Table B-6 Conditions for file search

Condition Description

-name name  The name of the file or folder to be searched. Wildcards, such as -name

‘*.c.’ , can be used.

-print   To print the path that meets the conditions.

-size n  To search for the files that use n blocks.

-type x  To search for files by file type. The file type x includes:

  d  --- folder

  f  --- file

  b --- block

  c ---character

  p --- pipe

Page 23: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 23/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-20 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

Condition Description

-user  user   To search for all files of user. The value of user can be a user name orUID.

-group  group  To search for all files of the user group group. The value of group can be a user group name or GID.

-links n  To search for all files with the number of links as n.

-atim n  To search for the files accessed n days before.

-mtime n  To search for the files modified n days before.

-exec command {};  Use the found file as the object of the command to be executed. Put the parameters to be used in the command execution between {}.

Table B-7 describes the logical operators of conditions.

Table B-7 Logical operators of conditions

LogicalOperator

Meaning Example Description

! non ! -name “*.c”  All files except those with the extendsionname as .c 

-o  or -size +10 -o-links 3 

All the files with more than 10 blocks orwith 3 links

and -size +10 -links3 

All the files with more than 10 blocks andwith 3 links

In Table B-7, +10 stands for more than 10 blocks and -10 for less than 10 blocks.

Example

  Search for files in the /tmp folder with the file name starting with c, and then print the

 paths.

Execute the following command:

$ find /tmp -name "c*" -print

/tmp/ctisql_0WBJgt

/tmp/ctisql_0dznJ_

/tmp/ctisql_0CpW34

/tmp/ctisql_0FO4vs

  Search for files named test in the current folder, and then print the paths.

Execute the following command:

$ find . -name test -print

./HWReport/reloc/resin1.2.0/conf/test

./HWReport/reloc/resin1.2.0/doc/examples/login/WEB-INF/classes/test

Page 24: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 24/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-21

 

./HWReport/reloc/resin1.2.0/doc/examples/tags/WEB-INF/classes/test

  It may take several minutes for the find command to search for the files that meet the set conditions.To save time, you can execute the find command in the background. In other words, the output for the

command is exported to a file for later query. End the command line with &, so that the systemexecutes the command in the background. For example,$ find  / -name "abc*" -print > abc.file &After the searching is complete, execute the following command to view the result of the search:$ cat abc.file 

  Different users may have different privileges for the same file; therefore, ordinary users may find onlysome files of the system. To list all the files that meet the set conditions, log in as a super user andsearch from the root directory.

B.3.2 Searching a Character String -- grep

Description

Search for a character string in a text file, and print all the lines that include the character string.

Command Format

grep [character ] [ string   file] 

Example

Search for the character string operation in the ifconfig.txt file.

Execute the following command:

$ grep operation ifconfig.txtused to control operation of dhcpagent(1M), the DHCP client

operation, be used to modify the address or characteristics

dhcpagent wakes up to conduct another DHCP operation on the

given, and the operation is one that

requested operation will continue. 

Search for the character string The following options are supported in the ifconfig.txt file.

The character string The following options are supported includes spaces. Remember toenclose the character string within quotation marks in the command line.

$ grep "The following options are supported" ifconfig.txt

The following options are supported:

Page 25: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 25/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-22 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

B.3.3 Backing Up and Restoring a File – tar

  Do not enter –  on the left of function and modification options in the command tar.

  Execute the following tar command to pack several files into a package:

$ tar cvf filebak.tar file1 file2 file3

  Execute the tar cvf filebak.tar file1 file2 file3 command to pack file1, file2, and file3 into a

 package named filebak.tar.

  The names of the disk and tape devices used in file backup and restoration in the tar 

command may vary according to the UNIX system. Check carefully before executing thecommand.

Description

Combine several files into one archive and save it to a tape or disk. When one of the files isrequired, obtain the file directly from the archive.

Command Format

tar [ function options [modification options]] [ file] 

Option Description

 

 function options: to set the actions, such as read and write, of the tar command 

r : to add the specified file to archive.

X: to read the file in the archive. If the file name is a folder, this option reads the subfoldersincluded in the folder.

c: to create an archive.

 g : to create the file at the beginning of the archive, instead of adding the file in the last file.

  modification options: to modify the actions of the tar command

v: to activate the display mode. The names of all the processed files are displayed. Thisoption is often used. 

w: to activate the confirmation mode. Your confirmation is required before each file is

 processed.

 f : to indicate that the archive is a file. If this parameter is skipped, the preset tape or disk isused as the object. This option is often used. 

Example

  Back up files.

To back up all the files and subfolders in the data folder in the current folder to the defaultdevice, and to view the file information during the backup, execute the followingcommand:

$ tar cv data

Page 26: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 26/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-23

 

In current folder, back up all the files and subfolders in the data folder to the databak.tar file, and to view the file information during the backup, execute the following command:$ tar cvf databak.tar data 

  Restore files.

To restore the files in the default device to a hard disk, and to view the file informationduring the restoration, execute the following command:$ tar xv 

To restore the databak.tar file to the current /data folder, and to view the file informationduring the restoration, execute the following command:$ tar xvf databak.tar 

B.3.4 Compressing/Decompressing a File -- compress/uncompress

  Do not execute the pack  command to compress files of small sizes. To compress such files,use the pack  command with the option -f  (for forced compression), as shown below:$ pack  -f filename

  The difference between the tar command and the file compressing commands is as follows:

The tar command packs or combines files, that is, putting a large number of small articlesinto a container and labeling it for preservation or transport. The total weight of the items,however, does not change. The tar command packs many folders or files into a package.Execute the compress or  pack  command to compress the combined files *.tar, if necessary.

Description

  Execute the compress command to compress files, to reduce the memory space. The nameof the compressed files ends with .z. The command for decompressing such files isuncompress. 

  Execute the pack  command to compress files. The name of the compressed files ends

with .z. The space achieved through compression depends on the file type. The commandfor extracting files is unpack.

Command Format

compress [ file] 

uncompress compressed file ending with “.z”.

pack  [ file] 

unpack  compressed file ending with “.z”.

Example

  Compress a file.

Execute the following command:

# compress file 

If the compressed file ends with .z, execute the following command to decompress the file:# uncompress file.z 

Page 27: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 27/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-24 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

  Pack a file.

Execute the following command:

# pack file 

pack: file: 56.8% Compression

If the packed file is named .z, execute the following command to unpack the file:# unpack file.z

unpack: file: unpacked

B.3.5 Sending a File Package to the System -- pkgadd

Description

Send a file package to the system for execution.

Command Format

pkgadd [option] [ file] [ package name] 

Option Description

-d device: to install or copy a package from the device.

The device can be an absolute path, the identifier of a tape or a disk such as /var/tmp or/floppy/floppy_name, or a device name such as /floppy/floppy0.

Example

# pkgadd -d. HWM2000

The dot . indicates that the folder is the current folder.

B.3.6 Removing a Package from the System -- pkgrm

Description

Remove a package from the system.

Command Format

pkgrm [option] [ file] [ package name] 

Example

# pkgrm HWM2000

The commands pkgadd and pkgrm are frequently used during the installation and upgrade of iManagerM2000. When upgrading the M2000 system, unload HWM2000 first through the pkgrm HWM2000 command after the process stops. After unloading the upgrading files, pack and then send them to thesystem through the pkgadd -d. HWM2000 command. 

Page 28: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 28/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-25

 

B.3.7 Calculation Command -- bc

Description

Perform simple calculation.

Example

# bc 

4*5

20

To get the result, execute the bc command, and then press Enter.

Enter the formula 4*5, and then press Enter. The result is displayed on the screen. Press Ctrl+D to exit thebc program.

B.3.8 Basic Features of the vi Editor

As a text editing tool, the vi editor is used to creat and modify text files.

The vi editor works in two modes:

  Text input mode: to enter the text

  Command mode: to enter the control command

Starting the vi Editor

To start the vi editor, enter the following command:

vi file name

Relevant Operations

Table B-8 lists the operations in the text input mode.

Table B-8 Operations in the text input mode

To … Press …

Insert text immediately after the cursor (append) a

Insert text at the end of the line where the cursor is A

Insert text immediately before the cursor (insert) i

Insert text before the first nonblank character in the line where the cursor is I

Start a new line below the current one and insert text (open) o

Start a new line above the current one and insert text O

Table B-9 lists the operations related to moving the cursor in the text input mode.

Page 29: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 29/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-26 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

Table B-9 Operations related to moving the cursor in the text input mode

To … Press …

Move the cursor one character left h

Move the cursor one character down j

Move the cursor one character up k

Move the cursor one character right l

Move the cursor to a specified line Line No. G

(For example, 1G means the cursor is movedto the first line.)

Move the cursor to the end of the text G

Table B-10 lists the operation for exiting the text input mode and switching to the commandmode.

Table B-10 Operation for exiting the text input mode and switching to the command mode

To … Press …

Exit the text input mode and switch to the command mode ESC 

Table B-11 lists the operations related to deleting characters in the command mode.

Table B-11 Operations related to deleting characters in the command mode

To … Press …

Delete the current character x

Delete the entire line dd

Exiting the vi Editor

Table B-12 describes the commands for exiting the vi editor.

Table B-12 Commands for exiting the vi editor

Command Description

:wq To save the file and exit the vi editor

:q To exit the vi editor without saving the file

:q! To exit the vi editor and discard all the changes

:w To save the file but not to exit the vi editor

Page 30: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 30/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-27

 

All the commands listed in Table B-12 must be executed in the command mode. Therefore press ESC before executing the commands.

B.4 System Resource CommandsTable B-13 describes the system resource report and management commands provided by theUNIX system.

Table B-13 System resource report and management commands provided by the UNIX system

Command Description 

man [option] [command ] To obtain the online hlep about a command

df  [option] [ file system] To view the free disk space

du [option] [ folder or file] To view the disk space used by each file system

ps [option] To view the status of an active process

kill [option] [ process No.] To terminate a process

who [option]  To list the information about the users that log in currently

whereis [option] [command ] To view the location of a command

which [command ]  To view the path of a specific command

hostname [host name]  To view or set the host name

uname [option]  To view the information about the operating system

ifconfig [option]  To view the IP address of the host

script [option] [ file]  To record screen I/O activity

date [option] [+format ] To view current date and time

B.4.1 Viewing Online Help About Commands -- man

DescriptionView the online help about a command.

Command Format

man [option] [command ] 

Example

View the online help about the pwd command.

Execute the following command:

Page 31: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 31/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-28 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

$ man pwd 

Reformatting page. Wait... done

User Commands pwd(1)

NAME

pwd - return working directory name

SYNOPSIS

/usr/bin/pwd

DESCRIPTION

pwd writes an absolute path name of the current working

directory to standard output.

Both the Bourne shell, sh(1), and the Korn shell, ksh(1),

also have a built-in pwd command.

ENVIRONMENT

See environ(5) for descriptions of the following environment

variables that affect the execution of pwd: LC_MESSAGES and

NLSPATH.

EXIT STATUS

--More--(30%)

 Not all parameters in the man command are command names. For example, the man ascii commanddisplays all the ASCII characters and their expressions. The man shell_builtins command displays the

 built-in command list and the shell using the commands.

B.4.2 Viewing the Free Disk Space -- df

Description

View the free disk space. The system administrator executes this command frequently to checkthe usage of the disk space to prevent disk failure due to data overflow.

Command Format

df  [option] [ file system] 

Option Description

-l : the local file system

-k : to view the free disk space (unit: kbyte)

Example

Check the free disk space.

Execute the following command:

$ df -k

Page 32: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 32/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-29

 

Filesystem kbytes used avail capacity Mounted on

/dev/dsk/c0t0d0s0 2053605 997684 994313 51% /

/proc 0 0 0 0% /proc

fd 0 0 0 0% /dev/fd

/dev/dsk/c0t1d0s7 35009161 2562019 32097051 8% /export/home

swap 3431792 6664 3425128 1% /tmp

The command output shows the following information:

  File system name

  File size (unit: kbyte)

  Used space

  Free space

  Capacity percentage of the filled file system and the mounting point

When you execute the df  command without any parameters, the free disk space in eachmounted device is displayed.

When the free disk space reduces to the bottom line, the system administrator must takemeasures immediately to find out the faulty file system.

B.4.3 Viewing the Disk Space Used by Each File System -- du

Description

View the disk space used by a specific folder or file.

Command Format

du [option] [ folder or file] 

Option Description

  -a: to view the disk space used by each file

  -s: to view the total disk space used

  -k : to view the result (unit: kbyte)

Example

  View the disk space used by the files in the /export/home/sybase folder.Execute the following command: 

$ du -k/export/home/Sybase |more

212554 /export/home/sybase/bin

7 /export/home/sybase/charsets/ascii_8

76 /export/home/sybase/charsets/cp437

124 /export/home/sybase/charsets/cp850

214 /export/home/sybase/charsets/deckanji

237 /export/home/sybase/charsets/eucgb

235 /export/home/sybase/charsets/eucjis

142 /export/home/sybase/charsets/iso_1

13 /export/home/sybase/charsets/mac

Page 33: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 33/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-30 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

78 /export/home/sybase/charsets/roman8

221 /export/home/sybase/charsets/sjis

1119 /export/home/sybase/charsets/unicode

1383 /export/home/sybase/charsets/utf8

3850 /export/home/sybase/charsets

76 /export/home/sybase/collate/unicode

77 /export/home/sybase/collate

97 /export/home/sybase/config

87484 /export/home/sybase/devlib

1921 /export/home/sybase/diag/bin

3 /export/home/sybase/diag/custom

37 /export/home/sybase/diag/formdefs

225 /export/home/sybase/diag/locales/us_english

--More—

  View the disk space used by all file systems in the current folder, and then send the results

to the sort command for sorting.

Execute the following command:

$ du -s * |sort -rn |more 

425108 bin

174968 devlib

41094 lib

18588 pad

9406 locales7700 charsets

6810 scripts

5552 install

4636 diag

4404 upgrade

1220 sample

834 symlib

718 include

194 sybhelp

194 config

154 collate

76 init

50 license

14 xappdefaults

12 sybserver.cfg

12 sybserver.bak

12 sybserver.083

--More—

 

List the first three file systems according to the file size.

Page 34: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 34/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-31

 

Execute the following command:

$ du -s * |sort -rn |head -10 

425108 bin

174968 devlib

41094 lib

18588 pad

9406 locales

7700 charsets

6810 scripts

5552 install

4636 diag

4404 upgrade

B.4.4 Viewing the Status of the Active Process -- psDescription

View the status of the processes that are currently running in the system.

Command Format

ps [option]

Option Description

 

-e: to view the status of all the processes that are running in the system

  -l : to view the running processes in a long-form list

  -u user : to view the process status of a specific user

  -f : to view all the status information about the processes that are running in the system

Example

  View the status of all the running processes controlled by the login device (the terminal).

Execute the following command:

$ ps

PID TTY TIME CMD

13726 pts/5 0:00 ksh

  View the complete information about the active processes.

Execute the following command:

$ ps -f

UID PID PPID C STIME TTY TIME CMD

sybase 13726 13724 0 08:44:35 pts/5 0:00 –ksh

  View the M2000 processes.

Execute the following command:

$ ps -ef | grep m2000

m2000 18355 18354 0 10:00:46 ? 0:00/export/home/02000/bin/timersvrd

Page 35: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 35/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-32 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

m2000 18354 1 0 10:00:46 ? 0:00 monsvrd /export/home/m2000/bin/timersvrd

m2000 18318 1 0 10:00:42 ? 0:00 monsvrd /export/home/m2000/bin/commonsvrd

m2000 18320 18318 0 10:00:42 ? 0:00/export/home/m2000/bin/commonsvrd

  After you execute the ps command without any parameters, the screen displays information about allrunning processes that are controlled by the login device (terminal).

  After you specify the –f  parameter, more information is displayed. The information includes the username (UID), process ID (PID), parent process ID (PPID), technical number that indicates the runningtime of the process (C), process start time (STIME), name of the terminal that activates the process(TTY), and the process name (CMD).

  To view all the processes related to certain characters, for example, the process related to M2000,execute the grep command with the ps command.

B.4.5 Terminating a Process -- kill

DescriptionSend termination signal to one or more processes to terminate the process(es).

Command Format

kill [option] [ process No.] 

Option Description

  -l : to list the names of all the signals

  -s signal : to send a signal named signal to the processes

Parameter Description

 Process No.: the ID of the process to be terminated, that is, the process ID

Example

  List all the signal names.

Execute the following command:

$ kill -l

EXIT HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRMTERM USR1 USR2 CLD PWR WINCH URG POLL STOP TSTP CONT TTIN TTOUVTALRM PROF XCPU XFSZ WAITING LWP FREEZE THAW CANCEL LOSTRTMIN RTMIN+1 RTMIN+2 RTMIN+3 RTMAX-3 RTMAX-2 RTMAX-1 RTMAX

  Terminate the process with PID as 256.

Execute the following command:

The kill command may lead to data loss. Be cautious with this command.

Page 36: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 36/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-33

 

$ kill -s KILL 256

  The previous signal names can be expressed by code. For example, -1 for HUP, -2 for INT, -3 forQUIT, -9 for KILL, and -15 for TERM. 

The signal KILL can be replaced with -9. This signal is the most frequently used one in the kill command, and thus it has the highest priority. The default signal 15 is used when no option is specifiedfor the kill command. Execute the following command to terminate the process with the PID as 256:

$ kill -9 256 

  Execute the ps command to check the execution of the kill command by listing the PIDs of theterminated processes.

B.4.6 Viewing Information About Current Login Users -- who

Description

View the login information of all the users that have logged in to the current system.

Command Format

who [option] 

Option Description

  -b: to view the date and time when the system last booted

  -m: to view information about the user executing the command (same as the case when the

who command with two parameter am and i is executed) 

Parameter Descriptionam i: to view the information about the user who logs in to the device sending out commands

Example  View the login information about all the users in the current system.

Execute the following command:

$ who

root pts/3 Feb 4 10:08 (10.129.16.60)

sybase pts/5 Feb 4 08:45 (10.129.28.44)

  View the information about the user who logs in to the device where the command is

executed.

Execute either of the following commands:

$ who am i

sybase pts/5 Feb 4 08:45 (10.129.28.44)

or

$ who -m

sybase pts/5 Feb 4 08:45 (10.129.28.44)

Page 37: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 37/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-34 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

B.4.7 Viewing the Command Location -- whereis

Description

View the location of a source file, binary file, and online help of a command.

Command Format

whereis [option] [command ] 

Option Description

  -b: to view the location of only the binary file

  -m: to view the location of only the help manual

  -s: to view the location of only the source file

Parameter Description

command : the command for which the location is to be displayed

Example

  View the exact location of files of various versions for the ls command.

Execute the following command:

$ whereis ls

ls: /usr/bin/ls /usr/ucb/ls /usr/man/man1/ls.1 /usr/man/man1b/ls.1b

 

To view the exact location of the binary file for the ls command, execute the followingcommand:

$ whereis -b ls

ls: /usr/bin/ls /usr/ucb/ls

  View the exact location of the help manual for the ls command.

Execute the following command:

$ whereis -m ls

ls: /usr/man/man1/ls.1 /usr/man/man1b/ls.1b

B.4.8 Viewing the Path of a Specific Command -- which

Description

View the location where a command is executed.

The result may be an absolute path or alias of the command found in the user environmentvariant PATH.

Command Format

which [command ] 

Page 38: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 38/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-35

 

Example

View the position where the commands pwd, who, and which are executed.

Execute the following command:

$ which pwd who which

/usr/bin/pwd

/usr/bin/who

/usr/bin/which

If the command to be located does not exist in the file, the following error messages are displayed afteryou execute the which command:

$ which qqqq

no qqqq in /usr/bin /usr/ucb /etc /export/home/sybase/bin /export/home/sybase/install .

B.4.9 Viewing or Setting the Host Name -- hostname

Description

View or set the host name.

Command Format

hostname [host name] 

Example

View the host name.

Execute the following command:

$ hostname

If you execute the hostname command without parameters, the host name of the equipment is displayed.If you execute the hostname command with parameters, the host name is to be set. Only the super user canexecute the hostname command.

B.4.10 Viewing Information About the Operating System --

uname

Description

View information about the operating system.

If you execute this command without parameters, only the name of the operating system isdisplayed. If you execute this comand with parameters, more details about the operating systemis displayed.

Command Format

uname [option] 

Page 39: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 39/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-36 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

Option Description

  -a: to view all the information

  -i: to view hardware information

 

-m: to view the name of the equipment hardware (It is suggested that option "-p" shall beused instead of this one)

  -n: to view the network name of the equipment

  -p: to view the ISA of the host or the type of the processor

  -r : to view the serial number of the operating system of the host

  -s: to view the name of the operating system of the host (it is the default option).

  -v: to view the version of the operating system of the host

  -S system_name: to set the host name of the machine

Example

View the name, version, and serial number of the operating system on the host.

Execute the following command:

$ uname -svr

B.4.11 Viewing the Host IP Address -- ifconfig

Description

View the IP address of the host.

Command Format

ifconfig [option] 

Option Description

-a: to view all the address information

Example

View the IP address of the host.

Execute the following command:

$ ifconfig -a

lo0: flags=849<UP,LOOPBACK,RUNNING,MULTICAST> mtu 8232inet 127.0.0.1 netmask ff000000

hme0: flags=863<UP,BROADCAST,NOTRAILERS,RUNNING,MULTICAST>mtu 1500 inet 129.9.169.143

netmask ffff0000 broadcast 129.9.255.255

hme0:1:flags=863<UP,BROADCAST,NOTRAILERS,RUNNING,MULTICAST> mtu 1500 inet

129.6.253.136 netmask ffff0000 broadcast 129.6.255.255

In the above output, the IP address of the displayed host is 129.9.169.143, and the logical IP address is129.6.253.136. In the UNIX system, a network adapter can bind several logical IP addresses, whichrealizes communications between different network segments.

Page 40: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 40/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-37

 

B.4.12 Recording Screen I/O Activities – script

Close the script file before you execute the exit command to terminate the recording of thescreen I/O. If you do not close the script file, the script file builds up and hinders the normaloperation of the system.

Description

Record in a script file all the screen input and output occurred from the time when the script command is executed to the time when the exit command is entered. The script command ishelpful for programming and debugging.

Command Format

script [option] [ file]

Option Description

-a: to append the screen I/O content to a file. 

If you do not set the –a parameter, the screen I/O overwrites the content of the file.

Parameter Description file: the file used to save the screen I/O content. 

If you do not specify the file name, the screen I/O content is saved to the typescript file.

Example

  Save the screen I/O content in the default destination file typescript.Execute the following commands:

$ script

Script started, file is typescript

$ psPID TTY TIME CMD

775 pts/8 0:00 ksh

$ pwd

/export/home/sybase

$ exit

Script done, file is typescript

  View the content of the typescript file.

Execute the following commands:

$ cat typescript

Script started on Mon Feb 04 19:11:49 2002

Page 41: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 41/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-38 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

………Omit the display content

$ exit

script done on Mon Feb 04 19:12:24 2002

B.4.13 Viewing the Current Date and Time -- date

Description

View the current date and time of the system.

The super user can execute the date command to set the system date and time.

Command Format

date [option] [+format ] 

Option Description

  -u: to use the Greenwich mean time

  +format : to specify the command output format

Table B-14 describes the format of the command output.

Table B-14  Format of the command output

Format Description

%h  Abbreviation of the month: from January to December

%j  Day in a year: from 001 to 366

%n  To switch to next line

%t   The tab key

%y  The last two digits of the year: from 00 to 99

%D  Output format of the date: month/date/year

%H   Hour: from 00 to 23

%M   Minute: from 00 to 59

%S   Second: from 00 to 59

%T   Output format of time: hour:minute:second

Example

  View the current date and time of the system.

Execute the following command:

$ date

Mon Feb 4 20:26:16 GMT 2002

  View the current system date and time in the Greenwich Mean Time.

Page 42: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 42/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-39

 

Execute the following command:

$ date -u

Mon Feb 4 12:27:26 GMT 2002

B.5 Network Communication Commands

B.5.1 TCP/IP Protocols

Because of powerful networking functions, the UNIX system is widely used, and is the firstchoice for all kinds of servers on the Internet. The TCP/IP protocol is the default network protocol for the UNIX system.

The TCP/IP protocol is composed of a series of protocols, which form the TCP/IP protocolfamily. The TCP/IP is the basic protocol of this family.

The following protocols are commonly used:

  TCP/IP: Transmission Control Protocol/Internet Protocol, is the basic protocol of the

 protocol family.

  UDP: User Datagram Protocol, provides the connectionless transport layer protocol. The

reliability of the transmission, however, is not ensured.

  Telnet: a user layer protocol, provides standards for remote login.

  FTP: File Transfer Protocol, a user layer protocol also, provides standards for file copying

 between various systems.

B.5.2 Network Communication Commands

Table B-15 describes the commands that are commonly used during network communications.

Table B-15  Network communication commands

Command Description

ping [ IP address] To test the physical connection of thenetwork

telnet [ IP address] | [domain] To log in to a remote computer throughnetwork connection

ftp [ IP address] | [domain] To transfer files on the network

finger [user name] [@ host domain name | IPaddress] 

To view the user information by usingUNIX system on the network

netstat [option]  To view the network status

route [option]  To modify and maintain the routing table

Page 43: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 43/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-40 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

B.5.3 Testing the Physical Network Connection -- ping

Description

Check the physical connection of the network when the communication between a usercomputer and the hosts in the network is interrupted.

Example

$ ping 129.9.0.1

129.9.0.1 is alive

Internet Control Message Protocol (ICMP) is used by the ping command to check the networkconnection. An ICMP echo request message is sent to a specific host, and requests for an ICMPecho response message. If the response message is not received within a specified time, theHost unreachable message is displayed on the screen.

The Host unreachable message is displayed in the following cases:

  The specified host is invalid.

  The physical connection of the network is not secure.

  The two communicating parties do not support the same communication protocol.

To analyze the causes, execute the ping command to connect with other hosts in the samenetwork segment. If the ping command is executed successfully, it indicates that the connectionis functional. In this case, check the physical connection and operation status of the peer system.If the ping command fails, check if the physical network connection of the local computer issecure or if the TCP/IP protocol is set correctly (for Windows’95 users only).

B.5.4 Logging In to a Remote Computer Through NetworkConnection—telnet

Before starting telnet, make sure the TCP/IP protocol between the local computer and theremote UNIX host is linked correctly.

Description

Telnet is the software used to log in to remote UNIX hosts through network connection. Telnettakes the local computer as a simulated terminal of the remote UNIX host, and enables you tolog in to the remote server from the local computer.

After you log in to the remote UNIX host successfully through telnet, you become a remotesimulated terminal user and can use the local computer as a real UNIX terminal. In this case, theresources and functions available and the operating mode completely depend on the settings ofthe remote host and the access privileges of the login account.

Page 44: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 44/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-41

 

Command Format

telnet [ IP address] | [domain] 

Parameter Description   IP address: the IP address of the remote UNIX host

   Domain: the domain name of the remote UNIX host

Example

Execute telnet on the local computer to log in to a remote WS named Sun. Suppose that the IPaddress of Sun is 129.9.169.143.

Click the Start menu on the local computer and select Run. In the displayed dialog, enter telnet

129.9.169.143 and click OK . ATelnet window is displayed to prompt you to enter the UNIXuser name and password, as shown below:

Sun OS 5.6

log sybase

Password: Password not echo

Last login: Wed Mar 6 10:52:34 from 129.9.28.44

Sun Microsystems Inc. SunOS 5.6 Generic August 1997

You have new mail.

$

The following steps are the same as those when you operate on a terminal window of the SunWS.

B.5.5 Transferring Files Through Network Connection -- ftp

Description

Similar to telnet, you can execute the ftp command to log in to a remote UNIX host and sharethe resources. The ftp command is mainly used to transfer files between the local computer andthe remote host. You can transfer one or more files at a time between the remote UNIX systemand the local computer.

Command Format

ftp [ IP address] | [domain] 

Parameter Description

   IP address: the IP address of the remote UNIX host

   Domain name: the domain name of the remote UNIX host

Example

Execute ftp on the local computer. Suppose that the IP address of the remote UNIX host is129.9.169.143.

Click the Start menu on the local computer, and select Run. In the displayed dialog box, enterftp 129.9.169.143, and click OK . When the ftp window is displayed, enter the UNIX user name

and password, as shown below:

Page 45: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 45/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-42 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

Connected to 129.9.169.143.

220 m2000-01 FTP server (Sunos 5.6) ready.

User (129.9.169.143: (none) : ) sybase

331 Password required for Sybase.

Password:

230 User Sybase logged in.

ftp>

Enter the ftp command behind the prompt ftp>. Table B-16 describes the ftp commands thatare commonly used.

Table B-16 Common ftp commands

FTP Command Description

! Command To execute the local command and return to ftp immediately.

? | help [command ] To view the command help.

ascii  To transfer files in the ASCII format (default).

binary  To transfer files in the binary format.

cd [ folder ] To modify the remote folder.

close  To shut down the remote connection.

dir [r-folder ] [l-file] To view the remote folder.

  r-folder: refers to the remote folder.

  l-file: refers to the local file.

If there is a local file, save the result to the locla file.

get [ file1] [ file2] To copy the remote file 1 to the local file 2.

lcd [ folder ]  To modify the local folder.

ls [r-folder ] [l-file] Same as dir, but the display format is different.

mget several files To copy several remote files to the local computer.

mput several files To copy several local files to the remote computer.

open [ IPaddress] | [domainname]

To re-establish a connection.

put  [ file1] [ file2] To copy the local file 1 to the remote file 2.

pwd  To list the folders of the current remote host.

Quit | bye To exit ftp.

status  To view the current ftp status.

  Copy all the files in the path C:\mydoc on the local computer to the /usr/local/tmp folder

on the remote host.

Execute the following commands:

Page 46: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 46/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-43

 

ftp> binary

ftp> lcd c:\mydoc

ftp> cd /usr/local/tmp

ftp> mput *.*

  Copy the .login file in the /usr/home/rms folder on the remote host to the path

C:\temp\from on the local computer.

Execute the following commands:

ftp> ascii

ftp> lcd c:\temp\from

ftp> cd /user/home/rms

ftp> get .login

  Copy all files in the /usr/home/rms folder on the remote computer to the path

C:\temp\from on the local computer in the binary format.

Execute the following commands:ftp> binary

ftp> lcd c:\temp\from

ftp> cd /user/home/rms

ftp> mget *

  Exit the FTP mode.

Execute the following command:

ftp> quit

The Telnet and FTP protocols belong to the TCP/IP family. They are the protocols at the application layer.

They work in the client/server mode. The telnet/ftp program running on the local computer is a telnet/ftpclient program. It connects to the server program in the remote host through and works in cooperation withthe TCP/IP protocol.

Any system installed with the telnet/ftp server-side software can serve as a remote host. In addition to thedefault network protocol TCP/IP, the UNIX system supports the Telnet/FTP protocols. As a UNIX host isinstalled with both the telnet/ftp server-side software and client-side software, it can serve as either atelnet/ftp server or a telnet/ftp client.

B.5.6 Viewing Information About Online Users -- finger

Description

View information about online users of the UNIX system.

Command Format

finger [user name][@host domain| IP address]

Parameter Description

  user name: the user that has currently logged in to the local system

  host domain: the UNIX host domain

   IP address: the IP address of the UNIX host

Page 47: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 47/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-44 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

Example

Table B-17 lists some examples of finger commands.

Table B-17 Examples of finger commands Example Description

$ finger To view information about all local users

$ finger root To view information about the root user

$ finger @omcsyb2 To view information about all users in the host omcsyb2 

$ finger

@omcsyb2.huawei.com.cn

To view information about all users in the hostomcsyb2.huawei.com.cn 

$ finger abc@omcsyb2 To view information about the user abc in the host

omcsyb2 $ finger [email protected] To view information about the user abc in the host

129.6.114.202 

B.5.7 Viewing Network Status -- netstat

Description

View the current network status.

The netstat command is a powerful command, however, complex in format. This sectiondescribes common applications of the command.

Command Format

netstat [options]

Option Description

For viewing all sockets and routing tables (netstat [-anv])

  -a: to view all socket information

  -n: to view information by number

If you do not specify this parameter, the information is displayed by logical name.

  -v: to view information about sockets and routing tables of the additional information

For viewing the IP address of the network adapter (netstat [-i][-I interface][interval])

  -i: to view information about the network interface

  -I interface: to specify an interface, for exmaple, hme0:1

  interval : the time interval

For viewing the routing table status (netstat -r [-anv])

 

-r : to view information about the routing table

Page 48: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 48/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-45

 

  -anv: same as viewing all sockets and routing tables

For viewing the broadcast information (netstat -M[-ns])

  -M : to view broadcast routing tables

 

-s: to summarize the status of each protocol

For viewing the DHCP status (netstat -D[-I interface])

-D: to view the DHCP information

Example

View information about the routing table.

Execute the following netstat  –rn command: 

root@ts-007 # netstat -rn

Routing Table:

Destination Gateway Flags Ref Use Interface

10.105.28.0 10.105.28.202 U 4 2 hme0

10.0.0.0 10.105.31.254 UG 0 0

224.0.0.0 10.105.28.202 U 4 0 hme0

127.0.0.1 127.0.0.1 UH 0 896 lo0

A router can be in either of the following five different flags: U, G, H, D, and M.

  U means that the routing is currently available.

  G means that the routing goes to a gateway such as a router.

If this flag is not set, it indicates that the destination is connected directly. Flag G 

distinguishes between direct and indirect routings. (Flag G is unnecessary for directroutings.) The difference is as follows: The packet sent to the direct routing carries boththe destination IP address and the link-layer address; in the packet sent to an indirectrouting, however, the IP address points to the destination and the link layer address pointsto the gateway (for example, the next router).

  H indicates the routing that leads to a host. In other words, the destination address is a

complete host address.

If this flag is not set, it indicates that the routing leads to a network, and that the destinationaddress is a network address: either a network number or a network. The part in theaddress for the host is 0. When searching for the routing table for an IP address, the hostaddress must exactly match the destination address, while the network address is requiredto match only the network number and subnetwork number of the destination address.

  D means that the routing is created by the redirected packet.

  M means that the routing is modified by the redirected packet.

The reference count column Refcnt shows the number of active processes that are currentlyusing the routing. The connection-oriented protocol, such as the TCP, requires a fixed routingduring the connection setup. If the host establishes a Telnet connection between svr4 and slip,the reference count is 1. When another Telnet connection is established, the reference count isadded up to 2, and so on.

The next column use shows the number of packets sent through this routing. If you are the onlyuser that uses this routing, after you execute the ping command and send five packets, thenumber displayed in this column is 5. The last column interface shows the name of the local

interface.

Page 49: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 49/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

B-46 Huawei Technologies Proprietary Issue 03 (2007-02-07)

 

The second row of the output is a loop-back interface. The interface name is always lo0. Flag G is not set here because the routing is not a gateway. Flag H indicates that the destination address,127.0.0.1, is a host address instead of a network address. As flag G is not set, the routing here isa direct routing, and the gateway column shows the out-going IP address.

Default routing: Each host has one or more default routings. In other words, if a particularrouting is not found in the table, the packet is sent to the router. In addition, the current host canaccess the other systems through the Sun router (and the slip link) on the internet based on thesettings of the routing table. The flag UG refers to the gateway.

B.5.8 Modifying and Maintaining the Routing Table -- route

Description

Modify and maintain the routing table.

The routing table relays IP address between network segments. The relay station is the gateway.

Command Format

route [-fnvq] [command ] [ [modifiers] args] 

route [-fnvq] [add ] | change | delete |get   [host | net ] destination [ gateway [args]]

route [-n] [monitor ] 

route [-n] [ flush] 

Option Description

 

-f : to refresh routing tables for all gateways

  -n: to view information in characters instead of symbols

  -v: to view the additional information

  -q: to suspend all outputs

  -command : add/chang/flush for clearing gateways in the routing table and /get/monitor 

  -description: the destination network segment; for example, 10.0.0.0 stands for section10,

and 10.11.0.0 stands for section 10.11

  -gateway: the IP address of the gateway

  net : the network segment IP address; for example, 10.11.12.0 stands for section 10.11.12

   Host : the IP address of the host

Example

  Obtain the routing information about network segment 10.

Execute the following command:

root@ts-007 # route -n get 10.0.0.0

route to: 10.0.0.0

description: 10.0.0.0

mask: 255.0.0.0

gateway: 10.105.31.254

interface: hme0

Page 50: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 50/51

M2000

Administrator Guide B Common Operations of the UNIX System

 

Issue 03 (2007-02-07) Huawei Technologies Proprietary B-47

 

flags: <UP, GATEWAY, DONE, STATIC>

recvpipe sendpipe ssthresh rtt, msec rttvar hopcount mtu expire

0 0 0 0 0 0 1500 0

  Clear gateways in the routing table.

Execute the following commands:

root@ts-007 # route -n flush

10 10.105.31.254 done

root@ts-007 # netstat -rn

Routing Table:

Destination Gateway Flags Ref Use Interface

------------------- -------------- ----- ----- ------ ---------

10.105.28.0 10.105.28.202 U 4 6 hme0

224.0.0.0 10.105.28.202 U 4 0 hme0

127.0.0.1 127.0.0.1 UH 0 1500 lo0

root@ts-007 # telnet 10.129.3.4

Trying 10.129.3.4...

telnet: Unable to connect to remote host: Network is unreachable

After the gateways in the routing table are cleared, the network segments beyond 10.105.28.202/34 are nolonger accessible.

  Add a routing record.

Execute the following command:

root@ts-007 # route add 129.9.0.0 10.105.28.202

add net 129.9.0.0: gateway 10.105.28.202 //Message returned when addingrouting is successful.

root@ts-007 # netstat -rn

Routing Table:

Destination Gateway Flags Ref Use Interface

-------------------- ------------- ----- ----- ------ ---------

10.105.28.0 10.105.28.202 U 4 2 hme0

129.9.0.0 10.105.28.202 UG 0 0 //Newly-added routing

10.0.0.0 10.105.31.254 UG 0 0

224.0.0.0 10.105.28.202 U 4 0 hme0

127.0.0.1 127.0.0.1 UH 0 313 lo0

  Modify the routing table (important).

Execute the following command: 

root@ts-007 # route change 129.9.0.0 1.2.3.4

change net 129.9.0.0: gateway 1.2.3.4

root@ts-007 # netstat -rn

Routing Table:

Destination Gateway Flags Ref Use Interface

-------------------- -------------------- ----- ----- -------

Page 51: 02-B Common Operations of UNIX System

7/25/2019 02-B Common Operations of UNIX System

http://slidepdf.com/reader/full/02-b-common-operations-of-unix-system 51/51

B Common Operations of the UNIX System

M2000

Administrator Guide

 

10.105.28.0 10.105.28.202 U 4 2 hme0

129.9.0.0 1.2.3.4 UG 0 0 //The gateway has been modified.

10.0.0.0 10.105.31.254 UG 0 0

224.0.0.0 10.105.28.202 U 4 0 hme0

127.0.0.1 127.0.0.1 UH 0 445 lo0