Shell命令ls、passwd、cd、type、which、printenv、date、cal

Linux的基本原则:
1、由目的单一的小程序组成:组合小程序完成复杂任务
2、一切皆文件
3、尽量避免捕获用户接口
4、配置文件保存为纯文本格式
GUI接口:
双击鼠标
CLI接口:
命令提示符,prompt,bash(shell)
#:root
$:普通用户
命令:命令会被shell送给内核,又内核判断是否具有执行权限以及能否执行,从什么地方开始执行。
[root@Smoke ~]# lss(通过shell返回的错误信息)
-bash: lss: command not found
命令格式:
命令 选项 参数
选项:修改命令的执行方式,选项可以有多个
短选项:一个横杠"-"引导跟一个字符,-character,多个选项彼此可以组合。
例如:-a -b = -ab
长选项:两个横线"--"引导跟一个单词,--word,长选项通常不能组合,必须要分开来写。
参数:命令的作用对象,这个命令对谁生效,可以跟多个参数,多个参数彼此用空格隔开。

[root@Smoke ~]# ls(不带选项)
anaconda-ks.cfg                              pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
cacti-0.8.8b.tar.gz                          Pictures
[root@Smoke ~]# ls -l(-l选项详细信息)
总用量 310680
-rw-------.  1 root root      1394 4月  14 08:38 anaconda-ks.cfg
-rw-r--r--   1 root root   2272130 5月  14 20:14 cacti-0.8.8b.tar.gz
drwxr-xr-x.  2 root root      4096 4月  15 21:27 Desktop
drwxr-xr-x.  2 root root      4096 4月  15 21:27 Documents
[root@Smoke ~]# ls -a(-a查看全部)
.                            .gnote                                       Pictures
..                           .gnupg                                       Public
.abrt                        .gstreamer-0.10                              .pulse
anaconda-ks.cfg              .gtk-bookmarks                               .pulse-cookie
[root@Smoke ~]# ls -a -l(多个选项,-a显示所有,-l详细信息)
总用量 310848
dr-xr-x---. 31 root root      4096 5月  31 23:30 .
dr-xr-xr-x. 26 root root      4096 5月  21 20:43 ..
drwxr-xr-x.  3 root root      4096 4月  15 21:55 .abrt
-rw-------.  1 root root      1394 4月  14 08:38 anaconda-ks.cfg
[root@Smoke ~]# ls -al(多个选项组合使用)
总用量 310848
dr-xr-x---. 31 root root      4096 5月  31 23:30 .
dr-xr-xr-x. 26 root root      4096 5月  21 20:43 ..
drwxr-xr-x.  3 root root      4096 4月  15 21:55 .abrt
-rw-------.  1 root root      1394 4月  14 08:38 anaconda-ks.cfg
[root@Smoke ~]# ls /etc/(命令加参数,不带参数显示当前目录)
abrt                     enscript.cfg      ld.so.cache       pinforc
[root@Smoke ~]# ls /root /var(命令跟多个参数使用)
/root:
anaconda-ks.cfg                              pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
cacti-0.8.8b.tar.gz                          Pictures
/var:
account  crash  db     ftp  

如何实现用户登录和切换:
使用凭证:验证使用者身份。
Linux严格区分大小写。
Smoke login:root(没登陆时,登录提示符)
Password:
[root@Smoke ~]#(命令提示符)
虚拟终端(terminal):
CTRL+ALT+F1-F6:默认6个终端。
[root@Smoke ~]# startx &(启动图形界面,&表示程序在后台运行)
图形终端:CTRL+ALT+F7
模拟终端:在图形界面想执行命令点击鼠标"右键"选择"Open Terminal"可以打开一个终端。
或者通过菜单栏选择"Applications"-->"Accessonries"-->"Terminal"打开模拟终端。
GUI类型:
1、Gnome:C开发
2、KDE:C++开发
3、Xface:简介轻量式嵌入式桌面
CLI:让用户通过输入命令,将命令结果取回到当前屏幕上来的一个用户接口,或人机交互接口。
sh1、bash:用的最广泛,功能最强大开源shell
2、csh
3、zsh
4、ksh
5、tcsh
只要跟shell相关的程序,只要shell关了,程序也会关闭。
切换用户:
假如:装完系统有三个用户root,student,vistor怎么完成用户切换。
su:Switch User切换用户。
# su [-l] 用户名:中括号[]表示可省略,
Linux另一个哲学思想能简写决不全写。

[root@Smoke ~]# su student(切换到student用户,半切换,有root)
[student@Smoke root]$ exit(退回原来的位置)
exit
[root@Smoke ~]# su -l student(切换到student用户,-l完全切换,没有root)
[student@Smoke ~]$
[student@Smoke ~]$ exit(退出用户)
logout

更换密码:
# passwd:用于修改当前用户密码,对于管理员可以随意改成其他密码,对于普通用户默认策略必须要符合密码复杂性规则。
密码复杂性规则:
1、使用4种类别字符中至少3种;
2、足够长,大于7位;
3、使用随机字符串;
4、要定义更换;
5、循环周期要足够大;

[root@Smoke ~]# passwd(更改当前用户密码)
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.

