UNIX Shell 编程(1)

简介: UNIX Shell 编程(1) Unix只能识别3种基本的文件类型:普通文件、目录文件和特殊文件。 普通文件:any file on the system that contains data, test, program instructions, or just about anything else.

UNIX Shell 编程(1)


Unix只能识别3种基本的文件类型:普通文件、目录文件和特殊文件。
普通文件:any file on the system that contains data, test, program instructions, or just about anything else.

统计文件中的单词数:wc命令
如:
[root@localhost test]# wc Makefile
 22 84 600 Makefile
第一个数字表示文件Makefile包含的行数;第二个数字表示文件包含的单词数目;第三个数字表示文件包含的字符数。
命令参数:
-l 表示显示行数
-c 表示显示字符数
-w 表示显示单词数

显示工作目录:pwd命令
如:
[root@localhost test]# pwd
/tools/test

ls命令详细说明:
[root@localhost test]# ls -l
total 44
drwxrwxrwx 8 1000 1000 4096 2006-04-01 14:42 make-3.81
-rw-r--r-- 1 root root 600 2009-04-13 15:45 Makefile
-rw-r--r-- 1 root root 364 2009-04-13 16:01 Makefile2
-rwxrwxr-x 1 root root 4995 2009-04-03 15:43 test_endian
-rw-r--r-- 1 root root 215 2009-04-03 15:43 test_endian.c
——————
第一行说明文件占用存储空间的块数。
后续行显示目录中每个文件的详细信息。

链接文件:ln命令
命令格式:ln from to
它类似于Windows平台上的快捷方式。
如:
ln abc writeback
ls -l
显示:
total 48
-rw-r--r-- 2 root root 13 2009-04-13 17:45 abc
-rw-r--r-- 1 root root 6 2009-04-13 17:39 collect
-rw-r--r-- 1 root root 6 2009-04-13 17:39 mon
-rw-r--r-- 1 root root 6 2009-04-13 17:38 wb
-rw-r--r-- 1 root root 6 2009-04-13 17:34 wbx
-rw-r--r-- 2 root root 13 2009-04-13 17:45 writeback
注:数字2表示链接数为2,这意味着一个文件可以链接多次。
执行:
[root@localhost programs]rm abc
rm: remove regular file `abc'? y
[root@localhost programs]# ls
collect mon wb wbx writeback
[root@localhost programs]# ls -l
total 40
-rw-r--r-- 1 root root 6 2009-04-13 17:39 collect
-rw-r--r-- 1 root root 6 2009-04-13 17:39 mon
-rw-r--r-- 1 root root 6 2009-04-13 17:38 wb
-rw-r--r-- 1 root root 6 2009-04-13 17:34 wbx
-rw-r--r-- 1 root root 13 2009-04-13 17:45 writeback
————————————————
文件writeback的链接数变成1了;文件仍然存在,所以它与Windows平台的快捷方式是有区别的。
ln最通常的用途是链接不同目录中的文件。
链接文件的唯一限制是,链接在一起的文件必须共存于同一文件系统。
要链接到不同文件系统中的文件,可以给ln命令加-s选项,这样可以建立一个符号化链接。

 

符号化链接与初始链接有一点不同:符号化链接指向初始文件,如初始文件被删除,该符号化链接则不起作用。
如:
[root@localhost programs]# ln -s wb wbb
[root@localhost programs]# ls -l
total 44
-rw-r--r-- 1 root root 6 2009-04-13 17:39 collect
-rw-r--r-- 1 root root 6 2009-04-13 17:39 mon
-rw-r--r-- 1 root root 6 2009-04-13 17:38 wb
lrwxrwxrwx 1 root root 2 2009-04-14 10:26 wbb -> wb
-rw-r--r-- 1 root root 6 2009-04-13 17:34 wbx
-rw-r--r-- 1 root root 13 2009-04-13 17:45 writeback
注意:wbb文件类型显示为1,表示它是一个符号化链接。

目录
相关文章
|
2月前
|
Unix Linux Shell
【Shell 编程指南 日期命令】Date命令:显示与设置系统时间和日期
【Shell 编程指南 日期命令】Date命令:显示与设置系统时间和日期
57 0
|
2月前
|
Shell C++ 开发者
【Shell 编程指南】Shell运算操作符之$[]详解
【Shell 编程指南】Shell运算操作符之$[]详解
22 0
|
2月前
|
存储 Shell Linux
【Shell 命令集合 网络通讯 】Linux 显示Unix-to-Unix Copy (UUCP) 系统的状态信息 uustat命令 使用指南
【Shell 命令集合 网络通讯 】Linux 显示Unix-to-Unix Copy (UUCP) 系统的状态信息 uustat命令 使用指南
28 0
|
3月前
|
Ubuntu Linux Shell
【Linux操作系统】探秘Linux奥秘:shell 编程的解密与实战
【Linux操作系统】探秘Linux奥秘:shell 编程的解密与实战
71 0
|
3天前
|
监控 关系型数据库 Shell
Shell脚本入门:从基础到实践,轻松掌握Shell编程
Shell脚本入门:从基础到实践,轻松掌握Shell编程
|
5天前
|
存储 Shell C语言
shell脚本 编程 变量 基本入门(详解)
shell脚本 编程 变量 基本入门(详解)
|
17天前
|
存储 网络协议 Shell
第十章 Shell编程时常用的系统文件
第十章 Shell编程时常用的系统文件
|
24天前
|
监控 Shell 开发工具
Shell编程
Shell编程
|
24天前
|
Shell
Shell脚本编程基础
Shell脚本编程基础
|
2月前
|
存储 Java Shell
bigdata-04-shell编程基础
bigdata-04-shell编程基础
24 0