llinux_2
1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[root@lhq ~]#ls /etc/ | grep "^[^[:alpha:]][[:alpha:]].*$"
2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
- 先列举出来符合要求的文件或目录
#ls /etc/ |grep "^p.*[^0-9]$" - 搭配xargs传参给cp
xargs -i cp -r {} /tmp/mytest1/
相对路径:
[root@lhq etc]#ls /etc/ |grep "^p.*[^0-9]$" |xargs -i cp -r {} /tmp/mytest1/
绝对路径:
[root@lhq ~]#mkdir /tmp/mytest1
[root@lhq etc]#ls /etc/ |grep "^p.*[^0-9]$" |xargs -i cp -r /etc/{} /tmp/mytest1/
3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@lhq ~]#cat /etc/issue | tr "a-z" “A-Z” > /tmp/issue.out
[root@lhq ~]#cat /tmp/issue.out
\S
KBOKBI \O LK በ\J
4、请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2019;
[root@lhq ~]#groupadd -g 2019 distro
//检验
[root@lhq ~]#cat /etc/group |tail -1
distro:x:2019:
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
[root@lhq ~]#useradd -u 1016 -g distro mandriva
//检验
[root@lhq ~]#id 1016
uid=1016(mandriva) gid=2019(distro) groups=2019(distro)
(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
[root@lhq ~]#useradd -u 1100 -d /home/linux mageia
//检验
[root@lhq ~]#cat /etc/passwd |tail -1
mageia:x:1100:1100::/home/linux:/bin/bash
(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
[root@lhq ~]#echo mageedu | passwd --stdin mageia | passwd mageia -x 7
Adjusting aging data for user mageia.
passwd: Success
#检验
[root@lhq ~]#cat /etc/shadow |tail -1
mageia:$1$WN/qMbtO$a3ZTk8PLPuEFdeucNrU3E1:18872:0:7:7:::
(5)、删除mandriva,但保留其家目录;
# 查看家目录
[root@lhq ~]#ll /home |grep mandriva
drwx------. 3 mandriva distro 78 Sep 2 10:18 mandriva
#删用户mandriva
[root@lhq ~]#userdel mandriva
# 查看家目录
[root@lhq ~]#ll /home |grep mandriva
drwx------. 3 mandriva distro 78 Sep 2 10:18 mandriva
#结论
userdel不做删除家目录操作
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[root@lhq ~]#useradd -u 2002 -g distro -G peguin slackware
[root@lhq ~]#id 2002
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7)、修改slackware的默认shell为/bin/tcsh;
[root@lhq ~]#usermod -s /bin/tcsh slackware
#检验
[root@lhq ~]#cat /etc/passwd |tail -1
slackwate:x:2002:2019::/home/slackware:/bin/tcsh
(8)、为用户slackware新增附加组admins,并设置不可登陆。
[root@lhq ~]#groupadd admins
[root@lhq ~]#usermod -aG admins -s /bin/nologin slackwate
5、创建用户user1、user2、user3。在/data/下创建目录test
[root@lhq ~]mkdir /date/test/
[root@lhq ~]useradd user1;useradd useradd user2;useradd user3
(1)、目录/data/test属主、属组为user1
[root@lhq ~]#chown user1:user1 /date/test
(2)、在目录属主、属组不变的情况下,user2对文件有读写权限
[root@lhq ~]#setfacl -m u:user2:rw- /date/test
#检验
[root@lhq ~]#getfacl /date/test
getfacl: Removing leading '/' from absolute path names
# file: date/test
# owner: user1
# group: user1
user::rwx
user:user2:rw-
group::r-x
mask::rwx
other::r-x
(3)、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh
[root@lhq ~]#touch /date/test/a{1..4}.sh
[root@lhq test]#cd /date/test
[root@lhq test]#chattr +i a1.sh a2.sh
[root@lhq ~]#chmod 755 /date/test
(4)、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件
[root@lhq ~]#usermod -aG user1 user3
[root@lhq ~]#chmod u-x /data/test
(5)、清理/data/test目录及其下所有文件的acl权限
[root@lhq ~]setfacl -b /data/test
llinux_2的更多相关文章
随机推荐
- Ubuntu18.04编译Zircon
1.获取源代码 git clone https://fuchsia.googlesource.com/zircon 2.安装编译环境 sudo apt-get install texinfo libg ...
- git报错 error: cannot stat 'file': Permission denied
切换分支(git checkout xxx)时报错: error: cannot stat 'file': Permission denied 解决方法:退出编辑器.浏览器.资源管理器等,然后再切换就 ...
- Linux上天之路(九)之文件和文件夹的权限
主要内容 linux 基本权限 linux特殊权限 linux隐藏权限 linux file ACL 权限 1. Linux的基本权限 使用ls -l filename 命令查看文件或文件夹详细权限 ...
- Java语言学习案例雷霆战机
1.Java雷霆战机学习笔记(一)-资源加载 https://www.toutiao.com/i6631331313259381255/ 2.Java雷霆战机学习笔记(二)-音乐播放 https:// ...
- Appium+python自动化测试过程中问题
一.自动删除contactmanager 自动化测试appium提供的sample如下包/activity:com.example.android.contactmanager/.ContactMan ...
- day 13 函数指针类型
(1).有以下程序: 则正确的选项是[B] (A).7 4 (B).4 10 (C).8 8 (D)10 10 分析:主要考求字符串的长度,strlen是专门求字符串长度的函数,但不包含'\0'在内. ...
- winfrom 双缓冲
在窗体load函数中 this.DoubleBuffered = true; //控件,需要反射的方式设置 Type dgvType = this.dgv.GetType(); PropertyInf ...
- 判断jquery类库是否加载,如未加载则加载。
本人所有文章使用到的东西均在"渭南电脑维修网"网站中得以实现和应用,还请大家参考. 抄写别人网站的同时,N多不同的网站,势必有N多的css.javascript引用文件都会重复引用 ...
- WPF学习笔记(四):AvalonEdit 代码高亮编辑控件专题
AvalonEdit 是一个基于 WPF 的文本编辑器组件.它是由 Daniel Grunwald 为 SharpDevelop 编写的.从 5.0 版开始,AvalonEdit 根据MIT许可证发布 ...
- golang中使用zap日志库
1. 快速使用 package main import ( "go.uber.org/zap" "time" ) func main() { // 1. sug ...