Linux find、diff、sort、tar和权限的操作

Linux:find、diff、sort、tar和权限的操作

Linux的基础操作

小编以一个小的操作样例给大家介绍一下Linux基本简单的操作,请先根据上一篇的文章创建如下图的目录文件结构。
在这里插入图片描述

Find命令的使用:

  1. 查询当天修改过的文件
    [user@localhost ~]# find ./ -mtime -1
  2. 查找在系统中最后10分钟访问的文件
    [user@localhost ~]# find ./ -atime -10
  3. 查找在系统中为空的文件或者文件夹
    [user@localhost ~]# find ./ -empty
  4. 查找在系统中最后5分钟里修改过的文件
    [user@localhost ~]# find ./ -mmin -5
  5. 查找在系统中属于作废用户的文件
    [user@localhost ~]# find ./ -nouser
  6. 查权限为700的文件或目录
    [user@localhost ~]# find ./ -perm -700
  7. 查硬连接数大于2的文件或目录
    [user@localhost ~]# find ./ -links +2
  8. 查小于512k的文件
    [user@localhost ~]# find ./ -size +512k
  9. 查找大小为0的文件或空目录
    [user@localhost ~]# find ./ -empty
  10. 查.txt文件并显示
    [user@localhost ~]# find ./ -name “*.txt”
  11. 查以大写字母开头的文件
    [user@localhost ~]# find ./ -name “A-Z”
  12. 查以host开头的文件
    [user@localhost ~]# find ./ -name “host*”
  13. 列出/home内不属于本地用户的文件或目录
    [user@localhost ~]# find ./ -nouser
  14. 列出/home内不属于本地组的文件或目录
    [user@localhost ~]# find ./ -nogroup

文件的比较:

[user@localhost ~]# vi a
This is a first file
This is a second file
This is a third file
:wq
[user@localhost ~]# vi b
This is a hhh
This is a first file
This is a second file
:wq
[user@localhost ~]# vi c
This is a hhh
This is a second file
This is a third file
:wq
[user@localhost ~]# diff a b
[user@localhost ~]# diff3a b c

排序命令

[user@localhost ~]# sort a b c
This is a first file
This is a first file
This is a first hhh
This is a first hhh
This is a second file
This is a second file
This is a second file
This is a third file
This is a third file

Tar命令的使用:

1) 使用tar命令创建b目录的打包文件b.tar
[user@localhost ~]# tar cf b.tar b
2) 列出备份文件b.tar中的文件列表
[user@localhost ~]# tar tf b.tar
3) 新建一个名为tmp的文件,并将文件加入到备份文件b.tar中
[user@localhost ~]# touch tmp
[user@localhost ~]# tar rf b.tar tmp
4) 将文件tmp从备份文件中删除
[user@localhost ~]# tar xf tmp b.tar
5) 创建a目录的打包文件a.tar
[user@localhost ~]# tar cf a.tar a
6) 将a.tar和b.tar备份文件合并
[user@localhost ~]# tar rf a.tar b.tar
7) 将user目录下的文件备份并压缩,产生备份压缩文件user.tar.gz。
[user@localhost ~]# gzip user.tar.gz user.tar
8) 解压并恢复打包文件user.tar
[user@localhost ~]# gzip -d user.tar.gz

文件的访问权限:

1)设置user目录为当前目录
[user@localhost ~]# cd /home/user
2) 在user目录下创建名为file1的文件,创建目录test
[user@localhost user]# mkdir test
[user@localhost user]# touch file1
3) 查看user目录下子目录和文件的访问权限
[user@localhost user]# ls -l
4) 设置file1文件的拥有者对文件具有执行权限
[user@localhost user]# chmod u+x file1
5) 设置同组用户对文件file1具有读写权限
[user@localhost user]# chmod g+w file1
6) 设置其它用户对文件file1具有读写权限
[user@localhost user]# chmod o+rw file1
7) 设置所有用户对文件file1具有执行权限。
[user@localhost user]# chmod a+x file1
8) 设置权限掩码为177
[user@localhost user]# umask 177
9) 查看文件file1和目录test的访问权限
[user@localhost user]# ls -l file1 test
10)设置权限掩码为022
[user@localhost user]# umask 022
11) 查看文件file1和test的访问权限
[user@localhost user]# ls -l file1 test

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值