• linux 基础知识及命令总结


    1.mkdir   创建目录 -p 创建多级目录  mkdir -p /data/test

    -m, --mode=模式 设置权限模式(类似chmod),而不是rwxrwxrwx 减umask

    -p, --parents 需要时创建目标目录的上层目录,但即使这些目录已存在也不当作错误处理

    • [root@wen data]# mkdir test/test{1..3} -p  #创建一个目录再在下面创建几个目录

    [root@wen data]# tree test

    test

    ├── test1

    ├── test2

    └── test3

    2.ls    list  查看目录文件  ls /etc/目录

    -l (long)长格式,-d 查看目录

    -i inode节点号 , -h 人类可读

    3.cd cd /etc  切换目录路径

    4.pwd   显示当前所在目录

    5.touch 创建文件,不存在即创建,存在就改变访问时间戳,atime

    6.echo   打印输出内容,配合 >(重定向,会清除之前内容),>>(在尾部追加内容) 可以为文件追加内容

    [root@wen 926]# echo {1..9}

    1 2 3 4 5 6 7 8 9

    • [root@wen data]# cat >fade.txt

    fade walk

    ^C

    [root@wen data]# cat fade.txt

    fade walk

    • [root@wen data]# cat >>fade.txt<<efo  #efo 可以是任意字符

    > i am studing linux

    > efo

    [root@wen data]# cat fade.txt

    fade walk

    i am studing linux

    • [root@wen data]# echo mygirl 1>walk.txt 2>&1  #正确,错误都输入到walk.txt

    [root@wen data]# cat walk.txt

    mygirl

    [root@wen data]# ech mygirl 1>walk.txt 2>&1   #正确,错误都输入到walk.txt,等同于 &>1

    [root@wen data]# cat walk.txt

    -bash: ech: command not found

    • [root@wen data]# echo  mygirl &>>walk.txt     #追加

    [root@wen data]# cat walk.txt

    -bash: ech: command not found

    mygirl

    [root@wen data]# ech  mygirl &>>walk.txt

    [root@wen data]# cat walk.txt

    -bash: ech: command not found

    mygirl

    -bash: ech: command not found

    • [root@wen data]# ech  mygirl 1>>walk.txt 2>>walk.txt   #重定向前面的数字要紧跟着

    [root@wen data]# cat walk.txt

    -bash: ech: command not found

    mygirl

    -bash: ech: command not found

    -bash: ech: command not found

    7.cat  查看文件内容 cat fade.txt

    -n 匹配排序,cat /rtc/log -n

    [root@wen data]# cat walk.txt -n

         1        -bash: ech: command not found

         2        mygirl

         3        -bash: ech: command not found

         4        -bash: ech: command not found

     

    8.vi windows记事本,简单    vim 复杂编辑器,功能复杂,高亮,自动缩进(写shell/python脚本用)

    9.xargs  从标准输入获取内容创建和执行命令  -n 数字,分组

    10.cp  copy  拷贝文件或目录,默认不能拷贝目录,   -r :递归,用于复制目录

    -a :相当于-pdr,  -p:连同档案的属性一起复制过去,而非使用默认属性

    • [root@wen data]# touch test.txt

    [root@wen data]# touch /data/926/test.txt

    [root@wen data]# cp /data/test.txt /data/926/test.txt

    cp:是否覆盖"/data/926/test.txt"? y

    [root@wen data]# cp /data/test.txt /data/926/test.txt              #cp,不再提示覆盖与否,… m ,mv

    [root@wen data]# /bin/cp /data/test.txt /data/926/test.txt          #不再提示覆盖与否

     

    11.rm  remove 删除目录和文件 -f(force)强制,-r 递归,用于删除目录 

    rm -fr "文件名" 强制删除目录不提示,非常危险

    强调:删除命令要慎用,非常危险,删除前一定要先备份一份

    • [root@wen data]# touch stu{0..6}

    [root@wen data]# find /data -type f -name "stu*" |xargs

    /data/stu1 /data/stu4 /data/stu6 /data/stu3 /data/stu2 /data/stu0 /data/stu5

    [root@wen data]# find /data -type f -name "stu*" |xargs -n 1

    /data/stu1

    /data/stu4

    /data/stu6

    /data/stu3

    /data/stu2

    /data/stu0

    /data/stu5

    [root@wen data]# find /data -type f -name "stu*" |xargs -n 2  #分组

    /data/stu1 /data/stu4

    /data/stu6 /data/stu3

    /data/stu2 /data/stu0

    /data/stu5

    • [root@wen data]# find /data -type f -name "stu*" |xargs rm -f    #find找到,管道xargs删除
    • [root@wen data]# touch stu{0..6}

    [root@wen data]# find /data -type f -name "stu*" -exec rm {} ;  #另一种删除方法

    [root@wen data]# ls

     

    12.mv   move 移动文件和目录

    14.find   查找  -type 文件类型(f(file),d(diretory),c(character),b(block),s(socket),l(link))

    -name  "文件名",-mtime 时间,按修改时间查找,时间数字

    +7 7天以前  7 第7天  -7最近7天

    15.*grep   linux三剑客老三  过滤需要的内容,-v 排除内容 

    -C #除了显示匹配行外,显示该行前后的num行

    -B #除了显示匹配行外,显示该行之前的num行

    -A #除了显示匹配行外,显示该行之后的num行       例子查看19-(5)

    • [root@wen data]# cat fade.txt

    fade walk

    i am studing linux

    [root@wen data]# grep -v fade fade.txt

    i am studing linux

    [root@wen data]# grep -v f fade.txt

    i am studing linux

    [root@wen data]# grep -v i fade.txt

    fade walk

    [root@wen data]# grep fade fade.txt

    fade walk

    16.head    头,头部   读取文件的前n行,默认前10行,-n 数字,习惯-5,忽略-n

    17.tail   尾巴       输出文件的后n行,默认后10行,-n 数字,习惯-5,忽略-n

    [root@wen data]# seq 20 > num.txt

    [root@wen data]# head num.txt

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    [root@wen data]# tail num.txt

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    [root@wen data]# head -3 num.txt

    1

    2

    3

    [root@wen data]# tail -3 num.txt

    18

    19

    20

    18.alias   查看设置别名,unalias取消别名

    • [root@wen data]# alias rm='echo this command does not allow to use'

    [root@wen data]# alias|grep rm

    alias rm='echo this command does not allow to use'

    [root@wen data]# rm

    this command does not allow to use

    定义别名永久生效:  /etc/profile  全局生效   ~/.bashrc  当前用户生效

    分享链接 http://oldboy.blog.51cto.com/2561410/699046

    19.seq   序列

    [root@wen data]# seq -s '*' 10   #以"*"为间隔符

    1*2*3*4*5*6*7*8*9*10

    [root@wen data]# seq 1 2 10      #以1为起点,2为间隔,10为终点

    1

    3

    5

    7

    9

    [root@wen data]# seq 0 2 10

    0

    2

    4

    6

    8

    10

    • [root@wen data]# seq 100 >ett.txt     #查看ett.txt内第20到25行的内容(常见考题)

    1. [root@wen data]# head -25 ett.txt|tail -6

    20

    21

    22

    23

    24

    25

    2. [root@wen data]# sed -n '20,25p' ett.txt  #更高效的方法

    20

    21

    22

    23

    24

    25

    3. [root@wen data]# awk '19<NR && NR<26' ett.txt

    20

    21

    22

    23

    24

    25

    4. [root@wen data]# awk '{if(NR >19 && NR< 26) printf $0 " "}' ett.txt

    20

    21

    22

    23

    24

    25

    5. [root@wen data]# grep 22 -C 2 ett.txt  #除了显示匹配行外,显示该行前后的num行

    20

    21

    22

    23

    24

    6. [root@wen data]# grep 25 -B 5 ett.txt  #除了显示匹配行外,显示该行之前的num行

    20

    21

    22

    23

    24

    25

    7. [root@wen data]# grep 20 -A 5 ett.txt  #除了显示匹配行外,显示该行之后的num行

    20

    21

    22

    23

    24

    25

     

     

    20.sed    linux三剑客老二,流编辑器,实现对文件的增删改替换查  s,g常联合使用,表示对当前进行全局匹配替换

    参数 -n 取消默认输出, -c 允许多项编辑, -I 修改文件内容

    [root@wen data]# echo mygirl >>fade.txt

    [root@wen data]# sed -i 's#mygirl#jujingyi#g' fade.txt

    [root@wen data]# cat fade.txt

    fade walk

    i am studing linux

    jujingyi

    • [root@wen data]# echo dream-girl{01..04} > /data/girl/del.sh

    [root@wen data]# find /data -type f -name '*.sh' |xargs cat

    dream-girl01 dream-girl02 dream-girl03 dream-girl04

    [root@wen data]# find /data -type f -name '*.sh' |xargs sed 's#dream-girl*#jujingyi#g'

    jujingyi01 jujingyi02 jujingyi03 jujingyi04

    [root@wen data]# find /data -type f -name '*.sh' |xargs sed 's#.*#jujingyi#g'

    jujingyi

    [root@wen data]# find /data -type f -name '*.sh' |xargs sed -i 's#dream*#jujingyi#g'

    [root@wen data]# find /data -type f -name '*.sh' |xargs cat

    • jujingyi-girl01 jujingyi-girl02 jujingyi-girl03 jujingyi-girl04

    [root@wen data]# echo dream-girl{01..04} > /data/girl/del.sh

    [root@wen data]# sed -i 's#dream-*#beautiful#g' `find /data -type f -name '*.sh'`  #替换方法二

    [root@wen data]# find /data -type f -name '*.sh' |xargs cat

    beautifulgirl01 beautifulgirl02 beautifulgirl03 beautifulgirl04

    21.linux系统查看命令帮助的手段

    a.man 命令名/配置文件 b.命令 --help (稍微简单的帮助)  c.搜索引擎“linux 命令名”,info  d.help 命令名,特殊bash内置命令

    22.常用快捷键

    Ctrl +c 终止当前任务命令或程序

    Ctrl +d退出当前用户环境,相当于

    Ctrl +l 清屏,相当于clear命令

    23.查看系统64位,内核

    [root@wen data]# cat /etc/redhat-release

    CentOS release 6.7 (Final)

    [root@wen data]# uname -r

    2.6.32-573.el6.x86_64

    [root@wen data]# uname -m

    x86_64

    24.tree 查看目录结构   没有则安装 yum -y install tree

    tree -L 1 ,查看当前下一层目录

    25.linux 基础知识

    一,分区

    一块硬盘:主分区,扩展分区,逻辑分区

    主分区+扩展分区的数量 <= 4,其中一个主分区可以用一个扩展分区,扩展分区最多只能有一个

    扩展分区不能直接使用,还需要在上面创建逻辑分区,逻辑分区可有多个

    主分区 + 扩展分区 编号只能1~4,逻辑分区的编号只能从5开始

     

    1.常规分区:数据不是特别重要的业务(集群的某个节点)

    /boot  引导分区 200M

    swap   交换分区  内存的1.5倍,内存大于 8G,就给 8~16G

    /      根分区,所有目录顶点  剩余所有空间

    2.数据重要(数据库,存储服务区)

    /boot  引导分区 200M

    swap   交换分区  内存的1.5倍,内存大于 8G,就给 8~16G

    /      根分区,所有目录顶点  100~200G

    /data  所有,存放数据

    3.特大网站,门户(产品线特别多,需求)

    /boot  引导分区 200M

    swap   交换分区  内存的1.5倍,内存大于 8G,就给 8~16G

        /      根分区,所有目录顶点  100~200G

    剩余空间不分配,哪个部门领到了服务器,根据需求再进行分区

    二,硬盘

    • 系统的第一块IDE接口的硬盘称为  /dev/had
    • 系统的第二块IDE接口的硬盘称为  /dev/hdb
    • 系统的第一块SCSI接口的硬盘称为  /dev/sda
    • 系统的第二块SCSI接口的硬盘称为  /dev/sdb

    价格与性能:SSD>SAS>SATA

     

    三,其他硬件

    1.网站PC服务器

    Dell(普遍)

    1u = 4.45cm---->R420,410,620,630

    2u--->R730,720,710

    2.raid卡及其介绍

    详见linux笔记

    26.stat  查看目录或文件的状态   display file or file system status

    27.检查网络服务

    ssh服务是否好的 检测办法:从哪个机器连就在那个机器上操作

    telnet 192.168.59.131 22(服务器的IP和port)在windows上操作

    不通的可能原因:

    a.物理链路是否有问题,ping 192.168.59.131 

    b.服务器端防火墙阻挡

    [root@wen data]# /etc/init.d/iptables stop

    iptables:将链设置为政策 ACCEPT:filter                    [确定]

    iptables:清除防火墙规则:                                 [确定]

    iptables:正在卸载模块:                                   [确定]

    c.端口没有开放,服务器没有监听你连接的端口

    [root@wen data]# netstat -lntup |grep 22  #以ssh服务22端口为例

    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1503/sshd          

    tcp        0      0 :::22                       :::*                        LISTEN      1503/sshd          

    [root@wen data]# netstat -lntup |grep sshd

    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1503/sshd          

    tcp        0      0 :::22                       :::*                        LISTEN      1503/sshd          

    [root@wen data]# /etc/init.d/sshd restart    #重启ssh服务

    • 网卡配置     刚安装的linux 网络服务默认是关闭的,需要手动调整

     #更改配置文件将ONBOOT=no改成yes

    [root@wen data]# sed -i 's#ONBOOT=no#ONBOOT=yes#g' /etc/sysconfig/network-scripts/ifcfg-eth0

    [root@wen data]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE=eth0

    TYPE=Ethernet

    ONBOOT=yes

    [root@wen data]# service network restart   #重启网络服务生效

    • 小节:linux客户端DNS可以在网卡配置文件里设置(ifcfg-eth0)

    linux客户端DNS也可以在/etc/resolv.conf里设置

    网卡里的设置DNS优先于/etc/resolv.conf,如果重启网络网卡的DNS会覆盖/etc/resolv.conf的设置

    • [root@wen ~]# cat /etc/resolv.conf

    ; generated by /sbin/dhclient-script

    search localdomain

    nameserver 192.168.59.2          #DNS

    [root@wen ~]# /etc/init.d/network restart    #重启网卡

    [root@wen ~]# setup "network configuration" "DNS configuration"  就是修改/etc/resolv.conf

     

    28.rz,上传 sz,下载命令 可执行 yum install lrzsz -y yum groupinstall 或 "Dial-up Networking Soupport" -y 命令来安装

    29.su  切换用户  su 和 su -的区别

    30.linux 命令提示符由PS1 环境变量控制

    [root@wen data]# set|grep PS1

    PS1='[u@h W]$ '

    [root@wen data]# PS1='[u@h W ]$ '   #可以通过全局变量配置/etc/profile,使其永久生效

    [root@wen data01:35:17]#                #提示符添加显示时间

    31.克隆机   1).编辑eth0的配置文件:

    [root@wen data01:4]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

    删除 HWADDR=00:0c:29:e9:95:dd 和 UUID

          2).如果有必要再清空如下文件:

     > /etc/udev/rules.d/70-persistent-net.rules

    3).最后reboot

     

  • 相关阅读:
    读取XML并绑定至RadioButtonList
    获取客户端IP地址
    Repeater控件数据导出Excel
    验证用户必选CheckBox控件
    限制CheckBoxList控件只能单选
    获取客户端电脑名称
    获取Repeter的Item和ItemIndex
    获取DataList控件的主键和索引
    InsusExportToExcel Library
    ASP.NET网页打印
  • 原文地址:https://www.cnblogs.com/wenyule/p/7683772.html
Copyright © 2020-2023  润新知