unix编程环境入门(一)

 1.1.0 按键


return 键是一种控制字符==即不可见字符,他控制着输入输出的某种状况。
在任何终端上,return都有自己的按键,但是其他大多数控制字符并非如此。
相反,它们可以通过control键,同时按下另一个键,通常是一个字母来输入。
例如:return键又称为control-m键,即ctrl-m。
其他控制字符:
ctrl-d: 表示程序输入到此结束
ctrl-g:终端上振铃鸣响
ctrl-h:通常为backspace,即退格键,在纠正错误时,使用
ctrl-i:通常作为tab键,它是光标跳往下一个tab的停止位,与普通的打字机类似。
在unix系统中tab间隔8个字符,在多数终端上都有backspace和tab键

两个有特殊意义的键:
delete: 有时称为robout 
break:有时称为 interrupt。
在unix系统中,按delete键可以立即终止程序,而不等待程序完成;
在某些系统中按ctrl-c完成同样的功能
而在有些系统中,break可能是delete或者ctrl-c的同义词。


1.1.1 与unix会话

通过putty连接远程主机:
系统显示:
login:username  // input your username and press down the return
password:// input your password,but the system doesn't echo it on screen

#you have mail

login as: wzb
wzb@211.87.235.108's password:
Last login: Thu Mar  3 15:05:51 2011
[wzb@wzb ~]$ who
root     tty1         2011-03-05 09:30
root     pts/0        2011-03-05 09:31 (:0.0)
root     pts/1        2011-03-05 10:29 (211.87.235.104)
wzb      pts/2        2011-03-05 10:30 (211.87.235.104)
[wzb@wzb ~]$ date
2011年 03月 05日 星期六 10:30:36 CST
[wzb@wzb ~]$ mail
No mail for wzb
[wzb@wzb ~]$ mail
No mail for wzb
[wzb@wzb ~]$ d
-bash: d: command not found
[wzb@wzb ~]$ mail root
Subject: hello, i'm login now


Cc: wzb
[wzb@wzb ~]$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/wzb": 1 message 1 new
>N  1 wzb@wzb.cn            Sat Mar  5 10:31  17/489   "hello, i'm login now"
& ?
    Mail   Commands
t <message list>                type messages
n                               goto and type next message
e <message list>                edit messages
f <message list>                give head lines of messages
d <message list>                delete messages
s <message list> file           append messages to file
u <message list>                undelete messages
R <message list>                reply to message senders
r <message list>                reply to message senders and all recipients
pre <message list>              make messages go back to /usr/spool/mail
m <user list>                   mail to specific users
q                               quit, saving unresolved messages in mbox
x                               quit, do not remove system mailbox
h                               print out active message headers
!                               shell escape
cd [directory]                  chdir to directory or home if none given

A <message list> consists of integers, ranges of same, or user names separated
by spaces.  If omitted, Mail uses the last message typed.

A <user list> consists of user names or aliases separated by spaces.
Aliases are defined in .mailrc in your home directory.
& n
At EOF
& !ls
Desktop       sh    VMwareTools-8.1.4-227600.tar.gz
manifest.txt  test  vmware-tools-distrib
!
& q
Held 1 message in /var/spool/mail/wzb
You have mail in /var/spool/mail/wzb
[wzb@wzb ~]$

1.1.2 登陆(login )
登陆必须有用户名和密码(username and password)
用户名和密码是大小写敏感的。并且输入口令时,口令不在屏幕上复显。

如果登陆成功,通常是root用户的提示符为#,一般用户的提示符为$,这是在bash下。在其他解释程序下有可能不同。
login: yourusername
passwrod:         

1.1.3 命令的使用
在bash的提示符下输入,输入命令。the shell command interpreter will interpret it by the system and complete the communication with the system. so the shell is a command interface of the unix system.
[wzb@wzb ~]$ date
2011年 03月 05日 星期六 10:45:13 CST
[wzb@wzb ~]$ who
root     tty1         2011-03-05 09:30
root     pts/0        2011-03-05 09:31 (:0.0)
root     pts/1        2011-03-05 10:29 (211.87.235.104)
wzb      pts/2        2011-03-05 10:30 (211.87.235.104)
[wzb@wzb ~]$

1.1.4 异常的终端行为
手册的第一节中有关stty( set terminal options) 命令叙述。如果终端没有tab键,要想巧妙地处理该键,可键入命令:
$ stty -tabs
$ tabs  终端类型

//在linux下,测试没有成功,没有设置成功


1.1.6 键入错误:
键入错误在按return键前,发现,有两种纠正方法:一次删除一个字符或者删除整行重新键入。
消行符号:@
#为字符删除符号;
(思考:该输入字符的缓冲区是不是一个stack,栈,解释器利用栈中的特殊字符,对栈中的字符进行处理,就起到删除作用了)
//在支持delete和backspace的linux虚拟终端上,测试不成功。
[wzb@wzb ~]$ date
2011年 03月 05日 星期六 11:00:31 CST
[wzb@wzb ~]$ datee#
-bash: datee#: command not found
[wzb@wzb ~]$ date@
-bash: date@: command not found
[wzb@wzb ~]$
但是可以用backspace,来删除字符,测试成功
删除行,可以用ctrl-u 来完成,测试成功:
转义字符:escape字符:/可以使特殊字符失去其特殊意义,而具有一般意义
练习:
[wzb@wzb ~]$ /#date
-bash: #date: command not found
[wzb@wzb ~]$ //#date
-bash: /#date: command not found
[wzb@wzb ~]$ date /@
date: invalid date “@”
[wzb@wzb ~]$

