1.删除文件夹下的文件
rm -rf /目录/*
若目录下文件太多,执行此命令会报/bin/rm Argument list too long.的错误提示,可进入要删除的目录然后执行以下命令:ls | xargs -n 10 rm -fr ls
2.搜索文件内容
2.1统计匹配次数
grep -o "匹配字符串" 文件|wc -l
2.2搜索并显示匹配内容
grep "匹配字符串" 文件
2.3搜索并显示匹配内容出现的文件及次数
grep -l "2016-12-06 " ./* | xargs grep -c "str" ./*
3.两台服务器之前拷贝文件及文件夹
scp 本地用户名 文件名 1 远程用户名 IP 地址 : 文件名 2
如:scp -r -P 22 /home/app/srcdir 192.168.0.55:/data/app
4.tail 分页
tail -n 3000 /home/logs/productor_58ad/info/info |more -100
从末尾返前3000行的位置,往下找100行 ctrl+f快捷键翻页
如:tail -n 20000 /home/logs/consume_event/tomcat-logs/catalina.out |more -70
5.复制文件夹
cp -R file1 file2
6.解压压缩
6.1解压
tar -zxvf name.tar.bz2 -C./test/
6.2压缩
压缩 man.config 用最佳的压缩比压缩,并保留原本的文件
[root@linux tmp]# gzip -9 -c man.config > man.config.gz
tar -xzvf filename
压缩文件,排除指定目录
tar -zcvf project.tar.gz --exclude=lib --exclude=upload folder
7.查看文件夹大小
du -sh 查看当前目录容量总和
du -h 查看当前目录每个文件夹大小
du -h |grep G 只列出1GB以上的文件目录(不包括非本分区的)
du -lh --max-depth=1 查看当前目录下一级子文件和子目录占用的磁盘容量。
8.统计文件内容中指定字符出现次数:
awk -v RS='str' 'END {print --NR}' filepath
9.查看目录下文件数,包括子目录下的文件
ls -lR|grep "^-"|wc -l
10.查看指定文件前N行
awk 'NR==1' info.3
11.查看端口占用:netstat -tunlp|grep
12.查看Nginx并发进程数:ps -ef | grep nginx | wc -l
13.查看Web服务器TCP连接状态:netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
14.查看进程对应程序的目录:ll /proc/21547
15.验证nginx gzip 配置:
curl -I -H "Accept-Encoding: gzip, deflate" "http://domain"
16.查看文件显示1000到300行的内容:sed -n '1000,3000p' filename
17.安装nginx时运行./configure --prefix=/usr/local/nginx报错解决办法:
报错如下:
[root@localhost nginx-1.8.1]# ./configure --prefix=/usr/local/nginx
checking for OS
+ Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
解决步骤:
[root@localhost nginx-1.8.1]# yum -y install gcc gcc-c++ autoconf automake libtool make install zlib zlib-devel openssl openssl-devel pcre pcre-devel
/home/myuser/source/mod_auth_cas/mod_auth_cas/missing: line 81: aclocal-1.15: command not found
WARNING: 'aclocal-1.15' is missing on your system.
You should only need it if you modified 'acinclude.m4' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'aclocal' program is part of the GNU Automake package:
<http://www.gnu.org/software/automake>
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
<http://www.gnu.org/software/autoconf>
<http://www.gnu.org/software/m4/>
<http://www.perl.org/>
make: *** [aclocal.m4] Error 127
Then I need to run autoconf:
$ autoreconf -f -i
18.开放端口:iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
12.清空日志文件不重启:echo "" > 文件路径