Shelll:
GUI:Graphic User Interface图形用户界面
Windows:windows在2008之前桌面直接内置在内核中的,不用桌面就无法使用winodws。
X-Window:X指它的协议,图形显示协议,超级的意思,Linux的桌面仅仅是一个外围软件而已,X-Windows是C/S架构的,当前主机装的是系统,另外一台显示器拿来做显示图形界面也完全是可以的,主机和显示器完全是可以分离的,只不过显示那端叫Server,请求显示那端叫Client。
1、Gnome
2、KDE
3、Xface
CLI:Command Line Interface命令行接口
1、sh
2、bash
3、csh
4、ksh
5、zsh
6、tcsh
操作系统组成结构:
最底层是硬件,硬件资源是独有的,在单颗CPU系统平台上,为了能够实现在同一个计算机上同时近似的运行多个程序,有了通用管理软件叫Kernel(内核),内核只是个平台,它不提供特定的任务,仅仅将硬件所提供的计算能力抽象出来并提供给上层其他软件,只不过它的提供方式叫做System call(系统调用),系统调用过于底层,所以使得程序员开发程序非常麻烦的,因此就有了库,库就是将一个或多个系统调用的功能封装起来做成更高级的调用接口,库是一个可执行程序,但是它却无法独立执行,必须被调用以后才能执行,在库的上面就是各种应用程序,这些应用程序根据自己的需要是各种各样的,比如shell是独特的用户界面,也有可能是web服务器,也有可能是IDE(开发环境)。
IDE:程序员在开发的时候所用到的开发环境。
Winodws系统的windows目录很多的.dll文件就是windows的动态连接库文件。
DLL:Dynamic Link Library动态链接库。
Linux系统上的库文件是.so结尾叫共享对象。
so:shared object共享对象。
dso:Dynamic shared object动态共享对象。
做一个操作系统:
需要提供一个内核,提供一些库,或提供运行软件,根据软件依赖那些库,将这些库也提供好,还需要提供一个shell。
一个linux可以做成2-3M的样子,内核1M,库1M,shell1M。
login:(验证用户身份)
用户名:用户ID(用户标识符)
计算机识别最快的不是字符而是数字。
每个用户名都有ID的,用户名是公开的,用户名不能用作限定用户是否能够访问资源的认证标识。
认证机制(Authentication):
认证的过程就是鉴别用户或某个人就是它所声称那个人的过程。
认证并不代表全部,认证完成以后还需要资源访问的授权。
授权(Authorization):
审计(Audition):日志
Smoke login:root
Password:
[root@Smoke ~]#
promprt:命令提示符。
命令:即可以是二进制命令也可以是脚本。
magic number:魔数,标识二进制执行格式。
在winodws上执行程序的魔数和在linux上执行程序的魔数是不一样的,它们所理解的二进制格式也是不尽相同的,所以就算两者的库完全一样,在linux上编译的程序未必能在windows上运行。
shebang
#!/bin/bash(指定魔数)
当一个程序被启动的时候,这个程序的执行入口,这个程序被提交给内核,只有内核才能管理进程,当我们在命令提示符键入一个命令,敲回车的时候,这么个程序就会由bash提交给内核,内核接着就去找这个程序执行的魔数,看它是不是一个可执行格式,以及是不是当前内核理解的可执行格式,如果是就执行起来,否则就拒绝运行,当然是不是会真正执行还要取决于权限和各种外围机制。
命令的格式:
# command options... arguments...
选项:修改命令执行特性。
短选项:可以合并
长选项:
参数:指定命令的作用对象,这个命令对谁生效,多个参数使用空格隔开。
在命令当中有些选项是可以带参数的,选项的参数和命令的参数是两码事。
ls:list列表,列出;可以列出所指定目录下的所有子目录或者文件。
文件夹:winodws系统对目录的误导。
目录:目录也是文件,目录并不是文件夹,它仅仅是一个路径映射。
路径:从指令起始点到目的地所经过的位置,路径为了实现层次化文件管理的机制。
文件系统:file system层次化管理文件的机制。
绝对路径:从根开始找到对应文件。
相对路径:相对于当前所处位置的路径。
工作目录:working directory登录系统以后所处的目录。
当前目录:current directory当前所处的位置。
FHS:文件系统层级标准,规定那些目录必须存在,而且这些目录必须放那些文件。

[root@Smoke ~]# ls(列出当前目录文件和子目录)
anaconda-ks.cfg                              nagios-plugins-2.0.1                     rrdtool-1.3.8-7.el6.x86_64.rpm
cacti-0.8.8b.tar.gz

pwd:Printing Working directory显示当前目录。
/:根目录表示,各目录节点间用/隔开。
蓝色:目录。
绿色:有执行权限。
紫色:套接字文件
常用的颜色有6种。

[root@Smoke ~]# pwd(显示当前所处的目录)
/root
[root@Smoke ~]# ls /root/(显示/root目录文件和子目录)
anaconda-ks.cfg                              nagios-plugins-2.0.1                     rrdtool-1.3.8-7.el6.x86_64.rpm
cacti-0.8.8b.tar.gz

ls:list列表,列出;可以列出所指定目录下的所有子目录或者文件。
-l:长格式,显示完整信息,会显示文件很多属性。
文件完整信息解释:
----------:10位,最左侧一位是文件类型,后面9位表示权限,每3位一组,每一组里面有:rwx(读写执行),如果没有对应权限横杠-表示。
文件类型:
-:普通文件(f)
d:目录文件
b:块设备文件(block)
c:字符设备文件(character)
l:符号链接文件(symbolic link file),也叫软连接。
p:命名管道文件(pipe)
s:套接字文件(socket)
rwx:写,写执行。
r--:能读,不能写不能执行。
文件硬连接的次数:
权限后面的数字表示文件硬链接的次数。
文件的属主(owner)
文件的属组(group)
文件大小(size):默认单位字节。
时间戳(timestamp):这里显示最近一次被修改的时间,每隔文件都有三个时间戳,包括最近一次被访问的时间,最近一次被修改的时间,最近一次被改变的时间。
访问:access读
修改:modify改变了文件的内容。
改变:change改变了文件的属性或元数据。
一个文件有两种数据,一种是文件自身的数据,另外一种是文件的属性数据,属性数据也叫元数据,
元数据:metadata
文件名:
-h:做单位转换。
-a:all显示所有文件,linux以.开头表示隐藏文件。
.:蓝色,代表目录,表示当前目录
..:蓝色,代表目录,表示当前目录的上一级目录,父目录。
-A:显示所有文件,但不包括当.前目录和..上级目录。
-d:显示目录自身属性。
计算机识别用户是通过数字来识别的,文件名也是如此,每一个文件都有一个唯一的数字标识符,这叫文件的inode(文件的索引节点)
inode:index node,
-i:显示文件索引节点号。
使用ls查看目录下的文件及子目录,文件及子目录的名称是通过字母表排序的,而且是升序排序的。
-r:逆序显示文件排序。
-R:递归(recursive)显示,比较消耗资源。

[root@Smoke ~]# ls -l(显示当前目录文件子目录完整信息,-l显示完整信息)
total 310680
-rw-------.  1 root root      1394 Apr 14 08:38 anaconda-ks.cfg(普通文件)
-rw-r--r--   1 root root   2272130 May 14 20:14 cacti-0.8.8b.tar.gz
drwxr-xr-x.  2 root root      4096 Apr 15 21:27 Desktop(目录文件)
drwxr-xr-x.  2 root root      4096 Apr 15 21:27 Documents
[root@Smoke ~]# ls(list列表,列出;可以列出所指定目录下的所有子目录或者文件)
anaconda-ks.cfg                              nagios-plugins-2.0.1                     rrdtool-1.3.8-7.el6.x86_64.rpm
cacti-0.8.8b.tar.gz    
[root@Smoke ~]# ls -l /dev/(查看/dev目录下的文件和子目录完整信息,-l长格式,显示完整信息,会显示文件很多属性)
total 0
crw-rw---- 1 root video    10, 175 May 21 20:43 agpgart(字符设备文件)
crw-rw---- 1 root root     10,  56 May 21 20:44 autofs
lrwxrwxrwx 1 root root           3 May 21 20:43 cdrom -> sr0(符号连接文件)
lrwxrwxrwx 1 root root           3 May 21 20:43 cdrw -> sr0
[root@Smoke ~]# ifconfig(查看主机地址)
eth0      Link encap:Ethernet  HWaddr 00:50:56:3A:91:69  
         inet addr:172.16.100.1  Bcast:172.16.100.255  Mask:255.255.255.0
         inet6 addr: fe80::250:56ff:fe3a:9169/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:40 errors:0 dropped:0 overruns:0 frame:0
         TX packets:47 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:4557 (4.4 KiB)  TX bytes:5770 (5.6 KiB)
