命令ls、date、cal、mkdir、touch、rm、cp、mv及文件系统详解

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 bug-coreutils@gnu.org
      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
[root@Smoke ~]# man file(查看file命令的man手册)
[root@Smoke ~]# file /root/(查看/root文件类型)
/root/: directory
[root@Smoke ~]# file /bin/ls(查看ls文件类型)
/bin/ls: ELF(可执行文件存储格式) 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
ELF:可执行文件存储格式,可执行的可链接的文件类型,Linux常见的可执行二进制文件格式。
Winodws:PE,可移植可执行文件。
Linux: ELF
[root@Smoke ~]# file /etc/issue(查看issue文件类型)
/etc/issue: ASCII text
[root@Smoke ~]# file /lib64/libc.so.6(查看libc.so.6文件类型)
/lib64/libc.so.6: symbolic link to `libc-2.12.so'
[root@Smoke ~]# file /lib64/libc-2.12.so(查看libc-2.12.so文件类型)
/lib64/libc-2.12.so: ELF 64-bit LSB shared object(可执行的共享对象), x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
文件系统:

文件系统是内核的主要核心功能之一,主要目的就是实现本机上某一个分区上的文件管理,文件系统一般而已对磁盘来说通常指的是以分区为单位进行装饰的,在整个系统上所有的文件系统都必须同属于整个系统级别叫做根,对于linux而言每个文件系统都必须是根文件系统下的某一个路径,或者是必须通过根文件系统才能找到,在每一个路径下还可以有子目录和文件,表现为文件的都是叶子节点,否则就是目录文件,文件分为目录文件,除了目录都是文件,所有的文件都存放在目录当中。
rootfs:根文件系统。
FHS:文件系统层级标准,规定Linux那些目录必须存在,而且这些目录必须放那些文件。

[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
/boot: 系统启动相关的文件,如vmlinuz内核、initrd(内存磁盘),以及grub(bootloader引导加载器)
/dev: 设备文件
       设备文件:
               块设备:随机访问,数据块,例如磁盘、硬盘
               字符设备:线性访问,按字符为单位,如鼠标、显示器
               设备号:主设备号(major)和次设备号(minor)
/etc:配置文件
/home:用户的家目录,每一个用户的家目录通常默认为/home/USERNAME
/root:管理员的家目录;
/lib:库文件
       静态库,  .a
       动态库, .dll(windows), .so(linux) (shared object共享对象)
       /lib/modules:内核模块文件

动态库和静态库区别:
动态库在linux上叫共享库,库就是一些被调用封装好的功能,一旦有这些功能,程序在开发的时候直接调用这个功能,不用再自己的写了,在系统上如何执行,任何程序和数据都必须要载入内存以后才能被程序所使用,共享库的好处就在于,第一个程序启动以后它如果用到某个共享库,它直接把共享库载入到内存就使用了,而启动第二个程序的时候,如果第二个程序也用到这个共享库,它就不需要再载入共享库,因为内存直接有拿来直接用,所以称为共享库,所以这个库文件在内存当中只需要存储一份即可,大大节约内存空间,静态库并非如此,静态库直接链接到程序地址空间中去,而且是作为程序的一部分而运行的,所以静态方式便于程序单个文件管理,要把一个程序从一个linux主机移动到另一个linux主机,如果它是编译时候使用静态编译方式,使用的是静态库文件的话,只需要把文件从A主机复制到B主机就能直接运行的,但是如果要使用动态链接库的方式的话,那就意味着它自己的运行还要依赖库,把程序从A主机移动的B主机,还要保证B主机有它运行时所依赖的共享库。
/lost+found:任何一个新建分区都会有的目录,通常跟文件系统相关,是用于存储那些机器突然断电的时候,文件没有属主属组并且尚未来得及保存的文件,为了实现丢失并能够找回目的。
/media:挂载点目录,移动设备,例如U盘、光盘等
/mnt:挂载点目录,额外的临时文件系统,例如第二块硬盘等
挂载点:必须要将设备关联到当前整个文件系统树上某一个节点上才能进行访问,而这个过程,把某个设备跟当前文件系统上的某一个目录相建立关联关系过程就叫挂载过程。
/misc:杂项,默认空目录,不便归类的文件
/opt:可选目录,早起通常安装第三方程序的安装目录
/proc:伪文件系统,内核映射文件,这个目录在系统不启动通常是空的,启动以后就不空了,因为这里面所显示的文件是内核映射文件
/sys:伪文件系统,跟硬件设备相关的属性映射文件,这个目录在系统不启动通常是空的,启动以后就不空了
/tmp:临时文件, /var/tmp,每隔一个月自动清理一次,每个用户都可以在这个目录创建文件,但是删除只能删自己的
/var:可变化的文件
/bin: 可执行文件, 用户命令
/sbin:管理命令
/usr:shared, read-only(全局共享只读文件)
/usr/bin
/usr/sbin
/usr/lib
/usr/local:(第三方软件安装目录)
/usr/local/bin
/usr/local/sbin
/usr/local/lib
创建文件目录命名规则:
1、长度不能超过255个字符;
2、不能使用/当文件名
3、严格区分大小写
相对路径:相对于当前位置开始的文件查找路径
绝对路径:必须从根开始查找路径
在系统通常工作:
文件管理
目录管理
运行程序
设备管理
软件管理
进程管理
网络管理
目录管理相关功能:
ls
cd
pwd
mkdir:创建空目录。
-p:递归创建,如果所要创建的目录的路径不存在先创建路径上的目录节点。
-v: verbose,详细信息,创建过程。
tree:查看目录树

[root@Smoke ~]# mkdir x(创建目录x)
[root@Smoke ~]# ls
x install.log install.log Desktop anaconda-ks.cfg
[root@Smoke ~]# mkdir x/y(在x目录创建y目录)
[root@Smoke ~]# mkdir x/y/z(在x/y路径下创建z目录)
[root@Smoke ~]# tree x(查看x目录树)
x
└── y
   └── z
2 directories, 0 files
[root@Smoke ~]# mkdir -pv /root/m/n/q(创建q目录,但是/m/n路径节点目录不存在,使用-p递归创建,如果所要创建的目录的路径不存在先创建路径上的目录节点,-v创建过程)
mkdir: created directory `/root/m'
mkdir: created directory `/root/m/n'
mkdir: created directory `/root/m/n/q'
问题1:通过一个命令创建/mnt/test/x/m,y
mkdir -pv /mnt/test/x/m /mnt/test/y(多个参数创建)
mkdir -pv /mnt/test/{x/m,y}(花括号展开创建)

