Linux shell
1.查看占用端口80的进程并结束进程
netstat -lnp|grep 80
kill -9 进程号
2.在 /home 目录下的所有文件中查找包含 test 字符串的文件。
grep -r -e “test” /home
grep -i ‘字符串’ 文件 //linux不打开文件的情况下查找字符串,返回整行数据
3.防火墙
centos7
systemctl status firewalld.service //查看防火墙状态
systemctl stop firewalld.service //关闭运行的防火墙,一旦重启操作系统,防火墙就自动开启了
systemctl disable firewalld.service //禁止防火墙服务器
一、两个文件的交集、并集(前提条件:每个文件中不得有重复行)
取出两个文件的并集(重复的行只保留一份) cat file1 file2 | sort | uniq > file3
取出两个文件的交集(只留下同时存在于两个文件中的文件) cat file1 file2 | sort | uniq -d > file3
删除交集,留下其他的行 cat file1 file2 | sort | uniq -u > file3
二、两个文件合并
- 一个文件在上,一个文件在下 cat file1 file2 > file3
- 一个文件在左,一个文件在右 paste file1 file2 > file3
find查找文件
将目前目录及其子目录下所有延伸档名是 c 的文件列出来。
# find . -name "*.c"
将目前目录其其下子目录中所有一般文件列出
# find . -type f
将目前目录及其子目录下所有最近 20 天内更新过的文件列出
# find . -ctime -20
查找/var/log目录中更改时间在7日以前的普通文件,并在删除之前询问它们:
# find /var/log -type f -mtime +7 -ok rm {} \;
查找前目录中文件属主具有读、写权限,并且文件所属组的用户和其他用户具有读权限的文件:
# find . -type f -perm 644 -exec ls -l {} \;
为了查找系统中所有文件长度为0的普通文件,并列出它们的完整路径:
# find / -type f -size 0 -exec ls -l {} \;
linux centos7添加ip黑名单禁止某个ip访问
vim /etc/hosts.deny 添加你要禁止的ip就可以了
sshd:192.168.1.147:deny
linux下查询当前所有连接的ip
也可以使用 egrep 过滤多个条件 # netstat -ntu | egrep ‘tcp|udp’
使用 awk 将第五列单独截出来 :
netstat -ntu | grep tcp | awk “{print $5}”
使用 sort -n , 可以按照数字升序排
使用 head 或 tail 取头部几行或尾部几行 :