初学Linux应掌握的Shell命令

###基本操作

  • 模糊查询正在运行的进程:

    1
    $ps -ef|grep tomcat
  • 解压tar.gz:

    1
    $tar -xzvf abc.tar.gz
  • 修改环境变量:

    1
    2
    3
    $vi /etc/profile  //以root运行
    到文件末尾新增一行:export PATH="/home/abc/bin:$PATH",保存退出
    $source /etc/profile //使配置立即生效
  • 查找文件:

    1
    $find / -name abc.sh
  • 在后台运行程序(用户注销后仍然保持运行):

    1
    $nohup abc.sh &

###防火墙相关

####CentOS防火墙

  • 打开端口
    1
    2
    $/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT  
    $/etc/rc.d/init.d/iptables save

重启计算机后,防火墙默认已经开放了22这个端口。

  • 临时性的完全关闭防火墙,可以不重启机器:

    1
    2
    3
    $/etc/init.d/iptables status                // 查看防火墙状态
    $/etc/init.d/iptables stop // 本次关闭防火墙
    $/etc/init.d/iptables restart // 重启防火墙
  • 永久性关闭防火墙:

    1
    $chkconfig --level 35 iptables off   // 注意中间的是两个英式小短线;重启