练习题1(通配符使用):
1. 在root用户家目录创建目录bbs, blog;
[root@westos ~]# mkdir ~/{bbs,blog}
[root@westos ~]# ls ~
anaconda-ks.cfg core.2104 Downloads Pictures Videos
bbs Desktop initial-setup-ks.cfg Public
blog Documents Music Templates
2. bbs目录中创建10个文件code{1..10}.java;
[root@westos ~]# touch ~/bbs/code{1..10}.java
[root@westos ~]# ls ~/bbs/
code10.java code2.java code4.java code6.java code8.java
code1.java code3.java code5.java code7.java code9.java
3. blog目录中创建5个python脚本, linux{a..f}.py;
[root@westos ~]# touch ~/blog/linux{a..f}.py
[root@westos ~]# ls ~/blog/
linuxa.py linuxb.py linuxc.py linuxd.py linuxe.py linuxf.py
4. 切换目录到bbs目录中, 复制/etc/passwd到当前目录;
[root@westos ~]# cd ~/bbs/
[root@westos bbs]# cp /etc/passwd /root/bbs/
[root@westos bbs]# ls /root/bbs/
code10.java code2.java code4.java code6.java code8.java passwd
code1.java code3.java code5.java code7.java code9.java
5. 复制/etc/group文件到当前目录之前所在的目录;
[root@westos bbs]# cd -
/root
[root@westos ~]# cp /etc/group ~
6. 移动以.py结尾的所有脚本文件到student用户的家目录中;
[root@westos ~]# mv ~/blog/*.py ~student/
[student@westos ~]$ ls ~
linuxa.py linuxb.py linuxc.py linuxd.py linuxe.py linuxf.py
7. 删除bbs目录中所有以code1开头的java文件;
[root@westos~]# rm -f ~/bbs/code1*.java
[root@westos ~]# ls ~/bbs/
code2.java code4.java code6.java code8.java passwd
code3.java code5.java code7.java code9.java
练习2(重定向):
1. student用户身份执行find /etc/ -name passwd;
[student@westos ~]$ find /etc/ -name passwd
find: ‘/etc/pki/CA/private’: Permission denied
find: ‘/etc/pki/rsyslog’: Permission denied
/etc/pam.d/passwd
find: ‘/etc/grub.d’: Permission denied
/etc/passwd
find: ‘/etc/cups/ssl’: Permission denied
find: ‘/etc/dhcp’: Permission denied
find: ‘/etc/lvm/archive’: Permission denied
find: ‘/etc/lvm/backup’: Permission denied
find: ‘/etc/lvm/cache’: Permission denied
find: ‘/etc/selinux/targeted/active’: Permissiondenied
find: ‘/etc/selinux/final’: Permission denied
find: ‘/etc/polkit-1/rules.d’: Permission denied
find: ‘/etc/polkit-1/localauthority’: Permissiondenied
find: ‘/etc/firewalld’: Permission denied
find: ‘/etc/redhat-access-insights’: Permission denied
find: ‘/etc/audisp’: Permission denied
find: ‘/etc/audit’: Permission denied
find: ‘/etc/ipsec.d’: Permission denied
find: ‘/etc/vmware-tools/GuestProxyData/trusted’:Permission denied
find: ‘/etc/libvirt’: Permission denied
find: ‘/etc/sudoers.d’: Permission denied
2. 将命令的正确输出保存在文件/tmp/findOk文件中;
[student@westos ~]$ find /etc/ -name passwd1>/tmp/findOk
3. 将命令的错误输出保存在文件/tmp/findErr文件中;
[student@westos ~]$ find /etc/ -name passwd2>/tmp/findErr
/etc/pam.d/passwd
/etc/passwd
4. 将命令的所有输出放入垃圾箱(/dev/null)中;
[student@westos ~]$ find /etc/ -name passwd2>/dev/null
[student@westos ~]$ find /etc/ -name passwd>/dev/null
5. 追加【年-月-日】到文件/tmp/findOk中;
[root@westos ~]# date +%F >>/tmp/findOk
[root@westos ~]# cat /tmp/findOk
/etc/pam.d/passwd
/etc/passwd
2018-02-03
练习3(用户管理):
1. 新建用户redhat,用户说明为“redhat User”,
[root@westos ~]# usermod -c "redhat User"redhat
2. 并设置redhat密码为redhat,该用户首次登陆需修改密码。
[root@westos ~]# passwd redhat
Changing password for user redhat.
New password:
BAD PASSWORD: The password is shorter than 8characters
Retype new password:
passwd: all authentication tokens updatedsuccessfully.
[root@westos ~]#
3、给redhat用户授权,可创建用户;
[root@westos~]# vim /etc/sudoers
[root@westos ~]# su -l redhat
Last login: Sat Feb 3 16:09:31 GMT 2018 on pts/0
[redhat@westos ~]$ useradd westos
4. redhat用户身份新建用户westos,指定uid=1008,gid=1008,但不能删除westos用户。
[root@localhostDesktop]# vim /etc/sudoers
配置文件信息:
## Allow redhat to run useradd anywhere
redhat ALL=(root) /usr/sbin/useradd
创建westos用户:
[root@localhost Desktop]# su -l redhat
Last login: Sun Feb 4 01:34:26 GMT 2018 on pts/2
[redhat@localhost ~]$ sudo useradd westos
We trust you have received the usual lecture from thelocal System
Administrator. It usually boils down to these threethings:
#1) Respectthe privacy of others.
#2) Thinkbefore you type.
#3) Withgreat power comes great responsibility.
[sudo] password for redhat:
显示westos用户:
[root@localhost ~]# usermod -u 1008 westos
[root@localhost ~]# usermod -g 1008 westos
[root@localhost ~]# id westos
uid=1008(westos) gid=1008(redhat) groups=1008(redhat)