(1)在$HOME目录及其子目录中,查找2天前被更改过的文件
[root@localhost ~]# find /home/ -mtime -2
(2)在/etc/目录下寻找以host开头的文件
[root@localhost ~]# find /etc -name "host*" -print
(3)在/test/下面查找目录文件
[root@localhost ~]# find /test -type d
(4)在/test目录及子目录中,查找超过2KB的文件
[root@localhost ~]# find /test -size -10
打包压缩
(1)将/test目录下的所有文件和文件夹全部压缩成myfile.zip文件
[root@localhost ~]# zip myfile.zip /test
adding: test/ (stored 0%)
(2)把myfile.zip文件解压到 /opt
[root@localhost ~]# unzip myfile.zip -d /opt
Archive: myfile.zip
creating: /opt/test/
[root@localhost ~]# ll /opt
total 4
drwxr-xr-x. 2 root root 4096 Aug 4 17:36 test
(3)将/opt目录下的文件全部打包并用gzip压缩成/test/newfile.tar.gz
[root@localhost test]# tar -czvf newfile.tar.gz /opt
tar: Removing leading `/' from member names
/opt/
/opt/test/
(4)查看/test/newfile.tar.gz文件中有哪些文件?
[root@localhost test]# tar tvf newfile.tar.gz
drwxr-xr-x root/root 0 2022-08-04 20:20 opt/
drwxr-xr-x root/root 0 2022-08-04 17:36 opt/test/
(5)在/test目录内,备份/etc下的所有文件并保留其权限
[root@192 test]# tar -cvf etc.tar /etc
1.当前用户永久生效的命令别名
(1)写一个命令命为hello,实现的功能为每输入一次hello命令,就有hello,everyone写入文
件/file.txt中。
[root@192 ~]# echo "alias hello=`echo hello,everyone >> /file.txt`" >> ~/.bashrc
[root@192 ~]# source ~/.bashrc
[root@192 ~]# hello
[root@192 ~]# cat /file.txt
hello,everyone
(2)写一个命令别名为shuaxin,实现的功能为每输入一次该命令,file.txt文件的所有时间就更新为当前时间。
[root@192 ~]# echo 'alias shuaxin="touch file.txt"' > ~/.bashrc
[root@192 ~]# source ~/.bashrc
[root@192 ~]# shuaxin
[root@192 ~]# stat file.txt
File: file.txt
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 10301h/66305d Inode: 273698 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2022-08-05 16:48:21.235124296 +0800
Modify: 2022-08-05 16:48:21.235124296 +0800
Change: 2022-08-05 16:48:21.235124296 +0800
Birth: 2022-08-05 16:15:21.834090851 +0800
2.所有用户生效的命令别名
写一个所有用户都生效的命令别名为hh,每一个用户输入这个命令之后可以在该用户家目录下创建一个file1文件。
[root@192 ~]# vim ~/.bashrc
alias hh=`touch ~/file$(date "+%F %T")`
[root@192 ~]# source ~/.bashrc
[root@192 ~]# hh
[root@192 ~]# ll
total 48
-rw-r--r--. 1 root root 0 Aug 5 17:42 file2022-08-05
1、新建一个名为sarah的用户,不属于adminuser组,并将其shell设置为不可登陆shell
[root@192 ~]# useradd sarah
[root@192 ~]# usermod -s /sbin/nologin sarah
2、创建alex用户,使alex用户满足以下要求:用户id为3456,描述名为alian,密码为glegung
[root@192 ~]# useradd alex -u 3456 -c "alian"
[root@192 ~]# passwd alex glegung
1、新建目录要求如下:
1)/pub目录为公共存储目录对所有用户可以读,写,执行,但用户只能删除属于自己的文件(t权限)
创建公共目录
[root@192 ~]# mkdir /pub
设置读写执行的权限
[root@192 ~]# chmod 777 /pub
用户之只能删除字段文件
[root@192 ~]# chmod o+t /pub
[root@192 ~]# ll -d /pub
drwxrwxrwt. 2 root root 4096 Aug 5 20:41 /pub
2)/sc目录为生产部存储目录只能对生产部人员可以写入,并且生产部人员该目录所建立的文件都自动归属到shengchan中
创建目录
[root@192 ~]# mkdir /sc
创建组
[root@192 ~]# groupadd shengchan
更改sc的组
[root@192 ~]# chown :shengchan /sc
2---自动归属到组 7是拥有者 7是组中用户 0其他用户
[root@192 ~]# chmod 2770 /sc
[root@192 ~]# ll -d /sc
drwxrws---. 2 root shengchan 4096 Aug 5 20:43 /sc
3)/cw目录为财务部存储目录只能对财务部人员可以写入并且财务部人员所建立的文件都自动属于caiwu组中
创建目录
[root@192 ~]# mkdir/cw
创建财务组
[root@192 ~]# groupadd caiwu
设置自动归属到财务
[root@192 ~]# chmod 2770 /cw
设置自动归属到财务
[root@192 ~]# chgrp caiwu /cw
4) admin用户对于/sc和/cw目录可以读,写,执行
创建asmin组
[root@192 ~]# useradd admin
设置admin对于/sc和/cw的读写执行
[root@192 ~]# setfacl -m u:admin:rwx /cw /sc
查看目录权限
[root@192 ~]# getfacl /sc /cw