命令行展开:bash的高级特性,当遇见花括号{}的时候,会自动把逗号,分割的路径展开为两个。
~USERNAME:波浪线展开。

[root@Smoke ~]# mkdir /mnt/test/{x/m,y} -pv(通过花括号展开创建/mnt/test/x/m和test/mnt/test/y目录,-p递归创建,如果所要创建的目录的路径不存在先创建路径上的目录节点,-v创建过程)
mkdir: created directory `/mnt/test'
mkdir: created directory `/mnt/test/x'
mkdir: created directory `/mnt/test/x/m'
mkdir: created directory `/mnt/test/y'
问题2:通过一个命令创建/mnt/test2/
a_b, a_c, d_b, d_c
(a+d)(b+c)=ab+ac+db+dc
{a,d}_{b,c}
[root@Smoke ~]# mkdir -pv /mnt/test2/{a,d}_{b,c}(通过花括号展开创建mnt/test2/a_b、/mnt/test2/a_c、/mnt/test2/d_b、/mnt/test2/d_c目录,,-p递归创建,如果所要创建的目录的路径不存在先创建路径上的目录节点,-v创建过程)
mkdir: created directory `/mnt/test2'
mkdir: created directory `/mnt/test2/a_b'
mkdir: created directory `/mnt/test2/a_c'
mkdir: created directory `/mnt/test2/d_b'
mkdir: created directory `/mnt/test2/d_c'

删除目录:rmdir (remove directory)
只能删除空目录
-p:只能删除一脉单传的目录

[root@Smoke ~]# rmdir /mnt/test2/(只能删除空目录)
rmdir: failed to remove `/mnt/test2/': Directory not empty(提示/mnt/test2/目录不空无法删除)
[root@Smoke ~]# rmdir /mnt/test2/a_b/(删除a_b目录,a_b目录为空正常删除)
[root@Smoke ~]# tree /mnt/test2(显示/test2的目录树,a_b不存在)
/mnt/test2
├── a_c
├── d_b
└── d_c
3 directories, 0 files
[root@Smoke ~]# rmdir -p /mnt/test2/a_c(提示不能删除test2目录,因为不空,但是把a_c删除了,-p只能删除一脉单传的目录)
rmdir: failed to remove directory `/mnt/test2': Directory not empty(test2无法删除,原因不空)
[root@Smoke ~]# tree /mnt/test2/(查看test2目录树,a_c不存在)
/mnt/test2/
├── d_b
└── d_c
[root@Smoke ~]# rmdir -p /root/x/y/z/(删除/root/x/y/z目录,x/y/z删除成功,但是/root没有删除,因为root不空,-p只能删除一脉单传的目录)
rmdir: failed to remove directory `/root': Directory not empty
2 directories, 0 files
[root@Smoke ~]# ls /root/(查看/root目录子目录和文件,x目录不存在)
install.log install.log Desktop anaconda-ks.cfg m

