在文本处理的工作中,统计文件的行数,单词数和字符数非常有用。而对于开发人员本身来说,统计LOC(line of code ,代码行数)是一件重要的工作。linux中有什么命令可以帮助我们做统计呢?没错,就是wc,不是厕所的意思啊,是Word Count的缩写。

当作好统计时,又需要写个开发的文档,特别是项目比较大的时候,如果将目录和文件系统以图形化的树状层次结构描述,在以后的维护过程将更加清晰明了,下面将同样将要介绍的还有tree命令.

一、wc命令详解

首先,输入man wc 查看wc 的指导手册

NAME
wc - print newline, word, and byte counts for each file SYNOPSIS
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F DESCRIPTION
Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or
when FILE is -, read standard input. A word is a non-zero-length sequence of characters delimited by white space. The
options below may be used to select which counts are printed, always in the following order: newline, word, character,
byte, maximum line length. -c, --bytes
print the byte counts -m, --chars
print the character counts -l, --lines
print the newline counts --files0-from=F
read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input -L, --max-line-length
print the length of the longest line -w, --words
print the word counts --help display this help and exit --version
output version information and exit

语法:

wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F

参数-实例:

下面将通过实例介绍各参数的含义和作用:

用到的test.txt

amosli@amosli-pc:~/learn/wc$ cat test.txt
Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or
when FILE is -, read standard input. A word is a non-zero-length sequence of characters delimited by white space. The
options below may be used to select which counts are printed, always in the following order: newline, word, character,
byte, maximum line length.

1、-c参数,统计字节数,字符数

amosli@amosli-pc:~/learn/wc$ wc -c test.txt
test.txt

2.-l参数,统计行数

amosli@amosli-pc:~/learn/wc$ wc -l test.txt
test.txt

3.-w参数,统计单词数

amosli@amosli-pc:~/learn/wc$ wc -w test.txt
test.txt

4.-L参数,统计最长行的长度

amosli@amosli-pc:~/learn/wc$ wc -L test.txt
test.txt

5.-m参数,统计字母数

amosli@amosli-pc:~/learn/wc$ wc -m test.txt
test.txt

6.不加参数

amosli@amosli-pc:~/learn/wc$ wc test.txt
test.txt

分别表示行数,单词数,字符数

7.使用标准输入进行统计

amosli@amosli-pc:~/learn/wc$ echo "hi_amos" | wc -m

二、tree命令详解

首先,sudo apt-get install tree安装一下tree命令

下面将输入tree --help查看提示信息:

