linux shell 脚本攻略学习16--wc命令详解,tree命令详解
linux shell 脚本攻略学习16--wc命令详解,tree命令详解
在文本处理的工作中,统计文件的行数,单词数和字符数非常有用。而对于开发人员本身来说,统计LOC(line of code ,代码行数)是一件重要的工作。linux中有什么命令可以帮助我们做统计呢?没错,就是wc,不是厕所的意思啊,是Word Count的缩写。
当作好统计时,又需要写个开发的文档,特别是项目比较大的时候,如果将目录和文件系统以图形化的树状层次结构描述,在以后的维护过程将更加清晰明了,下面将同样将要介绍的还有tree命令.
一、wc命令详解
首先,输入man wc 查看wc 的指导手册
- print newline, word, and counts each [OPTION]... --files0-from= counts each FILE, and a total line -, read standard input. A word is a non-zero- counts are printed, always -c, ---m, ---l, ----files0-from=-terminated names F; If F is - -L, --max-line--, ------
语法:
[OPTION]... --files0-from=F
参数-实例:
下面将通过实例介绍各参数的含义和作用:
用到的test.txt
amosli@amosli-pc:~/learn/$ counts each FILE, and a total line -, read standard input. A word is a non-zero- counts are printed, always , maximum line length.
1、-c参数,统计字节数,字符数
amosli@amosli-pc:~/learn/$ -c test.txt
test.txt
2.-l参数,统计行数
amosli@amosli-pc:~/learn/$ -l test.txt
test.txt
3.-w参数,统计单词数
amosli@amosli-pc:~/learn/$ - test.txt
test.txt
4.-L参数,统计最长行的长度
amosli@amosli-pc:~/learn/$ -L test.txt
test.txt
5.-m参数,统计字母数
amosli@amosli-pc:~/learn/$ -m test.txt
test.txt
6.不加参数
amosli@amosli-pc:~/learn/$ test.txt
test.txt
分别表示行数,单词数,字符数
7.使用标准输入进行统计
amosli@amosli-pc:~/learn/$ | -
二、tree命令详解
首先,sudo apt-get install tree安装一下tree命令
下面将输入tree --help查看提示信息:
amosli@amosli-pc:~/learn$ tree --help usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [--P pattern] [-I pattern] [-o filename] [--version] [--help] [----device] [--noreport] [--nolinks] [--dirsfirst] [----filelimit #] [<directory list>----f Print the full path prefix each -i Don -q Print non-printable characters as -N Print non--p Print the protections each -u Displays -g Displays -s Print the size bytes of each -h Print the size a -D Print the of -F Appends , , , or as per ---r Sort files -t Sort files by modification -----n Turn colorization off always (------T Replace the default HTML title and H1 header with -R Rerun tree when max -o Output to --inodes Print inode number of each --device Print device ID number to each --noreport Turn off /--nolinks Turn off hyperlinks ----charset X Use charset X --filelimit # Do not descend dirs with than # files them.
语法:
tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [--P pattern] [-I pattern] [-o filename] [--version] [--help] [----device] [--noreport] [--nolinks] [--dirsfirst] [----filelimit #] [<directory list>]
参数-实例:
-------F 在执行文件,目录,Socket,符号连接,管道名称名称,各自加上,,,,---------q 用----x 将范围局限在现行的文件系统中,若指定目录下的某些子目录,其存放于另一个文件系统上,则将该子目录予以排除在寻找范围外。
amosli@amosli-pc:~/learn/ tree . ├── d1 │ └── d2 │ └── d3 │ └── a.txt ├── d2 │ └── d2 │ └── d3 │ └── a.txt ├── db │ └── dc ├── directories, files
2、-P参数,对样式进行筛选
如,筛选.sh结尾的文件
amosli@amosli-pc:~/learn/re$ tree . -P
3、-h参数,打印出文件和目录的大小
amosli@amosli-pc:~/learn/re$ tree -h . ├── [.0K] ] test.] version. directories, files
4、-d参数,只显示目录
amosli@amosli-pc:~/learn/re$ tree -d . ├── d1 │ └── d2 │ └── d3 ├── d2 │ └── d2 │ └── d3 ├── db │ └── dc └── directories
5、-D参数,显示文件修改日期
amosli@amosli-pc:~/learn/re$ tree -D . ├── [Dec : : : : : : : : : : :] : :] test. : : :] version. directories, files
6、-i参数,不以阶梯状显示
amosli@amosli-pc:~/learn/re$ tree -i . d1 d2 d3 a.txt d2 d2 d3 a.txt db dc directories, files
7、其他参数可以根据自己需要去选择,更多信息请使用man tree查看tree命令手册.
评论暂时关闭