在文本处理的工作中,统计文件的行数,单词数和字符数非常有用。而对于开发人员本身来说,统计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. (转)PlayerPrefs在Windows下存到哪里去了?

    自:http://www.unitymanual.com/blog-77510-2971.html?_dsign=ec64b1e5 测试脚本  saveData.cs 附着在MainCamera上. ...

  2. 准确率,召回率,F值,机器学习分类问题的评价指标

    下面简单列举几种常用的推荐系统评测指标: 1.准确率与召回率(Precision & Recall) 准确率和召回率是广泛用于信息检索和统计学分类领域的两个度量值,用来评价结果的质量.其中精度 ...

  3. OCR 基本知识

    OCR,optical character recognition 的简称,也就是光学识别系统,属于图形识别的一个分支,OCR是针对印刷体字符,採用光学的方式将文档资料转换成原始资料黑白点阵的图像文件 ...

  4. iOS中文API之UIResponder介绍

    该UIResponder类定义了响应和处理事件的对象接口.它是UIView和UIApplication的超类(UIWindow).这些类的实例有时被称为响应者对象,简单地说就是响应者. 通常有2种事件 ...

  5. BAT,你好!字幕组,再见!——也许要跟美剧说再见了~

    对于美剧迷来说,上周的星期六(2014 年11 月 22 日)是黑色的一天. 11 月 22 日,人人影视暂时关站,并发布公告称网站正在清理内容.虽然这不是人人影视第一次关站清理,而且人人影视还给出提 ...

  6. DELL平板如何安装WIN10系统 -标记活动分区的问题

    在计算机管理中没有这个选项   可以在分区助手软件中,选中C分区之后,左边有设置活动分区,然后左上角提交执行即可        

  7. ASP.NET绑定学习

    1.直接绑定到页面成员<asp:Repeater ... DataSource='<%#页面方法或属性%>'></asp:Repeater> 2.绑定到数组< ...

  8. Python 函数参数引用(传值/传址)/copy/deepcopy

    精简版: 传值:被调函数局部变量改变不会影响主调函数局部变量 传址:被调函数局部变量改变会影响主调函数局部变量 Python参数传递方式:传递对象引用(传值和传址的混合方式),如果是数字,字符串,元组 ...

  9. Plupload上传插件中文帮助文档

    Plupload上传插件中文帮助文档 配置参数 实例化一个plupload对象时,也就是 new plupload.Uploader(),需要传入一个对象作为配置参数.后面内容中出现的plupload ...

  10. Java 生成ZIP文件

    public static byte[] fileToZip(){ ZipOutputStream append = null; ByteArrayOutputStream bos = new Byt ...