shell(v7,第七版)把#作为注释符,忽略从#开始到行尾的全部文字。
[wzb@wzb ~]$ date # this command will display the current date
2011年 03月 05日 星期六 11:11:06 CST
[wzb@wzb ~]$


1.1.7继续键入:
在系统在屏幕上进行输出的同时,可以继续键入命令,虽然在屏幕上,输入的字符和系统输入的字符混杂,但是系统会为输入令存一个缓冲区。无需等待即可完成输入。

1.1.8 终止程序,终止输出和恢复
delete/ break
中断输出: 
要避免某些重要的信息在屏幕上出现时,可以键入:
ctrl-s,输出立即停止,程序被挂起直到再次启动。
要打算继续输出,可以键入ctrl-q;
//在linux上测试通过, 呵呵,想想自己平时用vi的时候,有没有像在windows下一样,想保存文件时按了一下ctrl-s,结果系统一直发呆假死,好像死机了似的,
那时不知道有ctrl-q这个命令可以退出ctrl-s,只好重启,或者关掉虚拟终端,重新登录。


1.1.9注销(logout)
注销的真确方法是按下ctrl-d, 而不是命令。这样通知shell,输入终止了。
实际上,可以同过关闭终端,但这样是否真正注销了,则取决于不同的系统。

1.1.10 邮件 (mail)
系统提供了一套邮件系统,用于与其他用户通信,所以有时在登录时,在第一个提示前出现提示信息;you have a mail。
要阅读邮件,请键入;
mail
消息会打印出来
看下一封:n
查看mail 的所有命令用?或者help 查看mail系统中所有命令;

[wzb@wzb ~]$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/wzb": 1 message 1 new
>N  1 wzb@wzb.cn            Sat Mar  5 13:13  1**89   "sdfs"
& ?
    Mail   Commands
t <message list>                type messages
n                               goto and type next message
e <message list>                edit messages
f <message list>                give head lines of messages
d <message list>                delete messages
s <message list> file           append messages to file
u <message list>                undelete messages
R <message list>                reply to message senders
r <message list>                reply to message senders and all recipients
pre <message list>              make messages go back to /usr/spool/mail
m <user list>                   mail to specific users
q                               quit, saving unresolved messages in mbox
x                               quit, do not remove system mailbox
h                               print out active message headers
!                               shell escape
cd [directory]                  chdir to directory or home if none given

A <message list> consists of integers, ranges of same, or user names separated
by spaces.  If omitted, Mail uses the last message typed.

A <user list> consists of user names or aliases separated by spaces.
Aliases are defined in .mailrc in your home directory.
& h
>N  1 wzb@wzb.cn            Sat Mar  5 13:13  1**89   "sdfs"
& help
    Mail   Commands
t <message list>                type messages
n                               goto and type next message
e <message list>                edit messages
f <message list>                give head lines of messages
d <message list>                delete messages
s <message list> file           append messages to file
u <message list>                undelete messages
R <message list>                reply to message senders
r <message list>                reply to message senders and all recipients
pre <message list>              make messages go back to /usr/spool/mail
m <user list>                   mail to specific users
q                               quit, saving unresolved messages in mbox
x                               quit, do not remove system mailbox
h                               print out active message headers
!                               shell escape
cd [directory]                  chdir to directory or home if none given

A <message list> consists of integers, ranges of same, or user names separated
by spaces.  If omitted, Mail uses the last message typed.

A <user list> consists of user names or aliases separated by spaces.
Aliases are defined in .mailrc in your home directory.
&
给 earl 发邮件
 mail earl

接着键入邮件的文本
ctrl-d #结束邮件的输入,表示邮件的输入结束,到了邮件的结尾。

1.1.11 用户间的通信
message from marry tty?

$write marry

write 命令没有规则,所以要有一个协议,以免无法去区分,两人的对话。通常的做法是一方以(O)结束,而另一方以(oo)结束,这样就可以加以区分双方的对话了

退出write用ctrl-d,或者delete键

如果写给某个未登录的人,后者收件人不想被打扰,系统会通知你。
如果目标登录了,但是在一个间隔后没有回答,也许对方太忙或者不在终端旁,只要按ctrl-d或者delete键就可以退出了。如果不想被打扰,可利用mesg(1); 

1.1.12 新闻
news


1.1.13 unix程序员手册

 第一节:介绍命令
 第二节:系统调用
 第六节:关于游戏的内容
 其余章节:C程序员使用的函数、文件格式等,以及系统维护的

联机文档,帮助手册 manual: 用man查看
如:
man who
man man

1.1.14 计算机辅助教学
系统中的learn命令,这个命令提供了有关文件系统,基本命令、编辑器、文档准备,甚至包括C语言程序设计的计算机辅助教学。
$learn

$teach

//linux 下测试,不支持者两个命令

1.1.15游戏
游戏往往不被正式承认,但是熟悉计算机和终端的最好方式之一,就是玩游戏。unix系统中提供了适量的游戏。
通常本机上就有,问问周围的人,后者查看手册的第六节。





 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值