amosli@amosli-pc:~/learn$ tree --help
usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]]
[-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
[--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
[--filelimit #] [<directory list>]
-a All files are listed.
-d List directories only.
-l Follow symbolic links like directories.
-f Print the full path prefix for each file.
-i Don't print indentation lines.
-q Print non-printable characters as '?'.
-N Print non-printable characters as is.
-p Print the protections for each file.
-u Displays file owner or UID number.
-g Displays file group owner or GID number.
-s Print the size in bytes of each file.
-h Print the size in a more human readable way.
-D Print the date of last modification.
-F Appends '/', '=', '*', or '|' as per ls -F.
-v Sort files alphanumerically by version.
-r Sort files in reverse alphanumeric order.
-t Sort files by last modification time.
-x Stay on current filesystem only.
-L level Descend only level directories deep.
-A Print ANSI lines graphic indentation lines.
-S Print with ASCII graphics indentation lines.
-n Turn colorization off always (-C overrides).
-C Turn colorization on always.
-P pattern List only those files that match the pattern given.
-I pattern Do not list files that match the given pattern.
-H baseHREF Prints out HTML format with baseHREF as top directory.
-T string Replace the default HTML title and H1 header with string.
-R Rerun tree when max dir level reached.
-o file Output to file instead of stdout.
--inodes Print inode number of each file.
--device Print device ID number to which each file belongs.
--noreport Turn off file/directory count at end of tree listing.
--nolinks Turn off hyperlinks in HTML output.
--dirsfirst List directories before files.
--charset X Use charset X for HTML and indentation line output.
--filelimit # Do not descend dirs with more than # files in them.

语法:

tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]]
[-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
[--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
[--filelimit #] [<directory list>]

参数-实例:

-a 显示所有文件和目录。
-A 使用ASNI绘图字符显示树状图而非以ASCII字符组合。
-C 在文件和目录清单加上色彩,便于区分各种类型。
-d 显示目录名称而非内容。
-D 列出文件或目录的更改时间。
-f 在每个文件或目录之前,显示完整的相对路径名称。
-F 在执行文件,目录,Socket,符号连接,管道名称名称,各自加上"*","/","=","@","|"号。
-g 列出文件或目录的所属群组名称,没有对应的名称时,则显示群组识别码。
-i 不以阶梯状列出文件或目录名称。
-I 不显示符合范本样式的文件或目录名称。
-l 如遇到性质为符号连接的目录,直接列出该连接所指向的原始目录。
-n 不在文件和目录清单加上色彩。
-N 直接列出文件和目录名称,包括控制字符。
-p 列出权限标示。
-P 只显示符合范本样式的文件或目录名称。
-q 用"?"号取代控制字符,列出文件和目录名称。
-s 列出文件或目录大小。
-t 用文件和目录的更改时间排序。
-u 列出文件或目录的拥有者名称,没有对应的名称时,则显示用户识别码。
-x 将范围局限在现行的文件系统中,若指定目录下的某些子目录,其存放于另一个文件系统上,则将该子目录予以排除在寻找范围外。

1、不输入任何参数使用tree命令

amosli@amosli-pc:~/learn/re$ tree
.
├── d1
│ └── d2
│ └── d3
│ └── a.txt
├── d2
│ └── d2
│ └── d3
│ └── a.txt
├── db
│ └── dc
├── dd
│ └── db
├── test.sh
├── version1.txt
├── version2.txt
└── version.patch directories, files

2、-P参数,对样式进行筛选

如,筛选.sh结尾的文件

amosli@amosli-pc:~/learn/re$ tree . -P "*.sh"
.
├── d1
│   └── d2
│   └── d3
├── d2
│   └── d2
│   └── d3
├── db
│   └── dc
├── dd
│   └── db
└── test.sh

3、-h参数,打印出文件和目录的大小

amosli@amosli-pc:~/learn/re$ tree -h
.
├── [.0K] d1
│   └── [.0K] d2
│   └── [.0K] d3
│   └── [ ] a.txt
├── [.0K] d2
│   └── [.0K] d2
│   └── [.0K] d3
│   └── [ ] a.txt
├── [.0K] db
│   └── [.0K] dc
├── [.0K] dd
│   └── [.0K] db
├── [ ] test.sh
├── [ ] version1.txt
├── [ ] version2.txt
└── [ ] version.patch directories, files

4、-d参数,只显示目录

amosli@amosli-pc:~/learn/re$ tree -d
.
├── d1
│   └── d2
│   └── d3
├── d2
│   └── d2
│   └── d3
├── db
│   └── dc
└── dd
└── db directories

5、-D参数,显示文件修改日期

amosli@amosli-pc:~/learn/re$ tree -D
.
├── [Dec :] d1
│   └── [Dec :] d2
│   └── [Dec :] d3
│   └── [Dec :] a.txt
├── [Dec :] d2
│   └── [Dec :] d2
│   └── [Dec :] d3
│   └── [Dec :] a.txt
├── [Dec :] db
│   └── [Dec :] dc
├── [Dec :] dd
│   └── [Dec :] db
├── [Dec :] test.sh
├── [Dec :] version1.txt
├── [Dec :] version2.txt
└── [Dec :] version.patch directories, files

6、-i参数,不以阶梯状显示

amosli@amosli-pc:~/learn/re$ tree -i
.
d1
d2
d3
a.txt
d2
d2
d3
a.txt
db
dc
dd
db
test.sh
version1.txt
version2.txt
version.patch directories, files

7、其他参数可以根据自己需要去选择,更多信息请使用man tree查看tree命令手册.

linux shell 脚本攻略学习16--wc命令详解,tree命令详解的更多相关文章

  1. linux shell 脚本攻略学习8---md5校验,sort排序,uniq命令详解

    一.校验与核实 目前最为出名的校验技术是md5sum和sha1sum,它们对文件内容使用相应的算法来生成校验和. 举例: amosli@amosli-pc:~/learn$ md5sum text.t ...

  2. linux shell 脚本攻略学习20--awk命令入门详解

    awk生于1977年,创始人有三个,分别为 Alfred Aho,Peter Weinberger, 和 Brian Kernighan,名称源于三个创始人的姓的首字母. 作用:处理文本文件. awk ...

  3. linux shell 脚本攻略学习18--grep命令详解

    grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是unix/linux中用于文本搜索 ...

  4. Linux Shell脚本攻略学习总结:一

    终端打印 终端打印的常用命令有两个:echo和print 首先,我先介绍echo 1.echo echo这个命令接受三种形式的参数,实例如下: echo "Hello World" ...

  5. linux shell 脚本攻略学习14--head命令详解,tail命令详解

    当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...

  6. linux shell 脚本攻略学习13--file命令详解,diff命令详解

    一.file命令详解 find命令可以通过查看文件内容来找出特定类型的文件,在UNIX/ Linux系统中,文件类型并不是由文件扩展名来决定的(windows中却正是这么做的),file命令的目的是从 ...

  7. linux shell 脚本攻略学习 -- head命令详解, tail命令详解

    当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...

  8. Linux Shell 脚本攻略学习--四

    linux中(chattr)创建不可修改文件的方法 在常见的linux扩展文件系统中(如ext2.ext3.ext4等),可以将文件设置为不可修改(immutable).某些文件属性可帮助我们将文件设 ...

  9. linux shell 脚本攻略学习19--sed命令详解

    sed(意为流编辑器,英语“stream editor”的缩写)是Unix/linux常见的命令行程序.sed用来把文档或字符串里面的文字经过一系列编辑命令转换为另一种格式输出,即文本替换.sed通常 ...

随机推荐

  1. 战斗bug技巧全攻略

    程序员不是有一幅这样的对联吗 上联:一个项目两部电脑三餐盒饭只为四千工资搞得五脏俱损六神无主仍然七点起床八点开会处理九个漏洞十分辛苦: 下联:十年编码九年加班八面无光忙的七窍生烟到头六亲不认五体投地依 ...

  2. BitNami

    BitNami 提供wordpress.joomla.drupal.bbpress等开源程序的傻瓜式安装包下载,所有的安装包内置了服务器环境,就是说,不需要在本地 电脑上另外搭建服务器,就可以一次性傻 ...

  3. nova network工作原理及配置

    1. nova network简介 网络管理和配置是云计算中一项非常重要的功能.nova自带的nova-network实现了一些基本的网络模型,允许虚拟机之间的相互通信及虚拟机对internet的访问 ...

  4. mybatis自定义枚举转换类

    转载自:http://my.oschina.net/SEyanlei/blog/188919 mybatis提供了EnumTypeHandler和EnumOrdinalTypeHandler完成枚举类 ...

  5. 初始化android studio的方法

    有可能是在一次android studio被我强制关闭以后,我的android studio就出现了各种诡异的问题,项目无法运行,新建的项目报错,等等.抓狂~~ 于是想到把android studio ...

  6. xpress for node 路由route几种实现方式

    路由实现方式和顺序第二种路由写法第三种路由写法最佳 http://blog.csdn.net/mociml/article/details/11137571# http://blog.fens.me/ ...

  7. LintCode: Triangle

    C++ 逆推 class Solution { public: /** * @param triangle: a list of lists of integers. * @return: An in ...

  8. MVC 之 解决MVC中使用BundleConfig.RegisterBundles引用Css及js文件发布后的丢失

    在MVC3中我们这样引用资源文件: <link href="@Url.Content("~/Content/Site.css")" rel="s ...

  9. Java中监控文件变化的多种方案

    一.使用Apache.Common.io库 package yungoal.huafeng.utils.files; import com.sun.deploy.util.SyncFileAccess ...

  10. Linux和Windows中查看端口占用情况

    一.命令 netstat -lnt  或 netstat -tnlp 如: 二.较全 netstat -antulp 三.简单 ss -tanl  或 ss -tanlp 三.补充 Windows中使 ...