Linux常用命令

来源:互联网 发布:手机建站cms 编辑:程序博客网 时间:2024/06/06 03:53

1、查看活动端口

netstat -ntpl


2、查看防火墙防御日志

iptables -vnL


3、关闭防火墙

sudo ufw disable  Ubuntu


server iptables stop


4、使用Navicat链接mysql

1mysql -uroot -p,回车后提示你输密码,输入密码

2授权:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 你的密码  WITH GRANT OPTION;

3)操作完后切记执行以下命令刷新权限 
  FLUSH PRIVILEGES

4)重启mysql服务

service mysql restart

5)关闭防火墙

       service iptables stop  cenos下)


5、端口转发

lunix下,非root用户不能监听1024以上的端口号

80端口转发到8080

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080  

重启Tomcat

service tomcat restart

 

6、寻找文件

find / -name *index.html*

 

7、使用nginx配置端口转发

进入文件夹usr/local/nginx/conf

编辑文件vi nginx.conf

server {
listen 80;
server_name localhost;

location / {
    proxy_pass http://127.0.0.1:8080 ;
    proxy_set_header Host $host:80;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Via "nginx";

}
}

80端口转发到本地的8080端口

 8、查看网页源代码

curl http://www.baidu.com

将代码保存到文件中

curl http://www.baidu.com>page.html

下载资源

curl -o  1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG




###########################分界线##########################################


8、查看网页源代码




3、进程操作(ps)


显示当前所有进程环境变量及进程间关系
ps -ef


显示当前所有进程
ps -A


找出与 cron 与 syslog 这两个服务有关的 PID 号码
ps aux | grep '(cron|syslog)'


杀死进程


先使用ps查找进程pro1,然后用kill杀掉
kill -9 $(ps -ef | grep pro1)



4、关闭防火墙


server iptables stop


5、解压文件(tar)


tar zxvf filename.tar.gz


将/etc下的所有文件及目录打包到指定目录,并使用gz压缩
tar -zcvf /tmp/etc.tar.gz /etc


6、显示磁盘使用情况(df)


df -l
以易读方式列出所有文件系统及其类型
df -haT


7、文本搜索(grep)


查找指定进程
ps -ef | grep svn


从文件中读取关键词
cat test1.txt | grep -f key.log


从文件夹中递归查找以grep开头的行,并只列出文件
grep -lR '^grep' /tmp


8、内存使用情况

free



 

curl http://www.baidu.com