lo        Link encap:Local Loopback  
         inet addr:127.0.0.1  Mask:255.0.0.0
         inet6 addr: ::1/128 Scope:Host
         UP LOOPBACK RUNNING  MTU:16436  Metric:1
         RX packets:868 errors:0 dropped:0 overruns:0 frame:0
         TX packets:868 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:57236 (55.8 KiB)  TX bytes:57236 (55.8 KiB)

使用Xshell 4登录Linux系统:

Xshell:\> ping 172.16.100.1(测试能否ping通linux系统)
正在 Ping 172.16.100.1 具有 32 字节的数据:
来自 172.16.100.1 的回复: 字节=32 时间<1ms TTL=64
来自 172.16.100.1 的回复: 字节=32 时间<1ms TTL=64
172.16.100.1 的 Ping 统计信息:
   数据包: 已发送 = 2,已接收 = 2,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
   最短 = 0ms,最长 = 0ms,平均 = 0ms
Xshell:\> ssh 172.16.100.1(使用ssh连接linux主机)
[root@Smoke ~]# ls -l /tmp/(查看/tmp目录下文件及子目录完整信息)
total 44
-rw-------  1(文件硬连接次数) root(所有者)  root  18009 May 29 19:44 yum_save_tx-2014-05-29-19-44KIYaTb.yumtx(能读能写不能执行)
drwx------. 2 Smoke Smoke  4096 Apr 14 01:19 pulse-8G34pGhBrYlR
drwxr-xr-x  2 root  root   4096 May 29 19:39 puppet
srwxr-xr-x  1 root  root      0 May 18 02:43 mapping-root(套接字文件)
[root@Smoke ~]# ls -l -h(查看当前目录文件及子目录完整信息并做单位换算,-l显示完整信息,-h单位换算)
total 304M
-rw-------.  1 root root 1.4K Apr 14 08:38 anaconda-ks.cfg
-rw-r--r--   1 root root 2.2M May 14 20:14 cacti-0.8.8b.tar.gz
drwxr-xr-x.  2 root root 4.0K Apr 15 21:27 Desktop
drwxr-xr-x.  2 root root 4.0K Apr 15 21:27 Documents
[root@Smoke ~]# ls -lh(查看当前目录文件及子目录完整信息并做单位换算,-l显示完整信息,-h单位换算,组合选项)
total 304M
-rw-------.  1 root root 1.4K Apr 14 08:38 anaconda-ks.cfg
-rw-r--r--   1 root root 2.2M May 14 20:14 cacti-0.8.8b.tar.gz
drwxr-xr-x.  2 root root 4.0K Apr 15 21:27 Desktop
drwxr-xr-x.  2 root root 4.0K Apr 15 21:27 Documents
[root@Smoke ~]# ls -a(显示当前目录的文件及子目录所有文件包括隐藏文件,-a代表all显示所有)
.                            .lftp
..                           .local
[root@Smoke ~]# ls .(显示当前目录文件及子目录)
anaconda-ks.cfg                              pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
cacti-0.8.8b.tar.gz                          Pictures
[root@Smoke ~]# ls ..(显示上一级目录的文件及子目录)
bin   dev  home  lib64       media  mnt  opt   root  selinux  srv  tmp  var
boot  etc  lib   lost+found  misc   net  proc  sbin  shared   sys  usr
[root@Smoke ~]# ls -A(选项-A显示所有文件,但不包括当.前目录和..上级目录)
.abrt                        .local
anaconda-ks.cfg              .mozilla
[root@Smoke ~]# ls -ld /root/(显示目录自身完整信息属性,-l显示完整信息,-d显示目录自身)
dr-xr-x---. 31 root root 4096 Jun  1 14:43 /root/
[root@Smoke ~]# ls -i(显示当前目录的文件及子目录的索引节点号,-i显示索引节点号)
793872 anaconda-ks.cfg                              786737 pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
793444 cacti-0.8.8b.tar.gz                          790976 Pictures
[root@Smoke ~]# ls -R(递归显示当前目录下的文件及子目录及子子目录文件,-R递归显示)
.:
anaconda-ks.cfg
cacti-0.8.8b.tar.gz
Desktop
[root@Smoke ~]# ls -r(逆序排列显示当前目录下的子目录及文件,-r逆序显示)
vmware-tools-distrib                     nrpe-2.15.tar.gz
Videos                                   nrpe-2.15

cd:change directory切换当前工作目录。
cd:不加任何参数,回到用户的家目录。
家目录,主目录,home directory
对于自己的家目录用户有所有的操作权限,每个用户的家在bash当中都使用~波浪线表示。
cd ~:回到用户自己的家目录。
cd ~USERNAME:切换到指定用户的家目录,只有管理员才有权限进别的家。
cd -:在当前目录和前一次所在的目录之间来回切换。

[root@Smoke ~]# pwd(显示当前所处目录,在/root目录)
/root
[root@Smoke ~]# cd /usr/(切换到/usr目录)
[root@Smoke usr]# pwd(显示当前所在目录,在/usr目录)
/usr
[root@Smoke usr]# cd(cd不跟任何参数切换到用户家目录)
[root@Smoke ~]#
[root@Smoke ~]# cd /usr/(切换到/usr目录)
[root@Smoke usr]# cd ~(cd加参数~波浪线回到用户家目录)
[root@Smoke ~]#
[root@Smoke ~]# cd ~student(cd加参数~用户名,切换到响应用户的家目录)
[root@Smoke student]# pwd(显示当前所在的目录,在/home/student)
/home/student
[root@Smoke student]# cd(cd不跟任何参数切换到用户家目录)
[root@Smoke ~]# cd -(cd加参数-,在前一个目录和当前目录进行来回切换)
/home/student

命令类型:
内置命令:shell内置命令,内部,内建命令;我们登录系统以后默认给我们一个登录提示符,表示我们已经启动了shell,这个shell为了完成一些自身自我管理,就必须要内置一些基本命令。
外部命令:在文件系统的某个路径下有一个与命令名称相应的可执行文件
cd is a shell builtin:shell内建,内部命令。
which:查看命令文件所在目录。
type:显示指定命令属于哪种类型

