1、文件查看:查看/opt/passwd文件的第6行(使用head和tail指令)
使用[root@localhost ~]# head -6 /opt/passwd查看第六行
但是没有文件,我们先创建一个
用vim在里面加一些内容
现在可以查看了
[root@localhost ~]# head -6 /opt/passwd
15315315135
153153153185646131
784
78641687541563413561
7417564175641
641897641783
2、在/etc及其子目录中,查找host开头的文件(使用find指令)
[root@localhost ~]# find /etc -name "*host*" -print0
/etc/host.conf/etc/hosts/etc/samba/lmhosts/etc/opt/chrome/native-messaging-hosts/etc/ssh/ssh_host_ed25519_key/etc/ssh/ssh_host_ed25519_key.pub/etc/ssh/ssh_host_ecdsa_key/etc/ssh/ssh_host_ecdsa_key.pub/etc/ssh/ssh_host_rsa_key/etc/ssh/ssh_host_rsa_key.pub/etc/avahi/hosts/etc/chromium/native-messaging-hosts/etc/nvme/hostnqn/etc/nvme/hostid/etc/hostname[root@localhost ~]# find /etc -name "*host*" -print
/etc/host.conf
/etc/hosts
/etc/samba/lmhosts
/etc/opt/chrome/native-messaging-hosts
/etc/ssh/ssh_host_ed25519_key
/etc/ssh/ssh_host_ed25519_key.pub
/etc/ssh/ssh_host_ecdsa_key
/etc/ssh/ssh_host_ecdsa_key.pub
/etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_rsa_key.pub
/etc/avahi/hosts
/etc/chromium/native-messaging-hosts
/etc/nvme/hostnqn
/etc/nvme/hostid
/etc/hostname
若后跟-print0则不会分行,如图所示,二者区别在图中可看出来
3、查找文件 /usr/share/rhel.xml 中包含字符串 re 的所有行。将所有这些行的信息放在文件/root/files 中(使用grep指令和重定向符号>)
[root@localhost ~]# grep re /usr/share/rhel.xml
grep: /usr/share/rhel.xml: 没有那个文件或目录
[root@localhost ~]# grep re /usr/share/rhel/secrets/
etc-pki-entitlement/ redhat.repo rhsm/
[root@localhost ~]# grep re /usr/share/rhel/secrets/redhat.repo
# *** This file is auto-generated. Changes made here will be over-written. ***
# *** Use "subscription-manager repo-override --help" if you wish to make changes. ***
# a "yum repolist" to refresh available repos
[root@localhost ~]# grep re /usr/share/rhel/secrets/redhat.repo > /root/files
[root@localhost ~]# cat /root/files
# *** This file is auto-generated. Changes made here will be over-written. ***
# *** Use "subscription-manager repo-override --help" if you wish to make changes. ***
# a "yum repolist" to refresh available repos
由于没有rhel.xml,查找文件变为rhel下的redhat.repo
结果如图
4、将整个 /etc 目录下的文件全部打包并用 gzip 压缩成/back/etcback.tar.gz(使用tar指令)
[root@localhost ~]# cd /etc
[root@localhost etc]# cd /
[root@localhost /]# tar -czf /back/etcback.tar.gz etc
[root@localhost /]# cd
[root@localhost ~]# ll /back
总用量 6192
-rw-r--r--. 1 root root 6338113 4月 13 23:01 etcback.tar.gz
5、设置权限,要求如下:创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt(使用chown修改所属者和所属组)
[root@localhost ~]#
[root@localhost ~]# useradd redhat
[root@localhost ~]# groupadd g1+
groupadd:“g1+”不是有效的组名
[root@localhost ~]# groupadd g1
[root@localhost ~]# touch redhat.txt
[root@localhost ~]# chown :redhat redhat.txt
[root@localhost ~]# ll redhat.txt
-rw-r--r--. 1 root redhat 0 4月 13 23:06 redhat.txt
[root@localhost ~]#