文件创建和删除
# touch:修改文件时间戳,如果文件不存在创建空文件
最近一次访问时间
最近一次修改时间
最近一次改变时间
-a:只改变访问时间。
-m:只改变修改时间。
-t:[[CC]YY]MMDDhhmm[.ss]指定改变为那个时间点。
-c,--no-create:修改文件时间戳,如果文件不存在不创建空文件。
没有只改变改变时间,因为任何属性修改报错时间戳修改意味着属性也改了,访问时间和修改时间都可以改,但是改变时间不能改。
# stat:查看文件或文件系统状态信息

[root@Smoke ~]# touch a(创建空文件a)
install.log install.log Desktop anaconda-ks.cfg m a
[root@Smoke ~]# file a(查看a文件类型,为空文件)
a: empty
[root@Smoke ~]# mkdir a(创建a目录与文件a名字相同无法创建,原因目录也是文件,特殊文件)
mkdir: cannot create directory `a': File exists
[root@Smoke ~]# stat a(查看a文件状态信息)
 File: `a'
 Size: 0                Blocks(数据库): 0          IO Block(I/O块): 4096   regular empty file
Device: 802h/2050d        Inode: 793187      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access(最近一次访问时间): 2014-06-03 22:14:37.574026718 +0800
Modify(最近一次修改时间): 2014-06-03 22:14:37.574026718 +0800
Change(最近一次改变时间): 2014-06-03 22:14:37.574026718 +0800
[root@Smoke ~]# date(查看当前系统时间)
Tue Jun  3 22:22:07 CST 2014
[root@Smoke ~]# touch a(改变a文件的时间戳)
[root@Smoke ~]# stat a(查看a文件状态信息,时间戳发生改变)
 File: `a'
 Size: 0                Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d        Inode: 793187      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-06-03 22:22:30.916026342 +0800
Modify: 2014-06-03 22:22:30.916026342 +0800
Change: 2014-06-03 22:22:30.916026342 +0800
[root@Smoke ~]# ls(查看当前目录文件及子目录,没有c文件)
install.log install.log Desktop anaconda-ks.cfg m a x
[root@Smoke ~]# touch -c c(改变文件c的时间戳,-c修改文件时间戳,如果文件不存在不创建空文件)
[root@Smoke ~]# ls(查看当前目录文件及子目录,没有c文件)
install.log install.log Desktop anaconda-ks.cfg m a x
[root@Smoke ~]# date(查看系统当前时间)
Tue Jun  3 22:32:35 CST 2014
[root@Smoke ~]# stat a(查看a文件状态信息)
 File: `a'
 Size: 0                Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d        Inode: 793187      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-06-03 22:22:30.916026342 +0800
Modify: 2014-06-03 22:22:30.916026342 +0800
Change: 2014-06-03 22:22:30.916026342 +0800
[root@Smoke ~]# touch -a a(改变a文件的访问时间,-a只修改访问时间)
[root@Smoke ~]# stat a(查看a文件状态信息,访问时间改变,文件属性也改变,所以改变时间也改变)
 File: `a'
 Size: 0                Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d        Inode: 793187      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-06-03 22:33:53.861025450 +0800
Modify: 2014-06-03 22:22:30.916026342 +0800
Change: 2014-06-03 22:33:53.861025450 +0800
[root@Smoke ~]# touch -m a(改变a文件的修改时间,-m只改变修改时间)
[root@Smoke ~]# stat a(查看a文件状态信息,修改时间改变,文件属性也改变,所以改变时间也改变)
 File: `a'
 Size: 0                Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d        Inode: 793187      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-06-03 22:33:53.861025450 +0800
