Linux5

这篇博客详细介绍了在Linux环境下如何使用find命令查找特定条件的文件,包括按时间、名称和类型等。同时,展示了如何进行文件打包压缩,如使用zip、unzip、tar和gzip命令。此外,还涉及了用户管理,如创建用户、设置shell以及定义命令别名。内容覆盖了文件系统的操作和用户权限管理的基础知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文件查找

(1)在$HOME目录及其子目录中,查找2天前被更改过的文件

(2)在/etc/目录下寻找以host开头的文件

(3)在/test/下面查找目录文件

(4)在/test目录及子目录中,查找超过2KB的文件

打包压缩

(1)将/test目录下的所有文件和文件夹全部压缩成myfile.zip文件

(2)把myfile.zip文件解压到 /opt

(3)将/opt目录下的文件全部打包并用gzip压缩成/test/newfile.tar.gz

(4)查看/test/newfile.tar.gz文件中有哪些文件?

(5)在/test目录内,备份/etc下的所有文件并保留其权限

别名

1.当前用户永久生效的命令别名

(1)写一个命令命为hello,实现的功能为每输入一次hello命令,就有hello,everyone写入文

件/file.txt中。

(2)写一个命令别名为shuaxin,实现的功能为每输入一次该命令,file.txt文件的所有时间就更新为当前时间。

2.所有用户生效的命令别

名写一个所有用户都生效的命令别名为hh,每一个用户输入这个命令之后可以在该用户家目录下创建一个file1文件。

用户管理

1、新建一个名为sarah的用户,不属于adminuser组,并将其shell设置为不可登陆shell

1、创建alex用户,使alex用户满足以下要求:用户id为3456,描述名为alian,密码为glegung

查找

(1)

[root@localhost ~]# find /$HOME -mtime +2
//root/.bash_logout
//root/.bash_profile
//root/.bashrc
//root/.cshrc
//root/.tcshrc
//root/findresuits/.bash_logout
//root/findresuits/.bash_profile
//root/findresuits/.bashrc
//root/findresuits/.mozilla/plugins
//root/findresuits/.mozilla/extensions
//root/findresuits/plugins

(2)

[root@localhost ~]# find /etc -name "host*" -print
/etc/host.conf
/etc/hosts
/etc/nvme/hostnqn
/etc/nvme/hostid
/etc/avahi/hosts
/etc/hostname

(3)

[root@localhost ~]# find /test -type d
/test

(4)

[root@localhost ~]# find /test -size +2KB
find: invalid -size type `B'

打包压缩

(1)

[root@haha ~]# zip -r mrfile.zip /test
adding: test/ (stored 0%)
adding: test/file.lnk (deflated 7%)
[root@haha ~]# ls /test
file.lnk
[root@haha test]# ls myfile.zip
myfile.zip
 

(2)

[root@haha test]# unzip myfile.zip -d /opt
Archive:  myfile.zip
creating: /opt/test/
inflating: /opt/test/file.lnk
extracting: /opt/test/we
extracting: /opt/test/are
extracting: /opt/test/sss
creating: /opt/test/myfile/
extracting: /opt/test/mrfile.zip

(3)

[root@haha test]# tar -czf /test/newfile.tar.gz    myfile.zip
[root@haha test]# ll /test/
总用量 16
-rw-r--r--. 1 root root    0 8月   4 22:36 are
-rw-r--r--. 2 root root   27 7月  31 14:49 file.lnk
-rw-r--r--. 1 root root  921 8月   4 22:38 mrfile.zip
drwxr-xr-x. 2 root root    6 8月   4 22:37 myfile
-rw-r--r--. 1 root root 2000 8月   4 22:40 myfile.zip
-rw-r--r--. 1 root root  510 8月   4 22:46 newfile.tar.gz
-rw-r--r--. 1 root root    0 8月   4 22:36 sss
-rw-r--r--. 1 root root    0 8月   4 22:36 we

(4)

[root@haha test]# tar tvf /test/newfile.tar.gz
-rw-r--r-- root/root      2000 2022-08-04 22:40 myfile.zip

(5)

[root@haha test]# tar tpf /test

别名

1.

(1)

[root@haha test]# vim /.bashrc
[root@haha test]# source /.bashrc
[root@haha test]# hello
[root@haha test]# hello,everyone

(2)

[root@haha test]# vim /.bashrc
[root@haha test]# source /.bashrc
[root@haha test]# shuanxin
[root@haha test]# stat file.txt
文件:"file.txt"
大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:53596575    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:default_t:s0
最近访问:2022-08-04 23:09:09.155890745 +0800
最近更改:2022-08-04 23:09:09.155890745 +0800
最近改动:2022-08-04 23:09:09.155890745 +0800
创建时间:-

2.

(1)

[root@haha test]# vim /etc/bashrc
[root@haha test]# source /etc/bashrc
[root@haha test]# hh
[root@haha test]# stat /file1
文件:"/file1"
大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:2737361     硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:etc_runtime_t:s0
最近访问:2022-08-04 23:12:36.774825325 +0800
最近更改:2022-08-04 23:12:36.774825325 +0800
最近改动:2022-08-04 23:12:36.774825325 +0800

文件

(1)

[root@localhost ~]# useradd -N  adminuser -s /sbin/nologin sarah

(2)

[root@localhost ~]# useradd -u 3456 -c alian -p giegung  alex

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值