栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 系统运维 > 运维 > Linux

从零学习网络运维Linux-day11

Linux 更新时间:发布时间: 百科书网 趣学号

特殊符号; && ||

  • ;#命令分割符 无论前面命令是否执行成功,都会继续执行后面命令

    [root@theboy82 ~]# touch 88.txt;ll 88.txt
    -rw-r--r--. 1 root root 0 May 13 10:04 88.txt
    ​
    [root@theboy82 ~]# touh 22.tt;ll 22.txt
    -bash: touh: command not found
    ls: cannot access 22.txt: No such file or directory

  • &&#前面的命令执行成功 才可之后&&后面的命令

    &&#前面的命令执行成功 才可之后&&后面的命令
    [root@theboy82 ~]# mkdir linux&&ll linux
    mkdir: cannot create directory ‘linux’: File exists
    ​
    [root@theboy82 ~]# ll linux&&mkdir linux
    total 0
    drwxr-xr-x. 3 root root 18 Apr 28 22:07 wh
    mkdir: cannot create directory ‘linux’: File exists
  • ||#前面的命令执行失败 才能执行后面的命令

    [root@theboy82 ~]# touc 2.txt||pwd
    -bash: touc: command not found
    /root
    ​
    [root@theboy82 ~]# ll 2.txt||pwd
    -rw-r--r--. 1 root root 30 May 13 10:15 2.txt

文件压缩

  • 节约磁盘空间 压缩不常用的文件

  • 压缩后的文件,发送备份服务器过程减少磁盘IO,一个文件建立一次IO请求,多个文件建立多个IO请求

  • 压缩时间选择zabbix低点进行,因压缩过程比较消耗服务器CPU

Linux压缩命令