Modify: 2014-06-03 22:41:19.891024691 +0800
Change: 2014-06-03 22:41:19.891024691 +0800
[root@Smoke ~]# man touch
[root@Smoke ~]# touch -m -t 201212121212 a(改变a文件的修改时间为12年12月12日12点12分,-m只改变修改时间,-t指定改变为那个时间点)
[root@Smoke ~]# stat a(查看a文件状态信息,修改时间改变为2012-12-12)
 File: `a'
 Size: 0                Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d        Inode: 793187      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-06-03 22:33:53.861025450 +0800
Modify: 2012-12-12 12:12:00.000000000 +0800
Change: 2014-06-03 22:44:37.141025715 +0800

创建文件,可以使用文件编辑器
word:不是文本编辑器,是字处理器。
ASCII:美国国家标准信息交换代码,通过二进制变化来表示一些不同字符。
128不同的字符:
二进制:
2^6=0,63
2^7=0,127
000 0000 - 111 1111
计算机最小存储单位是字节,也就是8位。
英文表示需要1字节,因为英文由26个字母组成,计算机最小存储单位8位完全满足26个字母的变化。
汉字标准:GB18030, GBK, GB2312,Unicode(统一的字符编码标准)
汉字表示需要的多少位:常用汉字有10多万,所以一个汉子需要2byte(字节)
2^16:65536
0000 1001 0000 1110:到底是两个ACSII码还是一个汉字,取决于语言字符集,想让它解释为什么样的字符,就在这个数据上套上转义器的东西。
文本编辑器只是编辑纯ASCII码的
Notepad++:windows下的文本编辑器
nano:linux文本编辑器

[root@Smoke ~]# nano hello(编辑hello文件)
This is        a test file.
^G Get Help        ^O WriteOut(^脱字符,代表CTRL保存)        ^R Read File         ^Y Prev Page       ^K Cut Text        ^C Cur Pos
^X Exit(退出)            ^J Justify         ^W Where Is        ^V Next Page       ^U UnCut Text      ^T To Spell
点击CTRL+O(保存)
File Name to Write: hello(是否保存文件名为hello,可以修改点击回车键确认)
点击CTRL+X(退出)
[root@Smoke ~]# ls -lh(查看当前目录文件及子目录详细信息,-l详细信息,-h单位换算)
-rw-r--r--   1 root root    0 Dec 12  2012 a
-rw-------.  1 root root 1.4K Apr 14 08:38 anaconda-ks.cfg
drwxr-xr-x.  2 root root 4.0K Apr 15 21:27 Desktop
-rw-r--r--   1 root root   21 Jun  3 23:15 hello
-rw-r--r--.  1 root root  45K Apr 14 08:38 install.log
-rw-r--r--.  1 root root 9.8K Apr 14 08:35 install.log.syslog
drwxr-xr-x   3 root root 4.0K Jun  3 21:47 m
[root@Smoke ~]# file hello(查案hello文件类型为ASCII码)
hello: ASCII text

删除文件:
rm:删除文件
-i:交互式,提示是否删除,只有管理员有这个选项,普通用户是不会提示的,就是为了避免误操作。
-f:强行删除,不提示。
-r:删除目录。
rm -rf /:自杀,删除根文件系统所有文件不会提示
\rm:使用命令自身的意思,而不是别名

[root@Smoke ~]# rm hello(删除hello文件,提示是否确认删除,默认是不提示的,因为这里使用的rm命令已经不再是原生的rm命令,是被修改后的rm命令)
rm: remove regular file `hello'? y
[root@Smoke ~]# ls -lh(查看当前目录文件及子目录详细信息,-l详细信息,-h单位换算,hello文件被删除)
-rw-r--r--   1 root root    0 Dec 12  2012 a
-rw-------.  1 root root 1.4K Apr 14 08:38 anaconda-ks.cfg
drwxr-xr-x.  2 root root 4.0K Apr 15 21:27 Desktop
-rw-r--r--.  1 root root  45K Apr 14 08:38 install.log
-rw-r--r--.  1 root root 9.8K Apr 14 08:35 install.log.syslog
drwxr-xr-x   3 root root 4.0K Jun  3 21:47 m
[root@Smoke ~]# type rm(查看rm命令类型,rm是rm -i的别名)
rm is aliased to `rm -i'
[root@Smoke ~]# \rm a(删除a文件,使用反斜杠\转义,使用命令本身)
[root@Smoke ~]# ls(查看当前目录文件及子目录,a文件被删除)
Desktop anaconda-ks.cfg install.log install.log.syslog m x

当我们想使用一个命令自身的意思,而不是别名的时候,可以在命令前面加\反斜杠,只有有别名的命令才有意义。

[root@Smoke ~]# type ls(查看ls命令的类型)
ls is aliased to `ls --color=auto'
[root@Smoke ~]# \ls(ls的别名为`ls --color=auto',使用ls自身意思,文件没有颜色)
Desktop anaconda-ks.cfg install.log install.log.syslog m x
[root@Smoke ~]# tree /mnt/test2/(查看test2目录树)
/mnt/test2/
├── d_b
└── d_c
2 directories, 0 files
[root@Smoke ~]# rm -rf /mnt/test2/(删除test2文件,-r删除目录,-f强行删除)
[root@Smoke ~]# ls /mnt/(查看/mnt目录下文件及子目录,test2不存在)
test