[root@Smoke ~]# type cd
cd is a shell builtin(shell内建,内部命令)
[root@Smoke ~]# type ls
ls is aliased to `ls --color=auto'(外部命令)
[root@Smoke ~]# type su
su is /bin/su(外部命令)
[root@Smoke ~]# which ls(查看命令文件所在目录)
alias ls='ls --color=auto'
       /bin/ls

当我们执行一个命令,并没有告诉它执行那个路径的下的什么命令,它是如何知道的,系统怎么能找到这个命令,按道理来讲我们引用任何一个文件都必须给它一个全路径,系统为了能够让用户能够便捷在命令提示符下执行命令,它给我们内置了一种机制,这种机制是通过一个叫环境变量方式来实现的。
变量:
环境变量:命名的内存空间,在内存中划分一段空间给它起个名字,我就可以向起了名的内存空间放数据了,用户定义当前用户的工作环境属性。
变量赋值:放数据的过程,名称只在当前程序中有用,变量既可以申请使用,还可以释放。
NAME=jerry:等号=表示赋值。
声明变量的过程:程序告诉操作系统给我一段内存,我等会要放数据,申请内存使用的过程。
堆栈:在编程当中堆叫做heap,栈叫做stack,它们用来放各自不同类型的数据,比如在栈当中通常本地生成一些变量和静态变量等等,而其他用户获取申请保存数据不是变量需要申请一段空间保存数据,这个通常是堆,所以它们是两种申请内存空间的不同机制,而且在地址空间中也是不同的。
无论是哪一种shell都有自己的环境变;
PATH:一堆使用冒号分隔的路径,冒号隔开的次序很关键。
PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
当我们执行一个命令它会按次序从这些指定路径下一个一个找,直到第一次找到为止,如果两个地方都有相同的命令比如ls,这两个命令所在的路径在PATH中那个路径在前面以那个为准。
如果要执行很多的命令,但是每次都要查找一遍,虽然计算机执行速度很快,但是每次都找也很慢,在系统上有成千上万个命令,如果某个命令第一次执行的时候,它一定是实时去找的,如果找着了,第二次再执行同一个命令就不找了,会有一个缓存,在内存当中找一个地方将对应的命令和目录缓存下来,bash有个缓存,在缓存当中记录下来了此前用过的所有命令的路径,并且再以后使用不会再去找,而是先去找缓存。
hash:查看命令缓存。
如果缓存下来如果内容非常多的话,找缓存的速度就一定比找文件的速度快吗,缓存在这里保存的是一个hash(哈希)列表,哈希是一个key value(建值段),是一个建值数据库,在建值库当中查找内容的速度是O(1)的。
O(1):衡量程序执行速度标准,我们从一个列表中查找一个数据的速度随着列表长度变化而发生变化的比例,O(1)表示无论这个队列有多长,我从中找一个内容的时间是一样的。
如果我们开发一个程序放在某个路径下,而那个路径不再PATH=路径当中,如果执行不跟路径是不能执行的,所以我们的命令只要不带路径,就必须是PATH=指定路径下的命令,要么给它一个完整路径,要么把路径加到PATH=路径里面来。

[root@Smoke ~]# /bin/ls(全路径执行ls命令)
anaconda-ks.cfg                                     pam_mysql-0.7-0.12.rc1.el6.x86_64.rpm
cacti-0.8.8b.tar.gz                             Pictures
[root@Smoke ~]# clear(清屏)
[root@Smoke ~]# clear
[root@Smoke ~]# printenv(显示环境)
HOSTNAME=Smoke(主机名)
TERM=xterm(终端类型)
SHELL=/bin/bash(使用的shell类型)
HISTSIZE=1000
SSH_CLIENT=172.16.100.254 3901 22
QTDIR=/usr/lib64/qt-3.3
QTINC=/usr/lib64/qt-3.3/include
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
QTLIB=/usr/lib64/qt-3.3/lib
CVS_RSH=ssh
SSH_CONNECTION=172.16.100.254 3901 172.16.100.1 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
DISPLAY=localhost:10.0
G_BROKEN_FILENAMES=1
_=/usr/bin/printenv
OLDPWD=/home/student
[root@Smoke ~]# hash(缓存的命令,hits代表命中多少次,使用多少次。)
hits        command
  4        /bin/touch
  1        /usr/bin/printenv
 13        /bin/ls
  1        /usr/bin/clear

显示系统时间:
date:时间管理,系统时间而非硬件时间,不带任何选项查看当前系统时间。
Linux:rtc实时时钟
ntp:网络时间协议。
linux在开机的时候他会通过rtc读取当前时间,一旦读取成功了,就不再使用那个时间了,以后我们内核自身会通过软件的方式模拟振荡器在系统内部来维持一个时钟,只要我们操作系统在运行当中内核在CPU作用下就会自动进行计时的。
硬件时钟:
系统时钟:
clock:硬件时间,不带任何参数查看当前硬件时间。
hwclock:硬件时间。不带任何参数查看当前硬件时间。
练习:
使用date单独获取系统当前的年份、月份、日、小时、分钟、秒

[root@Smoke ~]# date(显示系统时间)
Sun Jun  1 20:07:38 CST 2014
[root@Smoke ~]# clock(显示硬件时间)
Sun 01 Jun 2014 08:19:14 PM CST  -0.393199 seconds
[root@Smoke ~]# hwclock(显示硬件时间)
Sun 01 Jun 2014 08:19:51 PM CST  -0.535787 seconds

如何获得命令的使用帮助:
内部命令:
help COMMAND:获取内部命令的帮助。
外部命令:
COMMAND --help:获得外部命令的帮助。
命令手册:manual
man COMMAND:不管内部命令还是外部命令都有公用的使用方式man帮助。
注意:内部命令man帮助,man的不是这个命令,而是这个命令所属的shell,内部命令一般不会使用man帮助。
man分章节:显示(1)表示第一章节,man常见的章节有8种。
1:用户命令(/bin, /usr/bin, /usr/local/bin):表示所有用户都可以使用的命令,包括普通用户也是。
2:系统调用
3:库调用:并非所有命令都有库调用,只有库才有库调用,如果碰巧一个命令和库的名字相同,他俩才会同时出现。
4:特殊文件(设备文件):设备文件都是特殊文件,它在磁盘上真正的数据区域没有存储任何内容,它只是作为设备的访问入口存在的。
5:文件格式(配置文件的语法):很多的命令为了定义它的执行特性可以使用选项,有些命令它的选项可能不需要用户每一次都指定,或者这个命令希望开机就能自动启动,对于非常复杂的执行文件,它通常都有一个配置文件的文件,在这个配置文件中保存了以往可以通过选项指定了程序执行特性,所以这个配置文件都类似于变量,都是什么=什么的方式定义这个程序的执行属性,解释某个命令对应的配置文件语法。
6:游戏
7:杂项(Miscellaneous):不便归类的杂项。
8: 管理命令(/sbin, /usr/sbin, /usr/local/sbin):只有管理员才能使用的命令,会修改硬件参数及系统级别参数。
man NUMBERS COMMAND:如果一个命令在多个章节都有,指定显示命令第几章节内容,如果不指定的章节显示1-7往过排,那一个先出现显示那一个。
whatis COMMAND:显示命令的摘要信息,以及出现在man帮助那些章节。
跟用户帐号相关的两个文件:
/etc/passwd
/etc/shadow
这两个跟我们的命令是一个名字,所以这个文件是有格式的。
man对命令的描述:
<>:必选
[]:可选
...:可以出现多次
|:多选一
{}:分组
MAN:
NAME:命令名称及功能简要说明
SYNOPSIS:用法说明,包括可用的选项
DESCRIPTION:命令功能的详尽说明,可能包括每一个选项的意义
OPTIONS:说明每一个选项的意义
FILES:此命令相关的配置文件
BUGS:
EXAMPLES:使用示例
SEE ALSO:另外参照
翻屏:
向后翻一屏:SPACE
向前翻一屏:b
向后翻一行:ENTER或j
向前翻一行:k
查找:
/KEYWORD: 向后查找
n: 下一个
N:前一个
?KEYWORD:向前查找
n: 下一个
N:前一个
q: 退出
在线文档:
info COMMAND:获取命令信息
PageUP:向上翻译
PageDown:上下翻译
文档:/usr/share/doc:几乎所有的命令文档都有
google搜索
apache, hadoop官方手册

[root@Smoke ~]# help cd(查看内部命令cd的帮助)
cd: cd [-L|-P] [dir]
   Change the shell working directory.
   Options:
       -L        force symbolic links to be followed
       -P        use the physical directory structure without following symbolic
           links

   The default is to follow symbolic links, as if `-L' were specified.

   Exit Status:
   Returns 0 if the directory is changed; non-zero otherwise.
