美文网首页
2019-07-22 课堂笔记

2019-07-22 课堂笔记

作者: 麟之趾a | 来源:发表于2019-07-23 17:33 被阅读0次

昨天回顾

  • 文件属性介绍
    文件属性中文件权限概念:rwx- 权限赋予用户(9位)数值表示根据权限找出相应的数据
[root@oldboy63 ~/oldboy]# find . -type f -name "*.txt" -perm 644
./1.txt
./2.txt
./3.txt
./4.txt
./5.txt
./6.txt
./7.txt
./8.txt
./9.txt
./10.txt

文件属性用户信息概念:用户分类(皇帝 平民 傀儡--不能登录系统/管理进程服务)

  • 根据时间信息查找文件
[root@oldboy63 /]# find /oldboy/ -type d -mtime -1
/oldboy/
/oldboy/oldgirl
+1 表示1天以前
1 表示第一天
-1 表示1天以内
  • find找到东西进行删除
1. find /oldboy -type f |xargs rm
2. rm `find /oldboy -type f`
3.find /oldboy -type f -exec rm {} \;
4.find /oldboy -type f -delete

今日总结

  • 文件属性,文件索引概念
    inode
    概念:用于存储文件属性信息/存储文件指针信息
    诞生:创建文件系统(格式化)
    查看:df -i
    block
    概念:用于存储文件数据信息
    1个文件可能有多个block 4K
    诞生:创建文件系统(格式化)
    查看: df
  • 硬链接
    硬链接:

概念:

  1. inode号码一致的数据互为硬链接数据
    02.相当于数据的多个门
    创建ln /oldboy/oldboy.txt /oldboy/oldboy_hard_link.txt
    特点:
    01.源文件删除,连接文件依然生效
    02.相当于数据的多个门
    03:不能给目录创建硬链接个数,创建目录的硬链接个数为2
    04:硬链接创建成功后,不会更新inode和block
    05:不能跨文件系统给文件创建硬链接,因为每个磁盘的inode号不能跨文件系统
    作用:
    01:硬链接文件可以用于数据恢复,防止数据误删(但无法防止文件误修改),完整的备份数据应使用cp备份
  • 面试题,为什么/etc/目录的硬链接个数为83
    在/etc/目录下有81个子目录

  • 可以使用find命令查找硬链接文件

root@oldboy63 ~]# ls -li /etc/hosts
16810598 -rw-r--r--. 2 root root 179 Jul 17 19:38 /etc/hosts
[root@oldboy63 ~]# find / -type f -inum 16810598
/etc/hosts
/tmp/hostss
  • 软连接

概念:数据的快捷方式
特点:
01:源文件删除,连接文件失效
02:连接文件会占用新的inode并不会占用新的bloack
03:软连接文件可以给目录创建软连接
作用:便于开发人员调取变量

+系统正则符号概念
1)系统正则符号
基础符号:

#表注释信息
表提示用户登录的命令提示符
$:表登录用户信息
调取变量使用
调取列信息 awk
正则表示匹配尾部
!:表示强制的意思
:wq! vim强制保存退出
!! 调取上一个命令
!sh 调取最近以sh开头的命令
|:管道符,前面命令的标准输出,作为后面命令的标准输入

练习:找出oldboy目录下所有以.txt结尾的文件,并进行压缩到tmp目录下
[root@oldboy63 ~/oldboy]# ls
10.jpg  1.jpg  2.jpg  3.jpg  4.jpg  5.jpg  6.jpg  7.jpg  8.jpg  9.jpg
10.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt
方法一:利用find+xargs
[root@oldboy63 ~/oldboy]# find /root/oldboy/ -type f -name "*.txt" |xargs tar zcvf /tmp/oldboy.tar.gz
tar: Removing leading `/' from member names
/root/oldboy/1.txt
/root/oldboy/2.txt
/root/oldboy/3.txt
/root/oldboy/4.txt
/root/oldboy/5.txt
/root/oldboy/6.txt
/root/oldboy/7.txt
/root/oldboy/8.txt
/root/oldboy/9.txt
/root/oldboy/10.txt
[root@oldboy63 ~/oldboy]# tar -tf /tmp/oldboy.tar.gz 
root/oldboy/1.txt
root/oldboy/2.txt
root/oldboy/3.txt
root/oldboy/4.txt
root/oldboy/5.txt
root/oldboy/6.txt
root/oldboy/7.txt
root/oldboy/8.txt
root/oldboy/9.txt
root/oldboy/10.txt
方法二:利用tar
[root@oldboy63 ~/oldboy]# tar -zvcf /tmp/oldboy1.tar.gz --exclude=*.jpg /root/oldboy/
tar: Removing leading `/' from member names
/root/oldboy/
/root/oldboy/1.txt
/root/oldboy/2.txt
/root/oldboy/3.txt
/root/oldboy/4.txt
/root/oldboy/5.txt
/root/oldboy/6.txt
/root/oldboy/7.txt
/root/oldboy/8.txt
/root/oldboy/9.txt
/root/oldboy/10.txt
方法三:ls+tar
[root@oldboy63 ~/oldboy]# ls *.txt|xargs tar -zvcf /tmp/oldboy2.tar.gz
10.txt
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
方法四:find 加 +号
[root@oldboy63 ~/oldboy]# find /root/oldboy/ -type f -name "*.txt" -exec tar zvcf /tmp/oldboy4.tar.gz {} +;
tar: Removing leading `/' from member names
/root/oldboy/1.txt
/root/oldboy/2.txt
/root/oldboy/3.txt
/root/oldboy/4.txt
/root/oldboy/5.txt
/root/oldboy/6.txt
/root/oldboy/7.txt
/root/oldboy/8.txt
/root/oldboy/9.txt
/root/oldboy/10.txt
方法五:ls+grep+xargs
[root@oldboy63 ~/oldboy]# ls -l|grep -o "[1-9]\.*txt" |xargs tar zvcf /tmp/oldboy5.tar.gz 
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt

  • 引号系列
    单引号:所见即所得
    双引号:调用变量使用
    反撇号:反撇号里面的命令的执行结果,给外面的命令执行
    无引号:基本与双引号相同,但可以执行序列

  • 路径符号信息
    ~:用户的家目录
    -:上一次工作目录
    .:当前目录
    ..:上一级目录

  • 定向符号
    \1> :标准输出重定向
    \1>>:标准输出追加重定向
    2>:错误输出
    2>>:错误输出重定向
    <0:标准输入
    tr 'a-z' 'A-Z'</tmp/oldboy
    xargs -n 2</tmp/oldboy
    <<0:标准输入追加
    cat >>oldboy<<EOF
    &>:错误正确标准输出
    &>>:错误正确标准追加输出

  • 逻辑运算符
    &&:前面命令执行成功才会执行后面的命令
    ||:前面命令执行失败才会执行后面的命令

相关文章

网友评论

      本文标题:2019-07-22 课堂笔记

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