练习:
1、创建目录
(1)在/mnt下创建boot和sysroot;
(2)在/mnt/boot下创建grub;
(3)在/mnt/sysroot下创建proc, sys, bin, sbin, lib, usr, var, etc, dev, home, root, tmp
a)在/mnt/sysroot/usr下创建bin, sbin, lib
b)在/mnt/sysroot/lib下创建modules
c)在/mnt/sysroot/var下创建run, log, lock
d)在/mnt/sysroot/etc下创建init.d

[root@Smoke ~]# mkdir -pv /mnt/{boot/{proc,sys,bin,sbin,lib,usr,var,etc,dev,home,root,tmp},sysroot/{usr,lib,var,etc}}(创建目录使用-p递归创建,如果所要创建的目录的路径不存在先创建路径上的目录节点,-v创建过程)
mkdir: created directory `/mnt/boot'
mkdir: created directory `/mnt/boot/proc'
mkdir: created directory `/mnt/boot/sys'
mkdir: created directory `/mnt/boot/bin'
mkdir: created directory `/mnt/boot/sbin'
mkdir: created directory `/mnt/boot/lib'
mkdir: created directory `/mnt/boot/usr'
mkdir: created directory `/mnt/boot/var'
mkdir: created directory `/mnt/boot/etc'
mkdir: created directory `/mnt/boot/dev'
mkdir: created directory `/mnt/boot/home'
mkdir: created directory `/mnt/boot/root'
mkdir: created directory `/mnt/boot/tmp'
mkdir: created directory `/mnt/sysroot'
mkdir: created directory `/mnt/sysroot/usr'
mkdir: created directory `/mnt/sysroot/lib'
mkdir: created directory `/mnt/sysroot/var'
mkdir: created directory `/mnt/sysroot/etc'

复制和移动文件:
复制文件:
cp:copy复制
cp SRC DEST
-r,-R,--recursive:递归复制目录及目录所有文件及子目录到目标目录下
-i:交互式,如果目标存在,提示要不要覆盖
-f:强行复制,如果目标文件存在,不提示,默认复制不会提示,命令使用别名,cp是个别名是cp -i命令,普通用户是没有别名的,普通用户复制目标存在不会提示,直接覆盖,可以通过\转义,不提示,使用命令本身。
-p,--preserve:复制文件时候保留文件的原有的属主、属组、权限、以及时间戳等属性值。
-a,-dR,--preserve=all:归档复制,常用于备份,保留文件原来所有的属性,比-p选项保留的
-d,--no-dereference,--preserve=link:当复制符号连接时,保持链接自身,把目标文件或目录也建立为符号连接,并指向与源文件或目录连接的原始文件或目录;
-L,--dereference:总是跟踪符号链接,复制的不是链接文件,而是链接指定的文件。
-P,--no-dereference:如果复制的文件是一个链接文件,保持链接,如果是一个链接把它复制为链接。
属性更多。
对于cp命令来讲,通常只有最后一个是目标此前的都是源,那就意味着它不允许一个源多个目标,也不允许多个源多个目标,只允许出现一个目的地,不能把两个文件复制成一个文件,
cp file1 file2 file3:file1和file2是源,file3是目标。
复制法则:
1、一个文件到一个文件
2、多个文件到一个目录
如果源是多个目标必须是目录,必须存在,而且还要是目录,否则复制将无法进行。
cp /etc/{passwd,inittab,rc.d/rc.sysinit} /tmp/:将/etc/passwd,/etc/inittab,/etc/rc.d/sysinit文件复制到/tmp目录