[root@Smoke ~]# ls --help(查看外部命令ls的使用帮助)
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
 -a, --all                  do not ignore entries starting with .
 -A, --almost-all           do not list implied . and ..
     --author               with -l, print the author of each file
 -b, --escape               print octal escapes for nongraphic characters
     --block-size=SIZE      use SIZE-byte blocks.  See SIZE format below
 -B, --ignore-backups       do not list implied entries ending with ~
 -c                         with -lt: sort by, and show, ctime (time of last
                              modification of file status information)
                              with -l: show ctime and sort by name
                              otherwise: sort by ctime
 -C                         list entries by columns
     --color[=WHEN]         colorize the output.  WHEN defaults to `always'
                              or can be `never' or `auto'.  More info below
 -d, --directory            list directory entries instead of contents,
                              and do not dereference symbolic links
 -D, --dired                generate output designed for Emacs' dired mode
 -f                         do not sort, enable -aU, disable -ls --color
 -F, --classify             append indicator (one of */=>@|) to entries
     --file-type            likewise, except do not append `*'
     --format=WORD          across -x, commas -m, horizontal -x, long -l,
                              single-column -1, verbose -l, vertical -C
     --full-time            like -l --time-style=full-iso
 -g                         like -l, but do not list owner
     --group-directories-first
                            group directories before files.
                              augment with a --sort option, but any
                              use of --sort=none (-U) disables grouping
 -G, --no-group             in a long listing, don't print group names
 -h, --human-readable       with -l, print sizes in human readable format
                              (e.g., 1K 234M 2G)
     --si                   likewise, but use powers of 1000 not 1024
 -H, --dereference-command-line
                            follow symbolic links listed on the command line
     --dereference-command-line-symlink-to-dir
                            follow each command line symbolic link
                            that points to a directory
     --hide=PATTERN         do not list implied entries matching shell PATTERN
                              (overridden by -a or -A)
     --indicator-style=WORD  append indicator with style WORD to entry names:
                              none (default), slash (-p),
                              file-type (--file-type), classify (-F)
 -i, --inode                print the index number of each file
 -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
 -k                         like --block-size=1K
 -l                         use a long listing format
 -L, --dereference          when showing file information for a symbolic
                              link, show information for the file the link
                              references rather than for the link itself
 -m                         fill width with a comma separated list of entries
 -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
 -N, --literal              print raw entry names (don't treat e.g. control
                              characters specially)
 -o                         like -l, but do not list group information
 -p, --indicator-style=slash
                            append / indicator to directories
 -q, --hide-control-chars   print ? instead of non graphic characters
     --show-control-chars   show non graphic characters as-is (default
                            unless program is `ls' and output is a terminal)
 -Q, --quote-name           enclose entry names in double quotes
     --quoting-style=WORD   use quoting style WORD for entry names:
                              literal, locale, shell, shell-always, c, escape
 -r, --reverse              reverse order while sorting
 -R, --recursive            list subdirectories recursively
 -s, --size                 print the allocated size of each file, in blocks
 -S                         sort by file size
     --sort=WORD            sort by WORD instead of name: none -U,
                            extension -X, size -S, time -t, version -v
     --time=WORD            with -l, show time as WORD instead of modification
                            time: atime -u, access -u, use -u, ctime -c,
                            or status -c; use specified time as sort key
                            if --sort=time
     --time-style=STYLE     with -l, show times using style STYLE:
                            full-iso, long-iso, iso, locale, +FORMAT.
                            FORMAT is interpreted like `date'; if FORMAT is
                            FORMAT1<newline>FORMAT2, FORMAT1 applies to
                            non-recent files and FORMAT2 to recent files;
                            if STYLE is prefixed with `posix-', STYLE
                            takes effect only outside the POSIX locale
 -t                         sort by modification time
 -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
 -u                         with -lt: sort by, and show, access time
                              with -l: show access time and sort by name
                              otherwise: sort by access time
 -U                         do not sort; list entries in directory order
 -v                         natural sort of (version) numbers within text
 -w, --width=COLS           assume screen width instead of current value
 -x                         list entries by lines instead of by columns
 -X                         sort alphabetically by entry extension
 -1                         list one file per line
SELinux options:
 --lcontext                 Display security context.   Enable -l. Lines
                            will probably be too wide for most displays.
 -Z, --context              Display security context so it fits on most
                            displays.  Displays only mode, user, group,
                            security context and file name.
 --scontext                 Display only security context and file name.
     --help     display this help and exit
     --version  output version information and exit
SIZE may be (or may be an integer optionally followed by) one of following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
Using color to distinguish file types is disabled both by default and
with --color=never.  With --color=auto, ls emits color codes only when
standard output is connected to a terminal.  The LS_COLORS environment
variable can change the settings.  Use the dircolors command to set it.
Exit status:
0  if OK,
1  if minor problems (e.g., cannot access subdirectory),
2  if serious trouble (e.g., cannot access command-line argument).
[root@Smoke ~]# man ls(查看ls命令的使用手册)
LS(1)                            User Commands                           LS(1)
NAME(命令名字)
      ls - list directory contents(简要功能说明)
SYNOPSIS(使用格式说明)
      ls [OPTION]... [FILE]...
