歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> Unix基礎知識 >> Unix基礎教程(1)

Unix基礎教程(1)

日期:2017/2/25 10:12:35   编辑:Unix基礎知識

第1章 UNIX簡介

【例1-1】使用telnet登錄到遠程一台AIX系統的例子。

括號內的楷體字內容是一些注釋。

$ (在shell提示符下輸入命令)

$ telnet 202.172.122.135

Trying...

Connected to 202.172.122.135.

Escape character is '^]'.

AIX Version 5

(C) Copyrights by IBM and by others 1982, 2000.

login: jiang (出現登錄提示符,輸於遠程計算機用戶的用戶名/口令)

jiang's Password:***

**********************************************************

* Welcome to AIX Version 5.1!

* Please see the README file in /usr/lpp/bos for information

* pertinent to this release of the AIX Operating System.

**********************************************************

Last unsuccessful login: Wed Jun 25 12:38:45 2003 on /dev/pts/0 from 61.149.71.89

Last login: Wed May 19 08:04:53 2004 on /dev/pts/0 from 61.149.159.49

$

(登錄到了遠程的計算機,這裡的shell提示符$是遠程計算機給出的,在此輸入的命令,在遠程計算機上執行)

$ tty

/dev/pts/1

$ who am i

jiang pts/1 May 19 08:45

$

$ ^](在此按下轉義字符Ctrl-]鍵,會出現telnet的提示符,開始和本地telnet仿真程序會話)

telnet> help

Commands may be abbreviated. Commands are:

close

close current connection

display

display operating parameters

emulate

emulate a vt100 or 3270 terminal

mode

try to enter line-by-line or character-at-a-time mode

open

connect to a site

quit

exit telnet

send

Transmit special characters ('send ?' for more)

set

set operating parameters ('set ?' for more)

status

print status information

toggle

toggle operating parameters ('toggle ?' for more)

z

suspend telnet

?

print help information

telnet> (在此直接按回車,退出和telnet程序的會話,繼續與遠程計算機會話)

1 1 2 3 4 5

2 3 4 5 6 7 8 6 7 8 9 10 11 12

9 10 11 12 13 14 15 13 14 15 16 17 18 19

16 17 18 19 20 21 22 20 21 22 23 24 25 26

23 24 25 26 27 28 29 27 28

30 31 . . .

November December

Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5 1 2 3

6 7 8 9 10 11 12 4 5 6 7 8 9 10

13 14 15 16 17 18 19 11 12 13 14 15 16 17

20 21 22 23 24 25 26 18 19 20 21 22 23 24

27 28 29 30 25 26 27 28 29 30 31

$ cal 10 2006

October 2006

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30 31

【例1-5】使用bc命令的例子。

其中的圓括號內的楷體字提示使用bc時的注意事項。

$ bc (啟動bc命令)

18 * (5 + 5) (輸入一個表達式,表達式中可以使用括號)

180 (打印出表達式的計算結果)

1024 * 4096

4194304

(下邊是一個高精度計算的例子。在32位系統中,數據線寬度32比特,CPU一次可運算的最大整數是4G,這也是C語言中無符號整數的最大值,下邊的兩個數以及它們的乘積都超過了4G)

1234567890123456789012345 * 9876543210987654321098765

12193263113702179522618496034720321071359549253925

2.5 * 2.1 (浮點數運算)

5.2 (運算結果應當是5.25,但是由於精度太低,未能取得期望的值)

1/113

0 (浮點數運算結果的精度太低,未能取得期望的值)

scale=40

(上述語句設置bc的內部控制變量,使得計算結果可保留到小數點後40位。很糟糕,scale的默認值為零,才有上述兩次計算結果的不如意)

2.5 * 2.1

5.25 (重新計算,得到正確結果)

1/113

.0088495575221238938053097345132743362831

(運算結果是無限循環小數,保留40個小數位)

(在這裡按下Ctrl-D鍵,退出bc程序,返回shell,出現shell提示符)

$

$ bc -l

(使用bc命令帶-l選項, bc的內部控制變量scale自動被設置為20,再進行浮點運算2.5*2.1或1/113會得到期望的結果,期望保留更多的小數位數,可以自行設置scale控制變量。-l選項原意是library,定義了一個bc使用的任意精度的數學函數庫,包括正弦函數s(x),余弦函數c(x)等,另外,將scale初始設置為20)

2.5 * 2.1

5.25

1/113

.00884955752212389380

p = 2.346901

(bc允許使用a~z的26個寄存器,後邊的計算如果經常使用這個值,將它存入到寄存器p中)

17.8 * p

41.7748378

198.23 * p

465.22618523

$

在使用浮點數運算的時候,最好直接使用bc –l選項。有關bc命令的更豐富功能,可參閱命令手冊。

Copyright © Linux教程網 All Rights Reserved