tar -参数

  • ​
    Z   #使用gzip方式进行压缩
    c   #使用create创建压缩包
    v   #显示压缩过程 verbose
    f   #指定文件 file
    x   #表示解压 使用xf参数进行解压 extract
    t   #查看压缩包里面文件名称 使用tf参数查看
    c   #指定解压位置(默认当前)
    ------------------------------------------------------------------------
    -P  #不提示从成员中删除/
    --exclude#排除文件
    --exclude-from#排除文件中的文件名
  • tar zcvf#压缩文件
    [root@theboy82 ~]# tar zcvf /root/test1/hosts.tar.gz /root/hosts /root/88.txt
    tar: Removing leading `/' from member names
    /root/hosts
    /root/88.txt
    [root@theboy82 ~]# ll test1
    total 4
    -rw-r--r--. 1 root root 197 May 13 11:06 hosts.tar.gz
    ​
    系统为保护文件安全,使用绝对路径会删除/,如不删除解压后的路径会覆盖源文件:
    [root@theboy82 ~]# tar tf test1/hosts.tar.gz
    root/hosts
    root/88.txt
  • tar xf#解压缩
    [root@theboy82 ~]# tar xf test1/hosts.tar.gz -C test2
    ​
    [root@theboy82 ~/test2/root]# ll
    total 4
    -rw-r--r--. 1 root root   0 May 13 10:04 88.txt
    -rw-r--r--. 1 root root 158 May 13 10:44 hosts
  • exclude#排除压缩
    [root@theboy82 ~]# tar zcvf 111.tar.gz ./* --exclude=passwd --exclude=anaconda-ks.cfg
    ./1.txt
    ./2.txt
    ./3.txt
    [root@theboy82 ~]# ll
    total 16
    -rw-r--r--. 1 root root  298 May 13 14:02 111.tar.gz
    -rw-r--r--. 1 root root  120 May 13 11:24 1.txt
    -rw-r--r--. 1 root root    0 May 13 11:22 2.txt
    -rw-r--r--. 1 root root    0 May 13 11:22 3.txt
    -rw-------. 1 root root 1505 Apr 28 22:03 anaconda-ks.cfg
    -rw-r--r--. 1 root root  938 May  5 19:42 passwd
  • --exclude-from#排除压缩写入到文件的文件

  • [root@theboy82 ~]# cat 1.txt
    2.txt
    3.txt
    [root@theboy82 ~]# tar zcvf yasobk.tar.gz ./* --exclude-from=1.txt
    ./1.txt
    ./anaconda-ks.cfg
    ./passwd
    [root@theboy82 ~]# ll
    total 16
    -rw-r--r--. 1 root root   12 May 13 14:08 1.txt
    -rw-r--r--. 1 root root    0 May 13 11:22 2.txt
    -rw-r--r--. 1 root root    0 May 13 11:22 3.txt
    -rw-------. 1 root root 1505 Apr 28 22:03 anaconda-ks.cfg
    -rw-r--r--. 1 root root  938 May  5 19:42 passwd
    -rw-r--r--. 1 root root 1399 May 13 14:09 yasobk.tar.gz
    ​

文件权限

[root@theboy82 ~]# ll -i
total 12
33574990 -rw-r--r--. 1 root root   12 May 13 14:08 1.txt
33574991 -rw-r--r--. 1 root root    0 May 13 11:22 2.txt
33575203 -rw-r--r--. 1 root root    0 May 13 11:22 3.txt
33574979 -rw-------. 1 root root 1505 Apr 28 22:03 anaconda-ks.cfg
33575204 -rw-r--r--. 1 root root  938 May  5 19:42 passwd

33574990-rw-r--r--.1rootroot12May 13 14:081.txt
inode文件类型9位权限表示开启selinux时创建的硬链接个数用户用户组文件大小创建时间文件名
分为3组权限位关闭就没有·文件默认1文件夹默认2
权限rw-r--r--rwx-
释义users属主权限group属组权限other其他用户权限read读取write写入execute执行无权限
表示数字666421

inode号:ll -i 查看

  • 同一文件系统中相同inode号的文件互为硬链接

  • 只能在相同分区创建,删除任意一个不影响其他

  • 不能对目录进行创建硬链接 文件可以

  • ln 源文件 目标文件#创建硬链接
    ​
    [root@theboy82 ~]# ln 1.txt tidl.txt
    ​
    [root@theboy82 ~]# ll -i
    total 16
    33574990 -rw-r--r--. 2 root root   12 May 13 14:08 1.txt
    33574990 -rw-r--r--. 2 root root   12 May 13 14:08 tidl.txt
    ​
    df -i#查看inode使用情况(每个文件最少占用1个inode和1个block软件储存块)

软连接:

  • 删除软链接不影响源文件,删除源文件软链接文件不可用,红底白字闪烁

  • 文件和目录都可做软链接,可以跨文件系统做软链接

  • 软链接inode号不同

  • ln -s 源文件 链接文件(做软连接尽量使用绝对路路径)
    [root@theboy82 ~]# ln -s 1.txt rrlmjx.txt
    [root@theboy82 ~]# ll
    total 16
    -rw-r--r--. 2 root root   12 May 13 14:08 1.txt
    -rw-r--r--. 1 root root    0 May 13 11:22 2.txt
    -rw-r--r--. 1 root root    0 May 13 11:22 3.txt
    -rw-------. 1 root root 1505 Apr 28 22:03 anaconda-ks.cfg
    -rw-r--r--. 1 root root  938 May  5 19:42 passwd
    lrwxrwxrwx. 1 root root    5 May 14 12:00 rrlmjx.txt -> 1.txt
    -rw-r--r--. 2 root root   12 May 13 14:08 tidl.txt
  • 利用软链接跨文件系统解决磁盘不足问题

  • 做代码上线 回滚等

文件时间

  • stat 查看文件详细属性

[root@theboy82 ~]# stat /etc/hosts
  File: ‘/etc/hosts’
  Size: 158         Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d  Inode: 16777795    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:net_conf_t:s0
Access: 2022-05-14 10:44:21.975015432 +0800
Modify: 2013-06-07 22:31:32.000000000 +0800
Change: 2022-04-28 22:00:21.455270984 +0800
 Birth: -
accessmodifychange
访问时间修改时间改变时间
第一次查看会发生变化,后面查看不会变编辑后三个时间都会变改变文件内容属性发生变化
  • 按时间进行查找文件

  • -atime按访问时间查找了解
    -mtime按修改时间查找重要
    -ctime按属性修改时间查找了解
    find ./ -mtime +7查找7天前被修改的文件和目录
    find ./ -mtime -7查找7天内被修改的文件和目录
    -mtime 0表示最近24小时修改的文件
    -mtime 1表示一天前修改的文件
转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/888018.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号