DESCRIPTION(使用描述)
      List  information  about  the  FILEs  (the  current directory by default).  Sort entries
      alphabetically if none of -cftuvSUX nor --sort.
      Mandatory arguments to long options are mandatory for short options too.
      -a, --all
             do not ignore entries starting with .
      -A, --almost-all
             do not list implied . and ..
      --author
             with -l, print the author of each file
      -b, --escape
             print octal escapes for nongraphic characters
      --block-size=SIZE
             use SIZE-byte blocks.  See SIZE format below
      -B, --ignore-backups
             do not list implied entries ending with ~
      -c     with -lt: sort by, and show, ctime (time of  last  modification  of  file  status
             information) with -l: show ctime and sort by name otherwise: sort by ctime
      -C     list entries by columns
      --color[=WHEN]
             colorize  the  output.   WHEN  defaults  to 'always' or can be 'never' or 'auto'.
             More info below
      -d, --directory
             list directory entries instead of contents, and do not dereference symbolic links
      -D, --dired
             generate output designed for Emacs' dired mode
      -f     do not sort, enable -aU, disable -ls --color
      -F, --classify
             append indicator (one of */=>@|) to entries
      --file-type
             likewise, except do not append '*'
      --format=WORD
             across  -x, commas -m, horizontal -x, long -l, single-column -1, verbose -l, ver-
             tical -C
      --full-time
             like -l --time-style=full-iso
      -g     like -l, but do not list owner
      --group-directories-first
             group directories before files.
             augment with a --sort option, but any use of --sort=none (-U) disables grouping
      -G, --no-group
             in a long listing, don't print group names
      -h, --human-readable
             with -l, print sizes in human readable format (e.g., 1K 234M 2G)
      --si   likewise, but use powers of 1000 not 1024
      -H, --dereference-command-line
             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
             follow each command line symbolic link that points to a directory
      --hide=PATTERN
             do not list implied entries matching shell PATTERN (overridden by -a or -A)
      --indicator-style=WORD
             append indicator with style WORD to entry  names:  none  (default),  slash  (-p),
             file-type (--file-type), classify (-F)
      -i, --inode
             print the index number of each file
      -I, --ignore=PATTERN
             do not list implied entries matching shell PATTERN
      -k     like --block-size=1K
      -l     use a long listing format
      -L, --dereference
             when  showing file information for a symbolic link, show information for the file
             the link references rather than for the link itself
      -m     fill width with a comma separated list of entries
      -n, --numeric-uid-gid
             like -l, but list numeric user and group IDs
      -N, --literal
             print raw entry names (don't treat e.g. control characters specially)
      -o     like -l, but do not list group information
      -p, --indicator-style=slash
             append / indicator to directories
      -q, --hide-control-chars
             print ? instead of non graphic characters
      --show-control-chars
             show non graphic characters as-is (default unless program is 'ls' and output is a
             terminal)
      -Q, --quote-name
             enclose entry names in double quotes
      --quoting-style=WORD
             use  quoting style WORD for entry names: literal, locale, shell, shell-always, c,
             escape
      -r, --reverse
             reverse order while sorting
      -R, --recursive
             list subdirectories recursively
      -s, --size
             print the allocated size of each file, in blocks
      -S     sort by file size
      --sort=WORD
             sort by WORD instead of name: none -U, extension -X, size -S, time -t, version -v
      --time=WORD
             with -l, show time as WORD instead of modification time: atime -u, access -u, use
             -u, ctime -c, or status -c; use specified time as sort key if --sort=time
      --time-style=STYLE
             with -l, show times using style STYLE: full-iso, long-iso, iso, locale,  +FORMAT.
             FORMAT  is interpreted like 'date'; if FORMAT is FORMAT1<newline>FORMAT2, FORMAT1
             applies to non-recent files and FORMAT2 to recent files;  if  STYLE  is  prefixed
             with 'posix-', STYLE takes effect only outside the POSIX locale
      -t     sort by modification time
      -T, --tabsize=COLS
             assume tab stops at each COLS instead of 8
      -u     with  -lt:  sort  by, and show, access time with -l: show access time and sort by
             name otherwise: sort by access time
      -U     do not sort; list entries in directory order
      -v     natural sort of (version) numbers within text
      -w, --width=COLS
             assume screen width instead of current value
      -x     list entries by lines instead of by columns
      -X     sort alphabetically by entry extension
      -1     list one file per line
      SELinux options:
      --lcontext
             Display security context.   Enable -l. Lines will probably be too wide  for  most
             displays.
      -Z, --context
             Display  security context so it fits on most displays.  Displays only mode, user,
             group, security context and file name.
      --scontext
             Display only security context and file name.
      --help display this help and exit
      --version
             output version information and exit
      SIZE may be (or may be an integer optionally followed by) one of following: KB  1000,  K
      1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
      Using   color   to  distinguish  file  types  is  disabled  both  by  default  and  with
      --color=never.  With --color=auto, ls emits color codes only  when  standard  output  is
      connected  to  a  terminal.  The LS_COLORS environment variable can change the settings.
      Use the dircolors command to set it.
  Exit status:
      0      if OK,
      1      if minor problems (e.g., cannot access subdirectory),
      2      if serious trouble (e.g., cannot access command-line argument).
AUTHOR(作者)
      Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS(如果发现命令有BUG将信息发送给谁)
      Report ls bugs to [email protected]
      GNU coreutils home page: < http://www.gnu.org/software/coreutils/ >
      General help using GNU software: < http://www.gnu.org/gethelp/ >
      Report ls translation bugs to < http://translationproject.org/team/ >
COPYRIGHT(版权)
      Copyright 2010 Free Software Foundation(自由软件基金会), Inc.  License GPLv3+: GNU GPL  version  3  or
      later < http://gnu.org/licenses/gpl.html >.
      This  is  free  software:  you are free to change and redistribute it.  There is NO WAR-
      RANTY, to the extent permitted by law.
SEE ALSO(如果想获得进一步信息请查看)
      The full documentation for ls is maintained as a Texinfo manual.  If  the  info  and  ls
      programs are properly installed at your site, the command
             info coreutils 'ls invocation'
      should give you access to the complete manual.
GNU coreutils 8.4                 March 2014                             LS(1)
[root@Smoke ~]# man cd(内部命令man帮助,man的不是这个命令,而是这个命令所属的shell)
BASH_BUILTINS(1)                                              BASH_BUILTINS(1)
NAME
      bash,  :, ., [, alias, bg, bind, break, builtin, caller, cd, command, compgen, complete,
      compopt, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, false,
      fc,  fg,  getopts,  hash,  help, history, jobs, kill, let, local, logout, mapfile, popd,
      printf, pushd, pwd, read, readonly, return, set, shift, shopt,  source,  suspend,  test,
      times,  trap,  true,  type, typeset, ulimit, umask, unalias, unset, wait - bash built-in
      commands, see bash(1)
[root@Smoke ~]# man 2 read(查看read第2章节系统调用章节)
READ(2)                    Linux Programmer's Manual(linux开发人员手册)                   READ(2)
NAME
      read - read from a file descriptor
SYNOPSIS
      #include <unistd.h>(这是一个系统调用)
      ssize_t read(int fd, void *buf, size_t count);
DESCRIPTION
      read() attempts to read up to count bytes from file descriptor fd into the buffer start-
      ing at buf.
      If count is zero, read() returns zero and has no other results.   If  count  is  greater
      than SSIZE_MAX, the result is unspecified.
[root@Smoke ~]# export LANG="en"(修改语言编码方式为english)
[root@Smoke ~]# man mount(查看mount的man帮助在第8章节)
MOUNT(8)                   Linux Programmer's Manual                  MOUNT(8)
NAME
      mount - mount a filesystem
SYNOPSIS
      mount [-lhV]
      mount -a [-fFnrsvw] [-t vfstype] [-O optlist]
      mount [-fnrsvw] [-o option[,option]...]  device|dir
      mount [-fnrsvw] [-t vfstype] [-o options] device dir
[root@Smoke ~]# whatis read(查看read命令man帮助在第几章节)
read                 (1p)  - read a line from standard input
read                 (2)  - read from a file descriptor
read                 (3p)  - read from a file
read [builtins]      (1)  - bash built-in commands, see bash(1)
[root@Smoke ~]# man 4 tty(查看第四章man帮助节特殊文件)
TTY(4)                     Linux Programmer's Manual                    TTY(4)
NAME
      tty - controlling terminal(用于控制终端)
DESCRIPTION
      The file /dev/tty(对应设备文件) is a character(字符文件) file with major number 5(主号码) and minor number 0(次号码), usually of
      mode 0666 and owner.group root.tty.  It is a synonym for the controlling terminal  of  a
      process, if any.
      In  addition  to  the  ioctl(2) requests supported by the device that tty refers to, the
      ioctl(2) request TIOCNOTTY is supported.
[root@Smoke ~]# cat /etc/passwd(查看/etc/passwd文件内容,这个文件是由格式的通过冒号:隔开)
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[root@Smoke ~]# man passwd(显示的是命令的帮助)
PASSWD(1)                       User utilities                       PASSWD(1)
NAME
      passwd - update user's authentication tokens
SYNOPSIS
      passwd  [-k]  [-l] [-u [-f]] [-d] [-e] [-n mindays] [-x maxdays] [-w warndays] [-i inac-
      tivedays] [-S] [--stdin] [username]
[root@Smoke ~]# man 5 passwd(显示passwd每隔冒号是什么意思,在第五章文件格式)
PASSWD(5)                  Linux Programmer's Manual                 PASSWD(5)
NAME
      passwd - password file(用户的密码文件)
[root@Smoke ~]# man man(获得man的man手册)
man(1)                                                                  man(1)
NAME
      man - format and display the on-line manual pages
SYNOPSIS
      man  [-acdfFhkKtwW]  [--path] [-m system] [-p string] [-C config_file] [-M pathlist] [-P
      pager] [-B browser] [-H htmlpager] [-S section_list] [section] name ...
man对命令的描述:
[root@Smoke ~]# man date(查看date命令的man帮助)
DATE(1)                          User Commands                         DATE(1)
NAME
      date - print or set the system date and time
SYNOPSIS
      date [OPTION]... [+FORMAT](中括号[]括起来可省略,...表示可以出现多次,可以有多个选项)
      date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]](中间竖线表示二选一或多选一,只能选择一个不能同时使用)
