美文网首页笔记本📒
linux常用命令笔记

linux常用命令笔记

作者: 涓涓自然卷 | 来源:发表于2020-03-31 13:26 被阅读0次
    • 版本查看
      1、操作系统查看:cat /proc/version、cat /etc/redhat-release
      2、java版本:java -version
      3、scala版本:scala --version
      4、hive版本:lsod -g 15432 | grep hive-service 或 直接hive命令进入命令行
      5、python版本:python --version
    • 主机
      1、查看主机名:hostname
      2、修改主机名:hostnamectl set-hostname newhostname
      3、重启:reboot
      4、查看当前用户:whoami
      5、查看服务状态:sudo service httpd status

    • 文件
      1、查看文件大小:du -sh /*
      2、查找内容:grep -rn "你好" *

    • : 表示当前目录所有文件,也可以是某个文件名
      -r 是递归查找
      -n 是显示行号
      -R 查找所有文件包含子目录
      -i 忽略大小写

    3、合并小文件:cat 00* > data.txt

    • 列出文件
      1、根据时间递增顺序列出文件:ls -ltr
      2、根据时间递减顺序列出文件:ls -lt
    • 磁盘
      1、查看磁盘信息:fdisk -l
      2、查看磁盘使用情况:df -h
      3、lsblk
    • 端口相关
      1、查看端口是否能连接:telnet 10.5.1.110 8040
      2、查看开放的端口:netstat -ntpl
      3、查看显示网络连接、路由表和网络接口信息,可以让用户得知目前都有哪些网络连接正在运作:netstat -an
    • ps
      1、ps aux | grep 'elastic'
      2、history | grep metastore
      3、ll | grep metastore
      4、ps -ef | grep hive
    • grep
      1、grep '^[a-z]' kibana.yml :正则查找文件制定内容
      2、grep 'exeTime' 08-24-0850.log : 查找文件制定内容
      3、history | grep metastore : 查看指定的历史命令
      4、搜包:rpm -aq|grep java
    • 其他查看
      1、查看命令位置:whereis hbase
      2、查看命令目录:which java

    which 只能查看命令的目录,而whereis可以看到配置文件的存放位置;

    3、想查看命令的简要信息:whatis java
    4、查看登录用户:who
    5、列出目前与过去登入系统的用户信息:last
    6、先把所有用户列出来:lastlog

    • find
      1、查找包含slot_max_size 字符串的文件:find cfg/* | xargs grep "slot_max_size"
      2、查找目录下的所有文件中是否含有某个字符串:
      (1)find .|xargs grep -ri "IBM"
      (2)find .|xargs grep -ri "IBM" -l
      3、查找 n天内修改的(-ctime)文件:find /data/server/ -type f -ctime -1| xargs ls –l

    说明:
    (1) -type f 只搜索文件,不包含文件夹
    (2)ctime中的c-change的意思
    (3)-ctime +n: n天前修改的;-ctime –n:n天内修改的,修改日期过去n天的
    ctime参数指文件日期等状态性参数修改,mtime参数指内容改变:
    find . -type f -mtime -1| xargs ls –l

    • 查看内存
      1、free -g : 查看内存大小-m是兆,-g是g
      2、free -h -s 3
      3、free -h
      4、free -m
      5、cat /proc/meminfo | grep MemTotal
      6、查看cpu核数:cat /proc/cpuinfo | grep "cpu cores" | uniq
    • 用户组和用户
      1、groupadd esgroup
      2、useradd esuser -g esgroup -p espassword
      3、更改elasticsearch文件夹及内部文件的所属用户及组:
      4、chown -R esuser:esgroup elasticsearch-6.2.4
    • 防火墙
      (一)iptables.service
      1、查看防火墙状态:systemctl status iptables.service
      2、重启防火墙:systemctl restart iptables.service
      3、关闭防火墙:systemctl stop iptables.service
      4、先检查是否安装了iptables.service:

      首先查看iptables状态:service iptables status|stop|start --临时关闭
      - 安装iptables : yum install -y iptables
      - 升级iptables : yum update iptables
      - 安装iptables-services : yum install iptables-services
      - 永久关闭 : chkconfig iptables off

    5、vim /etc/sysconfig/iptables

    (二)firewalld
    (1)查看防火墙状态:firewall-cmd --state、systemctl status firewalld
    (2)开启防火墙:systemctl start firewalld
    (3)临时关闭防火墙:systemctl stop firewalld
    (4)永久关闭防火墙:systemctl disabled firewalld

    (三)其他:先 "netstat -ntpl | grep 端口 " 看这个端口有没有,如果有 telnet 这台服务器肯定能通。 如果在别的机器上 ping通但 telnet不通,肯定是防火墙的问题。
    防火墙可以配置规则,
    比如 某个ip段的都可以访问,某个端口可以对外开放等都可以配置

    • vi编辑器
      1、 :set number --设置编号
      2、 // --查找
      3、o --在末尾插入
      4、shift + g --跳至最后一行
      5、shift + a --跳至行末
      6、dd -- 删除一行
    • 压缩和解压
      1、zip压缩:zip -r xxx.zip ./*
      2、zip解压缩:unzip filename.zip
      3、tar压缩:tar -zcfv conf-spark.tar.gz ./conf
      4、tar解压缩:tar -zxvf hbase-2.0.2-bin.tar.gz
    • 远程
      1、远程复制:scp -r /opt/hadoop-2.7.3 192.168.172.72:/opt/hadoop-2.7.3
      2、远程拷贝:scp yarn-site.xml root@10.5.1.110:/usr/hadoop/etc/hadoop/
      3、ssh -p 端口号 user@ip

    • top
      1、top : 查看CPU个数:top之后按 数字 1 摁1 按c可以显示全,按 shift + m 是按照内存使用情况排序

    • 其他
      1、后台执行命令:nohup hive --service metastore 2>&1 >> metastore.log &
      2、ip查看:ifconfig -a
      3、切分文件:split -b 100M txt

    • ls
      1、模糊查询:ls *foo?ar

    会匹配“myfoobar”“foocar”和“thefoodar”这样的单词
    使用*通配符替代任何数量的字符(也可以不含)或者是使用?通配符替代单个字符

    相关文章

      网友评论

        本文标题:linux常用命令笔记

        本文链接:https://www.haomeiwen.com/subject/cxqwuhtx.html