• linux 简单记录2--linux命令


    man

    空格键 向下翻一页
    PaGe down 向下翻一页
    PaGe up 向上翻一页
    home 直接前往首页
    end 直接前往尾页
    / 从上至下搜索某个关键词,如“/linux”
    ? 从下至上搜索某个关键词,如“?linux”
    n 定位到下一个搜索到的关键词
    N 定位到上一个搜索到的关键词
    q 退出帮助文档

    常用系统工作命令

    [root@iscsi ~]# echo yhq.com
    yhq.com
    [root@iscsi ~]# date
    Wed Jun 17 15:55:16 CST 2020
    [root@iscsi ~]# date "+%Y-%m-%d %H:%M:%S"
    2020-06-17 15:55:40
    [root@iscsi ~]# date "+%j" ##一年当中的第几天
    169
    #reboot
    #poweroff
    wget 终端下载网络文件
    -b 后台下载模式
    -P 下载到指定目录
    -t 最大尝试次数
    -c 断点续传
    -p 下载页面内所有资源,包括图片、视频等
    -r 递归下载
    # wget -r -p http://www.linuxprobe.com
    ps 查看系统进程状态
    -a 显示所有进程(包括其他用户的进程)
    -u 用户以及其他详细信息
    -x 显示没有控制终端的进程
    R(运行): 进程正在运行或在运行队列中等待。
    S(中断): 进程处于休眠中,当某个条件形成后或者接收到信号时,则脱离该状态。
    D(不可中断): 进程不响应系统异步信号,即便用 kill 命令也不能将其中断。
    Z(僵死): 进程已经终止,但进程描述符依然存在, 直到父进程调用 wait4()系统函数后将进程释放。
    T(停止): 进程收到停止信号后停止运行。
    top 用于动态监视进程活动与系统负载等信息
    pidof 用于查询某个指定服务进程的pid值
    [root@iscsi ~]# pidof sshd
    16363 976
    [root@iscsi ~]# pidof mongod
    1036
    [root@iscsi ~]# ps -ef|grep mongod
    root       1036      1  0 Jun16 ?        00:06:57 /usr/bin/mongod -f /home/data/mongodb/mongodb.conf
    root      16980  16369  0 16:09 pts/0    00:00:00 grep --color=auto mongod
    kill 用于终止某个指定pid的服务进程
    killall 用于终止某个指定名称的服务所对应的全部进程
    ifconfig
    uname -a
    uptime
    [root@iscsi ~]# uptime
     16:13:04 up 1 day, 42 min,  1 user,  load average: 0.00, 0.03, 0.05
    free
    who
    last
    history 默认保存最近的1000命令,可修改/etp/profile中HISTSIZE=1000
    history -c 清空,历史命令会被保存到用户根目录的.bash_history文件中
    sosreport 用于收集系统配置及架构信息并输出诊断文档
    pwd
    cd
    ls /ls -al
    [root@iscsi ~]# ls -ld /etc/ #查看目录属性信息
    drwxr-xr-x. 137 root root 8192 Jun 17 16:15 /etc/
    cat -n file
    more 
    head -n 10
    tail -n 20
    tail -f 
    cat xxx | tr [a-z] [A-Z] #替换文本中的字符 tr 原始字符目标字符
    wc 统计指定文本的行数、字数、字节数
    -l 只显示行数
    -w 只显示单词数
    -c 只显示字节数
    [root@iscsi opt]# stat test.txt #用于查看文件的具体存储信息和时间等信息
      File: ‘test.txt’
      Size: 17            Blocks: 8          IO Block: 4096   regular file
    Device: 802h/2050d    Inode: 69411794    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2020-06-16 17:20:23.311721421 +0800
    Modify: 2020-06-16 17:20:02.876611035 +0800
    Change: 2020-06-16 17:20:02.876611035 +0800
    [root@iscsi opt]# head -n 2 /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin
    [root@iscsi opt]# cut -d: -f1 /etc/passwd #按“列”提取文本字符
    root
    bin
    daemon
    adm
    diff 用于比较多个文本文件的差异
    diff --brief a.txt b.txt #判断文件是否相同
    diff -c a.txt b.txt #描述文件内容具体的不同
    touch #用于创建空白文件或设置文件的时间
    -a 仅修改“读取时间”(atime)
    -m 仅修改“修改时间”(mtime)
    -d 同时修改 atime 与 mtime
    [root@iscsi opt]# touch yhq
    [root@iscsi opt]# ls -l yhq 
    -rw-r--r-- 1 root root 0 Jun 18 09:58 yhq
    [root@iscsi opt]# echo "yhq isuer avc" >>yhq
    [root@iscsi opt]# ls -l yhq 
    -rw-r--r-- 1 root root 14 Jun 18 09:59 yhq
    [root@iscsi opt]# touch -d "2020-07-01 11:24" yhq 
    [root@iscsi opt]# ls -l yhq 
    -rw-r--r-- 1 root root 14 Jul  1  2020 yhq
    [root@iscsi opt]# touch -d "2020-06-01 11:24" yhq 
    [root@iscsi opt]# ls -l yhq 
    -rw-r--r-- 1 root root 14 Jun  1 11:24 yhq
    mkdir 创建目录
    mkdir -p /opt/a/backup #-p 递归迭代
    mkdir -p /opt/b/{backup,scripts,logs}
    [root@iscsi opt]# mkdir -p /opt/b/{backup,scripts,logs}
    [root@iscsi opt]# ll /opt/b/
    total 0
    drwxr-xr-x 2 root root 6 Jun 18 10:06 backup
    drwxr-xr-x 2 root root 6 Jun 18 10:06 logs
    drwxr-xr-x 2 root root 6 Jun 18 10:06 scripts
    cp 复制文件或目录
    -p 保留原始文件的属性
    -d 若对象为“链接文件”,则保留该“链接文件”的属性
    -r 递归持续复制(用于目录)
    -i 若目标文件存在则询问是否覆盖
    -a 相当于-pdr(p、 d、 r 为上述参数)
    mv 剪切文件或重命名
    mv a.log c.log
    rm 删除文件或目录
    rm -f a.txt
    rm -rf /opt/b/backup
    dd 用于按照指定大小和个数的数据块来复制文件或转换文件
    if 输入的文件名称
    of 输出的文件名称
    bs 设置每个“块”的大小
    count 设置要复制“块”的个数
    [root@iscsi opt]# dd if=/dev/zero of=56_file count=1 bs=56M
    1+0 records in
    1+0 records out
    58720256 bytes (59 MB) copied, 0.668979 s, 87.8 MB/s
    [root@iscsi opt]# ll -h 56_file 
    -rw-r--r-- 1 root root 56M Jun 18 10:28 56_file
    # dd if=/dev/cdrom of=RHEL-server-7.0-x86_64-LinuxProbe.Com.iso #使用dd命令来压制出光盘镜像文件
    file #用于查看文件的类型
    [root@iscsi opt]# file yhq 
    yhq: ASCII text
    [root@iscsi opt]# file /dev/sda
    /dev/sda: block special
    tar 对文件进行打包压缩或解压,主要使用.tar,.tar.gz,tar.bz2格式
    -c 创建压缩文件
    -x 解开压缩文件
    -t 查看压缩包内有哪些文件
    -z 用 Gzip 压缩或解压
    -j 用 bzip2 压缩或解压
    -v 显示压缩或解压的过程
    -f 目标文件名
    -p 保留原始的权限与属性
    -P 使用绝对路径来压缩
    -C 指定解压到的目录
    -c 和-x不能同时使用,-f必须放到参数的最后一位。
    tar -czvf 压缩包名称.tar.gz 要打包的目录 #把指定的文件进行打包压缩
    tar -xzvf 压缩包名称.tar.gz
    # tar -czvf etc.tar.gz /etc
    # tar xzvf etc.tar.gz -C /root/etc
    grep 用于在文本中执行关键词搜索,并显示匹配的结果
    -b 将可执行文件(binary)当作文本文件(text)来搜索
    -c 仅显示找到的行数
    -i 忽略大小写
    -n 显示行号
    -v 反向选择—仅列出没有“关键词”的行
    [root@iscsi opt]# grep /sbin/nologin /etc/passwd
    bin:x:1:1:bin:/bin:/sbin/nologin
    daemon:x:2:2:daemon:/sbin:/sbin/nologin
    find 用于按照指定条件来查找文件
    -name 匹配名称
    -perm 匹配权限(mode 为完全匹配, -mode 为包含即可)
    -user 匹配所有者
    -group 匹配所有组
    -mtime -n +n 匹配修改内容的时间(-n 指 n 天以内, +n 指 n 天以前)
    -atime -n +n 匹配访问文件的时间(-n 指 n 天以内, +n 指 n 天以前)
    -ctime -n +n 匹配修改文件权限的时间(-n 指 n 天以内, +n 指 n 天以前)
    -nouser 匹配无所有者的文件
    -nogroup 匹配无所有组的文件
    -newer f1 !f2 匹配比文件 f1 新但比 f2 旧的文件
    --type b/d/c/p/l/f 匹配文件类型(后面的字幕参数依次表示块设备、目录、字符设备、管道、链接文件、文本文件)
    -size 匹配文件的大小(+50KB 为查找超过 50KB 的文件,而-50KB 为查找小于 50KB 的文件)
    -prune 忽略某个目录
    -exec …… {}; 后面可跟用于进一步处理搜索结果的命令(下文会有演示)
    [root@iscsi opt]# find /etc/ -name "host*"
    /etc/host.conf
    /etc/hosts
    [root@iscsi opt]# find / -perm -400 -print #搜索权限包括SUID权限的所有文件
    # find / -user yhq -exec cp -a {} /root/findresults/ ;#找出属于yhq用户的文件并复制到/root目录
  • 相关阅读:
    微信支付Native扫码支付模式二之CodeIgniter集成篇
    如何使用硬盘安装debian8.3?
    使用git将代码push到osc上
    树莓派(Raspberry Pi)搭建简单的lamp服务
    win下修改mysql默认的字符集以防止乱码出现
    CodeIgniter2.2.0-在控制器里调用load失败报错的问题
    Ubuntu Server(Ubuntu 14.04 LTS 64位)安装libgdiplus2.10.9出错问题记录
    linux下mono的安装与卸载
    asp.net中ashx生成验证码代码放在Linux(centos)主机上访问时无法显示问题
    使用NPOI将数据导出为word格式里的table
  • 原文地址:https://www.cnblogs.com/yhq1314/p/13158605.html
Copyright © 2020-2023  润新知