date:
date - print or set the system date and time
date [OPTION]... [+FORMAT](格式)
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]](修改系统时间,月日小时分钟年.秒)
FORMAT(格式):
%D     date; same as %m/%d/%y(显示月日年)
%y     last two digits of year (00..99)(显示两位年)
%Y     year(显示四位年)
%d     day of month (e.g, 01)(显示一个月的第几天)
%n     a newline(换行)
%T     time; same as %H:%M:%S(显示小时分钟秒)
%F     full date; same as %Y-%m-%d(显示年月日)
%M     minute (00..59)(分钟)
%S     second (00..60)(显示秒)
%s     seconds since 1970-01-01 00:00:00 UTC(时间戳,Unix元年计时法,从1970年01月01日00点00分00秒至此刻为止经过的秒数)
[root@Smoke ~]# date 0601220514.30(更改系统时间为6月1日22点05分14年30秒)
Sun Jun  1 22:05:30 CST 2014
[root@Smoke ~]# date +%D(显示月日年)
06/01/14
[root@Smoke ~]# date +%Y(显示四位年)
2014
[root@Smoke ~]# date +%y(显示两位年)
14
[root@Smoke ~]# date +"This year is %Y"(可以带字符原封不动显示年)
This year is 20
[root@Smoke ~]# date +"This year is %Y."(可以带字符和标点符号原封不动显示年)
This year is 2014.
[root@Smoke ~]# date +%d(显示今天是这个月第几天)
01
[root@Smoke ~]# date +"This year is %Y. Today is %d."(显示年,并显示今天是这个月第几条,加入其他字符标点符号显示)
This year is 2014. Today is 01.
[root@Smoke ~]# date +"This year is %Y. %nToday is %d."显示年,并显示今天是这个月第几条,加入其他字符标点符号显示,并通过%n换行显示)
This year is 2014.
Today is 01.
[root@Smoke ~]# date +%T(显示小时分钟秒)
22:26:14
[root@Smoke ~]# date +%F(显示年月日)
2014-06-01
[root@Smoke ~]# date +%Y-%m-%d(显示年月日,横线-隔开)
2014-06-01
[root@Smoke ~]# date +%H:%M(显示几点几分,冒号:隔开)
22:29
[root@Smoke ~]# date +%H-%M(显示几点几分,横线-隔开)
22-30
[root@Smoke ~]# date +%s(显示时间戳,从1970.01.01.00.00.00到现在经过的秒数)
1401633375

clock:查看硬件时间,等同于hwclock
hwclock:默认显示硬件时间
-w: 将系统时间同步到硬件,改硬件时间
-s: 把硬件时间同步到系统时间,改系统时间
-r:显示硬件时间,可以不加-r。

[root@Smoke ~]# clock(查看硬件时间)
Sun 01 Jun 2014 10:39:07 PM CST  -0.220458 seconds
[root@Smoke ~]# hwclock -w(将系统时间同步到硬件,改硬件时间)
[root@Smoke ~]# clock(查看硬件时间)
Sun 01 Jun 2014 10:41:11 PM CST  -0.127240 seconds
[root@Smoke ~]# date 03151132(更改系统时间为错误时间)
Sat Mar 15 11:32:00 CST 2014
[root@Smoke ~]# hwclock -s(把硬件时间同步到系统时间,改系统时间)
[root@Smoke ~]# date
Sun Jun  1 22:43:11 CST 2014
[root@Smoke ~]# man hwclock(查看hwclock的man文档)
[root@Smoke ~]# hwclock -r(显示硬件时间)
Sun 01 Jun 2014 10:48:40 PM CST  -0.112417 seconds

在线文档:
info COMMAND
翻页:
PageUP:向上翻译
PageDown:上下翻译

