zoukankan      html  css  js  c++  java
  • Linux基础学习-基本命令

    基本命令

    date命令

    参数 作用
    %t 跳格
    %H 小时(00-23)
    %I 小时(00-12)
    %M 分钟(00-59)
    %S 秒(00-59)
    %j 今年中的第几天
    [root@qdlinux Documents]# date
    Fri Aug 31 22:05:03 CST 2018
    
    [root@qdlinux Documents]# date "+%Y-%m-%d %H:%M-%S"
    2018-08-31 22:05-57
    
    [root@qdlinux Documents]# date "+%Y-%m-%d %I:%M-%S"
    2018-08-31 10:06-38
    
    [root@qdlinux Documents]# date "+%j"
    243
    
    

    wget命令

    参数 作用
    -b 后台下载模式
    -P 下载到指定的目录
    -t 最大尝试次数
    -c 断点续传
    -p 下载页面内所有资源,包括图片,视频等
    -r 递归下载
    [root@qdlinux Documents]# wget https://www. linux probe .com/docs/LinuxProbe.pdf
    
    

    ps命令

    参数 作用
    -a 显示所有进程(包括其他用户的进程)
    -u 用户以及其他详细信息
    -x 显示没有控制终端的进程
    [root@qdlinux Documents]# ps -aux
    
    

    top命令

    • R:正在运行,正在为用户提供服务
    • S:正在休眠,等待为用户提供服务
    • D:进程不可中断
    • Z:僵死,僵尸进程
    • T:已经停止
    [root@qdlinux Documents]# top
    top - 22:17:38 up 3 days, 13:27,  3 users,  load average: 0.02, 0.04, 0.07
    Tasks: 208 total,   1 running, 207 sleeping,   0 stopped,   0 zombie
    %Cpu(s):  0.5 us,  0.3 sy,  0.0 ni, 99.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
    KiB Mem :  2030172 total,    71556 free,   923720 used,  1034896 buff/cache
    KiB Swap:  2097148 total,  1944316 free,   152832 used.   810872 avail Mem 
    
       PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                   
     13292 root      20   0 2177072 204976  27668 S   1.0 10.1  52:20.88 firefox                                                                   
       560 root      20   0  320064   2836   2328 S   0.7  0.1  26:39.01 vmtoolsd                                                                  
     61616 root      20   0  161972   2320   1580 R   0.7  0.1   0:00.23 top                                                                       
       559 root      20   0   21664    964    804 S   0.3  0.0   2:53.58 irqbalance                                                                
      2154 root      20   0  488996  20652   3216 S   0.3  1.0   8:46.37 containerd                                                                
      2557 root      20   0  547932  29992   9424 S   0.3  1.5  14:19.50 dockerd                                                                   
     12950 root      20   0  731256   7456   2364 S   0.3  0.4   2:34.16 gsd-color                                                                 
     13092 root      20   0  402992   6844   2412 S   0.3  0.3  17:43.46 vmtoolsd                                                                  
     61020 root      20   0       0      0      0 S   0.3  0.0   0:11.00 kworker/0:0                                                               
         1 root      20   0  125632   3492   2172 S   0.0  0.2   0:35.90 systemd             
    
    [root@qdlinux Documents]# uptime
     22:29:43 up 3 days, 13:39,  3 users,  load average: 0.02, 2.05, 2.42
     
    
    
    [root@qdlinux Documents]# uname -a
    Linux qdlinux.com 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    
    [root@qdlinux Documents]# uname -snrvmpio
    Linux qdlinux.com 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    
    
    [root@qdlinux Documents]# free 
                  total        used        free      shared  buff/cache   available
    Mem:        2030172      704064      106192        6116     1219916     1044096
    Swap:       2097148      151296     1945852
    [root@qdlinux Documents]# free -m
                  total        used        free      shared  buff/cache   available
    Mem:           1982         687         103           5        1191        1019
    Swap:          2047         147        1900
    [root@qdlinux Documents]# free -h
                  total        used        free      shared  buff/cache   available
    Mem:           1.9G        687M        103M        6.0M        1.2G        1.0G
    Swap:          2.0G        147M        1.9G
    [root@qdlinux Documents]# free -k
                  total        used        free      shared  buff/cache   available
    Mem:        2030172      704176      106060        6116     1219936     1043984
    Swap:       2097148      151296     1945852
    
    

    wc命令

    参数 作用
    -l 只显示行数
    -w 只显示单词数
    -c 只显示字节数
    [root@qdlinux ~]# cat anaconda-ks.cfg | tr [a-z] [A-Z]
    
    [root@qdlinux ~]# wc -l /etc/passwd
    43 /etc/passwd
    
    [root@qdlinux ~]# wc -w /etc/passwd
    85 /etc/passwd
    
    [root@qdlinux ~]# wc -c /etc/passwd
    2245 /etc/passwd
    
    
    [root@qdlinux ~]# stat initial-setup-ks.cfg 
      File: ‘initial-setup-ks.cfg’
      Size: 1783      	Blocks: 8          IO Block: 4096   regular file
    Device: 803h/2051d	Inode: 67157617    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2018-08-31 22:39:00.663764363 +0800
    Modify: 2018-08-04 15:07:54.860635244 +0800
    Change: 2018-08-04 15:07:54.860635244 +0800
     Birth: -
    
    
    [root@qdlinux ~]# cat /etc/redhat-release
    CentOS Linux release 7.5.1804 (Core) 
    
    
    [root@qdlinux ~]# cut -d: -f1 /etc/passwd
    
    
    [root@qdlinux ~]# dd if=/dev/zero of=560_file count=1 bs=560M
    
    

    grep命令

    参数 作用
    -b 将可执行文件当做文本文件来搜索
    -c 仅显示找到的行数
    -i 忽略大小写
    -n 显示行号
    -v 反向选择
    -E
    
    

    find命令

    参数 作用
    -name 匹配名称
    -perm 匹配权限
    -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 匹配文件的大小
    -prune 忽略某个目录
    -exec {} ; 后面可跟用于进一步处理搜索结果的命令

    快照虚拟机网卡问题解决

    [root@www ~]# rm -f /etc/udev/rules.d/70-persistent-net.rules 
    

    CentOS6中设置开机自启动

    [root@www tools]# chkconfig --list sshd
    sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    [root@www tools]# echo /etc/init.d/sshd start >> /etc/rc.local 
    [root@www tools]# cat /etc/rc.local 
    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.
    
    touch /var/lock/subsys/local
    /etc/init.d/sshd start
    [root@www tools]# chkconfig --level 345 sshd off
    [root@www tools]# chkconfig --list sshd
    sshd           	0:off	1:off	2:on	3:off	4:off	5:off	6:off
    [root@www tools]# chkconfig --level 345 sshd on
    [root@www tools]# chkconfig --list sshd
    sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    
    

    linux启动流程

    1. Bios自检
    2. MBR引导
      0柱面0磁道1扇区 前446字节
    3. grub引导菜单
    4. 加载kernel
    5. 启动init进程
    6. 读取inittab文件

    开启需要的服务

    [root@www tools]# chkconfig --list | grep 3:on| egrep -v "sshd|sysstat|network|crond|rsyslog" | awk '{print "chkconfig",$1,"off"}'|bash
    
    
    [root@www tools]# chkconfig --list | grep 3:on | awk '{print "chkconfig",$1,"off"}'
    
    [root@www tools]# chkconfig --list | grep -E "sshd|rsyslog|network|sysstat|crond"|awk '{print "chkconfig",$1,"on"}'
    
    

    awk命令

    mkdir /tools
    cat /etc/passwd > /tools/awkfile.txt
    [root@www tools]# awk 'NR==1 {print NR,$1}' awkfile.txt 
    1 root:x:0:0:root:/root:/bin/bash
    
    awk -F ":" 'NR>=2&&NR<=5{print $1,$3}' /tools/awkfile.txt
    
    [root@www tools]# awk -F ":" 'NR==1 {print NR,$1,$NF}' awkfile.txt 
    1 root /bin/bash
    
    [root@www tools]# awk 'NR>=2 && NR<=5 {print NR,$1,$5}' awkfile.txt 
    2 bin:x:1:1:bin:/bin:/sbin/nologin 
    3 daemon:x:2:2:daemon:/sbin:/sbin/nologin 
    4 adm:x:3:4:adm:/var/adm:/sbin/nologin 
    5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin 
    
    

    chgrp命令

    [root@mail ~]# groupadd testgroup
    [root@mail ~]# mkdir testdir
    [root@mail ~]# ls
    anaconda-ks.cfg       testdir         公共  视频  文档  音乐
    initial-setup-ks.cfg  typechoDB.dump  模板  图片  下载  桌面
    [root@mail ~]# ls -ld testdir
    drwxr-xr-x. 2 root root 6 9月   8 19:37 testdir
    [root@mail ~]# chgrp testgroup testdir
    [root@mail ~]# ls -ld testdir
    drwxr-xr-x. 2 root testgroup 6 9月   8 19:37 testdir
    [root@mail ~]# chgrp -R testgroup testdir
    [root@mail ~]# ls -l testdir
    总用量 0
    -rw-r--r--. 1 root testgroup 0 9月   8 19:38 test
    
    
  • 相关阅读:
    易优CMS:compare的基础用法
    易优CMS:switch的基础用法
    2019年创意可爱卡通小清新教育课件培训PPT模板
    简约清新立体商务年终工作总结汇报动态PPT模板
    中国古风唯美水墨工作计划汇报PPT模板推荐
    新学期教育教学小学家长会PPT模板推荐
    遇见手绘花卉小清新简约通用PPT模板推荐
    简约清新日系你好五月通用PPT模板推荐
    清新简约风格毕业论文答辩PPT模板推荐
    C# 中=>符号的使用
  • 原文地址:https://www.cnblogs.com/qdlinux/p/9636797.html
Copyright © 2011-2022 走看看