1. awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.
语法: awk [-F|-f] 'pattern + action' file
-F分隔符
-f文件
pattern正则匹配
action if语句或者 print命令,print命令$0表示一行,$1表示第一个字符
参考 日期 9-23
2. Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.
语法:grep [options]
options参数:
-c:只输出匹配行的计数。
-l:查询多文件时只输出包含匹配字符的文件名。
-n:显示匹配行及 行号。
-s:不显示不存在或无匹配文本的错误信息。
-v:显示不包含匹配文本的所有行。
pattern正则表达式主要参数:
\: 忽略正则表达式中特殊字符的原有含义。
^:匹配正则表达式的开始行。
$: 匹配正则表达式的结束行。
\<:从匹配正则表达 式的行开始。
\>:到匹配正则表达式的行结束。
[ ]:单个字符,如[A]即A符合要求 。
[ - ]:范围,如[A-Z],即A、B、C一直到Z都符合要求 。
. :所有的单个字符。
* :有字符,长度可以为0。
参考 9-23
3.sed是利用脚本来处理文本文件,处理,编辑文本文件
语法:
sed [-hnV][-e<script>][-f<script文件>][文本文件]
示例:
在testfile文件的第四行后添加一行
sed -e 4a\newline testfile 只是打印输出到控制台,文件testfile没有写入这一行,如果想写入到文件,把e改为i
更多参考 9-25
4.ps 命令主要用到几个常见的命令,查看进程命令
ps -ef | grep python 查看运行的python程序
ps aux | head -n 3 查看运行的进程,显示前三个
其他的参考 9-26
5.netstat 是用于显示网络状态
语法; netstat [-acCeFghilMnNoprstuvVwx] [-A] [--ip]
一般用到 netstat -an | grep 1630 查看端口占用情况
参数说明参考
6.chown 将指定文件的拥有者改为指定的用户和组。
语法: chown [-cfhvR] [--help] [--version] user[:group] file
示例:将文件file1.txt的拥有者设为runob,群体的使用者runobgroup
chown runob:runobgroup file1.txt
7.apt-get 是一条linux命令,适用于deb包管理式的操作系统,主要用于自动从互联网的软件仓库中搜索、安装、升级、卸载软件或操作系统
常见命令:
apt-get install packagename #安装一个新软件包
apt-get remove packagename #卸载一个已安装的软件包(保留配置文档)
apt-get remove --purge packagename #卸载一个已安装的软件包(删除配置文档)
apt-get autoremove packagename #删除包及其依赖的软件包
apt-get autoremove --purge packagname #删除包及其依赖的软件包+配置文件,比上面的要删除的彻底一点
dpkg --force-all --purge packagename #有些软件很难卸载,而且还阻止了别的软件的应用,就能够用这个,但是有点冒险。
apt-get update 更新源列表
apt-get upgrade 更新软件包
8.date命令是linux日期命令,常用于时间查询,或者日期输出到日志文件
若是不以加号作为开头,则表示要设定时间
date命令查看 date --help
示列在 crontab中
* * * * * curl -xget 'localhost:9200' && date +\%y-\%m-\%d \%H-\%M-\%S 这个命令不对,中间的空格不能读取正确是
* * * * * curl -xget 'localhost:9200' && date +\%y-\%m-\%d\ \%H-\%M-\%S 在天和小时间的空格用\转义。
9.wc命令,wc --help查看命令帮助
Usage: wc [OPTION]... [FILE]...
or: wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. A word is a non-zero-length sequence of
characters delimited by white space.
With no FILE, or when FILE is -, read standard input.
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 maximum display width
-w, --words print the word counts
--help display this help and exit
--version output version information and exit
ju'lie统计文件夹下文件的个数,
ll | wc -l ,
10.find命令
find 查询24小时内修改过的文件 find -atime -1
根据关键字查询文件(文件夹) find -name "*han*"
只查询文件不包括文件夹 find -type f -name "*han*"
查询当前目录下的所有子目录 find . type d
查询当前目录下大于1k的文件 find . -type f -size +1000c
列出更加详细的文件信息组合命令 find . -type f -exec ls -l {} \;
把查找到的文件移动到指定目录 find . -type f -name "*han*" -exec mv {} hello
把查找到的文件复制到指定目录 find . -type f -name "*han*" -exec cp {} hello
查找当前目录文件并显示属于哪类文件 find . -type f --- xargs file
查找当面目录文件中包括关键字 find . -type f --- xargs grep "hank"
在a目录查询避开b目录查询 find a -path "b" -prune -o -print
优先在当前目录查找然后去子目录 find / -name "file" -