[root@Smoke ~]# info ls(查看ls命令的在线文档)
文档:/usr/share/doc:几乎所有的命令文档都有。
[root@Smoke ~]# cd /usr/share/doc/(命令手册文档目录)
[root@Smoke doc]# ls(查看目录下的文件及子目录)
abrt-2.0.8                               libstdc++-devel-4.4.7
abyssinica-fonts-1.0                     libtar-1.2.11
cal: calendar日历
[root@Smoke ~]# cal(查看日历)
     June 2014    
Su Mo Tu We Th Fr Sa
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
[root@Smoke ~]# cal 2013(2013年的年历)
                              2013                              
      January               February                 March      
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
      1  2  3  4  5                   1  2                   1  2
6  7  8  9 10 11 12    3  4  5  6  7  8  9    3  4  5  6  7  8  9
13 14 15 16 17 18 19   10 11 12 13 14 15 16   10 11 12 13 14 15 16
20 21 22 23 24 25 26   17 18 19 20 21 22 23   17 18 19 20 21 22 23
27 28 29 30 31         24 25 26 27 28         24 25 26 27 28 29 30
                                             31
       April                   May                   June        
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
   1  2  3  4  5  6             1  2  3  4                      1
7  8  9 10 11 12 13    5  6  7  8  9 10 11    2  3  4  5  6  7  8
14 15 16 17 18 19 20   12 13 14 15 16 17 18    9 10 11 12 13 14 15
21 22 23 24 25 26 27   19 20 21 22 23 24 25   16 17 18 19 20 21 22
28 29 30               26 27 28 29 30 31      23 24 25 26 27 28 29
                                             30
       July                  August                September    
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
   1  2  3  4  5  6                1  2  3    1  2  3  4  5  6  7
7  8  9 10 11 12 13    4  5  6  7  8  9 10    8  9 10 11 12 13 14
14 15 16 17 18 19 20   11 12 13 14 15 16 17   15 16 17 18 19 20 21
21 22 23 24 25 26 27   18 19 20 21 22 23 24   22 23 24 25 26 27 28
28 29 30 31            25 26 27 28 29 30 31   29 30
      October               November               December      
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
      1  2  3  4  5                   1  2    1  2  3  4  5  6  7
6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14
13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21
20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28
27 28 29 30 31         24 25 26 27 28 29 30   29 30 31
[root@Smoke ~]# cal 12 2012(2012年12月日历)
   December 2012  
Su Mo Tu We Th Fr Sa
                  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、echo是内部命令还是外部命令?

[root@Smoke ~]# type echo(查看echo命令类型,为内部命令)
echo is a shell builtin
2、其作用?
[root@Smoke ~]# help echo(查看echo命令帮助)
[root@Smoke ~]# man echo(查看echo命令man文档)
NAME
      echo - display a line of text(显示一行文本)
SYNOPSIS
      echo [SHORT-OPTION]... [STRING]...
      echo LONG-OPTION
[root@Smoke ~]# echo(打印文本,默认自动换行)

echo默认动作,不管输入什么文本都会打印并进行换行
-n:不换行.

[root@Smoke ~]# echo -n(显示文本不换行)
[root@Smoke ~]# echo "The year is 2013. Today is 26."(显示字符)
The year is 2013. Today is 26.

3、如何显示"The year is 2013. Today is 26."为两行?
-e:开启反斜杠转义
\n:换行
\:显示反斜杠自身
\b:退格键
\t:横向制表符
\v:纵向制表符

[root@Smoke ~]# echo -e "The year is 2013. \nToday is 26."(显示字符串,并通过-e选项开启反斜杠转义\n进行换行)
The year is 2013.
Today is 26.
[root@Smoke ~]# echo -e "The year is 2013.\bToday is 26."(显示字符串,并通过-e选项开启反斜杠转义\b退一格删除.点号)
The year is 2013Today is 26.
[root@Smoke ~]# echo -e "The year is 2013.\b\bToday is 26."(退格两次)
The year is 201Today is 26.
[root@Smoke ~]# echo -e "The year is 2013.\tToday is 26."(显示字符串,并通过-e选项开启反斜杠转义\t横向tab空白)
The year is 2013.        Today is 26.
[root@Smoke ~]# echo -e "The year is 2013.\vToday is 26."."(显示字符串,并通过-e选项开启反斜杠转义\v纵向tab空白)
The year is 2013.
                Today is 26.
[root@Smoke ~]# echo -n "The year is 2013."(显示字符串,-n不换行显示,默认自动换行_
The year is 2013.[root@Smoke ~]#

练习:
1、printf是内部命令还是外部命令?

[root@Smoke ~]# type printf(查看printf命令类型,内部命令)
printf is a shell builtin

2、其作用?
3、如何显示"The year is 2013. Today is 26."为两行?

[root@Smoke ~]# man printf(查看printf命令man文档)
NAME
      printf - format and print data(格式化并显示数据)
SYNOPSIS
      printf FORMAT(格式) [ARGUMENT]...(参数)
      printf OPTION
\n:换行符
[root@Smoke ~]# printf "The year is 2013."(格式化并显示数据,默认不会换行)
The year is 2013.[root@Smoke ~]#
[root@Smoke ~]# printf "The year is 2013.\n"(格式化并显示数据,使用\n换行;默认不会换行)
The year is 2013.
[root@Smoke ~]# printf "The year is 2013.\nToday is 26."(格式化并显示数据,并通过\n将两行字符串换行,但最后一行还没换行)
The year is 2013.
Today is 26.[root@Smoke ~]#
[root@Smoke ~]# printf "The year is 2013.\nToday is 26.\n"(格式化并显示数据,并通过\n将两行字符全部换行)
The year is 2013.
Today is 26.

file命令及其用法:
file命令用来探测给定文件的类型。file命令对文件的检查分为文件系统、魔法幻数检查和语言检查3个过程。
语法
file(选项)(参数)
选项
-b:列出辨识结果时,不显示文件名称; -c:详细显示指令执行过程,便于排错或分析程序执行的情形; -f<名称文件>:指定名称文件,其内容有一个或多个文件名称时,让file依序辨识这些文件,格式为每列一个文件名称; -L:直接显示符号连接所指向的文件类别; -m<魔法数字文件>:指定魔法数字文件; -v:显示版本信息; -z:尝试去解读压缩文件的内容。
参数
文件:要确定类型的文件列表,多个文件之间使用空格分开,可以使用shell通配符匹配多个

[root@localhost ~]# file install.log
install.log: UTF-8 Unicode text
[root@localhost ~]# file -b install.log <== 不显示文件名称
UTF-8 Unicode text
[root@localhost ~]# file -i install.log <== 显示MIME类别。
install.log: text/plain; charset=utf-8
[root@localhost ~]# file -b -i install.log
text/plain; charset=utf-8

猜你喜欢

转载自blog.51cto.com/smoke520/2425429