工作中经常会用到的linux命令
系统:
磁盘使用情况:df -l
查看端口占用:lsof -i:8000
查看端口网络情况:netstat -tunlp | grep 8000(t:tcp u:udp n:number l:listening p:programs)
查看进程:ps -ef|grep (process name)
查看指定进程占用情况:top -p 609
杀死进程:kill -9 609
查看用户和组列表:cat /etc/passwd cat /etc/group
防火墙:
iptables -L -n #查看防火墙规则列表
service iptables save #保存防火墙规则
iptables -A INPUT -p tcp --dport 22 -j ACCEPT #设置开放input端口
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT #设置开放output端口
iptables -A INPUT -p tcp -s 192.168.1.2 -j DROP #设置禁止端口orip
iptables -L -n --line-number #查看带行号的规则列表
iptables -D INPUT 2 #删除规则
Redis:
重启:
/etc/init.d/redis restart
Nginx:
检测:nginx -t
平滑重启:nginx -s reload
文件:
删除文件:rm -f file.name
移动文件:mv file.name /path/to/traget/
重命名文件:mv file.name modifyed.name
清空文件内容:cat /dev/null > file.name
软链:ln -s resource.name /path/to/file.name
复制文件:cp -ai file.name /path/to/file.name
动态查看:tail -f file.name
查找文件:find /path/ -name "file.name" 例如:php -i|grep "php.ini"
压缩:tar -zcvf test.tar.gz /test/
解压缩:tar -zxvf test.tar.gz
chmod:
chmod 751 file.name or (chmod u=rwx, g=rx, o=x file.name)
将目录及子目录的所有文件添加可读权限:chmod u+r, g+r, o+r -R /path/dir/
chown:
更改文件所属的主及组:chown www-data:www-data file.name or (chown www-data:www-data -R /test/path/file.name)
vi/vim:
显示行号::set nu(set number)
隐藏行号::set nonu(set nonumber)
搜索时忽略大小写::set ignorecase
搜索时匹配大小写::set smartcase
搜索: /word n(向下) N(向上)
回到内容顶部:gg
回到内容底部:G
删除/解切光标所在行:dd
复制:yy
向下翻页:ctrl+f
向上翻页:ctrl+b