[root@Smoke ~]# cp /etc/passwd /tmp/(把/etc/paswwd文件复制到/tmp目录下,并且保存为原来的文件名)
提示:如果目标是一个目录,并且它存在的话,就意味将源文件放在这个目录下并保持原来的名字。
[root@Smoke ~]# cp /etc/passwd /tmp/test(将/etc/passwd复制到/tmp目录下并重命名为test)
提示:源是一个文件,如果目标test不存在,就意味这将passwd复制到/tmp下名重命名为test,如果test存在,要看是目录还是文件,如果是个文件则提示我们是否覆盖,就意味着把test删除,把passwd复制过来并重命名为test,如果test是个目录,把passwd放到/tmp/test目录下,并保持原来的文件名。
[root@Smoke ~]# cp /etc/passwd /etc/issue /etc/inittab /tmp/abc(复制passwd、issue、inittab文件到/tmp/abc下,由于abc目录不存在复制失败)
cp: target `/tmp/abc' is not a directory
[root@Smoke ~]# cp /etc/inittab /tmp/abc(复制源为一个,目标/abc不存在,将initab复制到/tmp下并重命名为abc)
[root@Smoke ~]# ls /tmp/(查看/tmp目录下文件及子目录,abc复制成功)
abc                 pulse-8G34pGhBrYlR  VMwareDnD    vmware-root-3980361937
pulse-3roVQmCsn5Z5  puppet              vmware-root
[root@Smoke ~]# cp /etc/init.d/ /tmp/(复制/etc/init.d目录到/tmp/目下下不能复制)
cp: omitting directory `/etc/init.d/'(略过目录/etc/init.d)
[root@Smoke ~]# ls /tmp/(查看/tmp目录下文件及子目录,init.d不存在,复制失败)
abc                 pulse-8G34pGhBrYlR  VMwareDnD    vmware-root-3980361937
pulse-3roVQmCsn5Z5  puppet              vmware-root
提示:copy命令默认是不会复制目录,只复制文件。
[root@Smoke ~]# cp -r /etc/init.d/ /tmp/hello
提示:如果复制的源是目录,目标hello不存在,把init.d目录复制到/tmp目录下并重命名为hello目录,如果hello存在是个目录,将init.d目录复制到/tmp/hello目录下并保持原来的目录名,如果hello存在是个文件,不能复制,但是redhat 5.x可以复制为链接。
[root@Smoke ~]# cp -r /etc/init.d/ /tmp/passwd(将/init.d目录复制到/tmp目录,passwd是个文件,不能复制)
cp: cannot overwrite non-directory `/tmp/passwd' with directory `/etc/init.d/'
[root@Smoke ~]# type cp(查看cp命令类型,cp命令别名为cp -i复制目标文件存在提示)
cp is aliased to `cp -i'
提示:默认复制不会提示,命令使用别名,cp是个别名是cp -i命令,普通用户是没有别名的,普通用户复制目标存在不会提示,直接覆盖,可以通过\转义,不提示,使用命令本身。
[root@Smoke ~]# su - student(切换到student用户)
[student@Smoke ~]$ cd /tmp/(进入/tmp目录下)
[student@Smoke tmp]$ cp /etc/inittab /tmp/stu.inittab(拷贝/etc/inittab到/tmp目录并重命名为stu.inittab)
[student@Smoke tmp]$ ls -l /tmp/stu.inittab(查看stu.inittab文件详细信息,属主属组为student,谁复制的新文件就属于谁)
-rw-r--r-- 1 student student 884 Jun  4 11:04 /tmp/stu.inittab
[student@Smoke tmp]$ exit(退出用户)
logout
[root@Smoke ~]# ls -l /tmp/stu.inittab(查看/stu.inittab文件属主属组为student)
-rw-r--r-- 1 student student 884 Jun  4 11:04 /tmp/stu.inittab
[root@Smoke ~]# cp /tmp/stu.inittab /tmp/root.inittab(使用root帐号复制stu.inittab文件到/tmp目录并改名为root.inittab)
[root@Smoke ~]# ls -l /tmp/(查看/tmp目录,复制的root.inittab文件属主属组为root)
-rw-r--r--  1 root    root      884 Jun  4 11:08 root.inittab
-rw-r--r--  1 student student   884 Jun  4 11:04 stu.inittab
提示:谁复制新文件的属主属组就属于谁。
[root@Smoke ~]# cp -p /tmp/stu.inittab /tmp/root.inittab.2(复制stu.inittab文件到/tmp目录下并重命名为root.inittab.2文件,-p保存源文件的属性值)
[root@Smoke ~]# ls -l /tmp/(查看/tmp目录详细信息,rot.inittab.2文件属主属组还是student,-l相信信息)
-rw-r--r--  1 root    root      884 Jun  4 11:08 root.inittab
-rw-r--r--  1 student student   884 Jun  4 11:04 root.inittab.2
-rw-r--r--  1 student student   884 Jun  4 11:04 stu.inittab
[root@Smoke ~]# ls -l /etc/rc(查看rc文件类型为链接文件)
lrwxrwxrwx. 1 root root 7 Apr 14 22:59 /etc/rc -> rc.d/rc
[root@Smoke ~]# cp /etc/rc /tmp/(复制rc链接文件到/tmp目录)
[root@Smoke ~]# ll /tmp/(通过查看复制的rc文件,非链接文件,而是链接文件指向的文件)
-rwxr-xr-x  1 root    root     2617 Jun  4 11:34 rc
提示:默认情况下,复制链接指向的那个文件,而不是链接本身。
[root@Smoke ~]# cp -L /etc/rc /tmp/rc.2(复制rc文件到/tmp目录并重命名为rc.2,复制链接文件指定的文件,-L复制的不是链接文件,而是链接指定的文件)
[root@Smoke ~]# ll /tmp/(查看/tmp目录,通过-L选项复制的rc.2文件为连接文件指向的文件)
-rwxr-xr-x  1 root    root     2617 Jun  4 11:38 rc.2
[root@Smoke ~]# cp -P /etc/rc /tmp/rc.3(复制rc文件到/tmp目录重命名为rc.3,-P如果复制的文件是一个链接文件,保持链接,如果是一个链接把它复制为链接)
[root@Smoke ~]# ll /tmp/(查看/tmp目录,通过-P选项复制的rc.3文件为链接文件)
-rwxr-xr-x  1 root    root     2617 Jun  4 11:34 rc
-rwxr-xr-x  1 root    root     2617 Jun  4 11:38 rc.2
lrwxrwxrwx  1 root    root        7 Jun  4 11:44 rc.3 -> rc.d/rc
移动文件:

mv: move移动
mv SRC DEST
mv -t DEST SRC:先写目标,再跟源文件,还是把SRC移动到DEST,但是先指定目标。
-i:如果目标存在,提示是否覆盖,默认不会提示
-f:如果目标存在强制进行覆盖。
\mv:使用命令本身意思,不使用别名,mv是mv -i别名,覆盖提示,只有root用户提示,普通用户没有别名。
不允许一个源多个目标或多个源多个目标,只有最后一个是目标,目标只能有一个,可以一个源一个目标,可以多个源一个目标,多个源如果目标存在但不是目录不行,

[root@Smoke ~]# mv /tmp/root.inittab /var/tmp/(将root.inittab文件剪贴到/var/tmp目录,并保留原来名称)
[root@Smoke ~]# mv /tmp/root.inittab /var/tmp/abc(abc为文件,移动root.inittab文件到/var/tmp/目录并重命名为abc)
[root@Smoke ~]# mv /tmp/hello/ /var/tmp/abc(将hello目录移动到/var/tmp/abc)
提示:移动hello/目录,mv移动目录不需要任何选项,abc不存在,把hello移动过去并重命名为abc,如果abc存在并且是个文件,无法移动,不能拿目录覆盖非目录,如果abc存在并且是个目录,移动到/abc目录下,保存原来的名字,不会覆盖目标目录。
[root@Smoke ~]# cp /etc/inittab /var/tmp/abc(复制inittab文件到/var/tmp目录重命名为abc)
[root@Smoke ~]# file /var/tmp/abc(查看/abc文件类型,为文本文件ASCII)
/var/tmp/abc: ASCII English text
[root@Smoke ~]# mv /tmp/hello/ /var/tmp/abc(移动hello目录到/var/tmp/abc文件,无法移动)
mv: overwrite `/var/tmp/abc'? y
mv: cannot overwrite non-directory `/var/tmp/abc' with directory `/tmp/hello/'
[root@Smoke ~]# cd /var/tmp/(切换到/var/tmp目录)
[root@Smoke tmp]# pwd(查看当前路径)
/var/tmp
[root@Smoke tmp]# ls(查看tmp目录文件及子目录)
abc
[root@Smoke tmp]# mv abc mn(把abc文件移动到当前目录下叫mn重命名)
[root@Smoke tmp]# ls
mn
提示:如果源和目标的目录一致,路径一致只是名称不同,就是重命名,重命名不关心你是文件还是目录,只要是在同一目录下就是重命名。
[root@Smoke tmp]# ls(查看目录文件及子目录)
abc                 puppet          stu.inittab
hello               rc              VMwareDnD
init.d              rc.2            vmware-root
passwd              rc.3            vmware-root-3980361937
pulse-3roVQmCsn5Z5  root.inittab    yum_save_tx-2014-05-29-19-44KIYaTb.yumtx
pulse-8G34pGhBrYlR  root.inittab.2
[root@Smoke tmp]# mv hello/ hi(移动本地目录hello到本地目录hi,重命名)
[root@Smoke tmp]# ls(查看重命名的hi目录)
abc                 puppet          stu.inittab
hi                  rc              VMwareDnD
init.d              rc.2            vmware-root
passwd              rc.3            vmware-root-3980361937
pulse-3roVQmCsn5Z5  root.inittab    yum_save_tx-2014-05-29-19-44KIYaTb.yumtx
pulse-8G34pGhBrYlR  root.inittab.2
[root@Smoke tmp]# type mv(查看mv命令类型,mv是个别名为mv -i)
mv is aliased to `mv -i'

install:复制文件和设置文件属性,只能复制文件,不能复制目录。
-d DIRECOTRY ... :创建目录
SRC... DEST:复制文件,但是复制过去有执行权限,源可以有多个,但目标必须是目录。
-m,--mode=MODE:指定复制过去权限是什么,如果不指定默认是rwxr-xr-x权限。
install -t DIRECTORY SRC...:先指定目标再指定源文件,源如果有多个,目标就必须是目录,还是把SRC移动到DEST,但是先指定目标。

[root@Smoke ~]# install -d /tmp/{install.1,install.2}(在tmp目录创建两个目录叫install.1和install.2)
[root@Smoke ~]# ls /tmp/(查看在/tmp目录下创建的两个目录)
abc                 pulse-8G34pGhBrYlR  stu.inittab
hi                  puppet              VMwareDnD
init.d              rc                  vmware-root
install.1           rc.2                vmware-root-3980361937
install.2           rc.3                yum_save_tx-2014-05-29-19-44KIYaTb.yumtx
passwd              root.inittab
pulse-3roVQmCsn5Z5  root.inittab.2
[root@Smoke ~]# install /etc/passwd /var/tmp/install.file1(复制/passwd到/var/tmp目录改名为install.file1)
[root@Smoke ~]# ls /var/tmp/(查看复制的文件)
install.file1  mn
[root@Smoke ~]# file /etc/rc.d/(查看/rc.d文件类型为目录)
/etc/rc.d/: directory
[root@Smoke ~]# install /etc/rc.d/ /var/tmp/(isntall默认不能复制目录)
install: omitting directory `/etc/rc.d/'

提示:install命令只能复制源为文件,不能源是目录。
文本处理:cat,more,less,head,tail,cut,sort,unig,grep则会给你则表达式
管道和重定向:> < >> <<
用户、组、权限
bash及其特性

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值