Linux教程

Linux基础

本文主要是介绍Linux基础,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

完成作业:

第四周

1、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。

[root@localhost src]# find /etc/*.conf |xargs tar zcvf /usr/local/src/`date +%F_%T`.tar.gz
[root@localhost src]# tar xvf 2021-05-30_18\:01\:37.tar.gz --force-local  #由于压缩文件名字里面有":",所以会被识别成一个地址,此时解压缩需要使用--force-loca的参数来忽略冒号

2、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录

[root@localhost src]# find / \( -nouser -o -nogroup -a -atime -7 \)
find: ‘/proc/41530/task/41530/fd/8’: No such file or directory
find: ‘/proc/41530/task/41530/fdinfo/8’: No such file or directory
find: ‘/proc/41530/fd/9’: No such file or directory
find: ‘/proc/41530/fdinfo/9’: No such file or directory
[root@localhost src]# find /  -nouser -o -nogroup -a -atime -7 -ls
find: ‘/proc/41544’: No such file or directory
find: ‘/proc/41545/task/41545/fd/8’: No such file or directory
find: ‘/proc/41545/task/41545/fdinfo/8’: No such file or directory
find: ‘/proc/41545/fd/9’: No such file or directory
find: ‘/proc/41545/fdinfo/9’: No such file or directory

3、查找/etc目录下至少有一类用户没有执行权限的文件

[root@localhost src]# find /etc/ -not -perm /111 -ls

4、自建网络yum源(通过httpd实现)

#现配置本地yum源,详细步骤如下:
#Centos7yum源
[root@localhost ~]#mount /dev/sr0 /media
[root@localhost ~]#mkdir -p /mnt/yum/centos7
[root@localhost ~]#cp /media/*   /mnt/yum/centos7
[root@localhost ~]#mkdir /etc/yum.repos.d/backup
[root@localhost ~]#mv -f /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
[root@localhost ~]#vi /etc/yum.repos.d/centos7.repo
[root@localhost ~]#cat /etc/yum.repos.d/centos7.repo
[centos7]
name=centos7
baseurl=file:///mnt/yum/centos7
gpgcheck=0
enabled=1
[root@localhost ~]#yum clean all    #清除缓存
[root@localhost ~]#yum makechace    #创建缓存

#Centos8yum源
[root@localhost ~]#mount /dev/sr0 /media
[root@localhost ~]#mkdir -p /mnt/yum/centos8
[root@localhost ~]#cp /media/*   /mnt/yum/centos8
[root@localhost ~]#mkdir /etc/yum.repos.d/backup
[root@localhost ~]#mv -f /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
[root@localhost ~]#vi /etc/yum.repos.d/centos8.repo
[root@localhost ~]#cat /etc/yum.repos.d/centos8.repo #centos8有两个yum源必须全部配置
[BaseOS]
name=BaseOS
baseurl=file:///mnt/yum/centos8/BaseOS
gpgcheck=0
enabled=1

[AppStream]
name=AppStream
baseurl=file:///mnt/yum/centos8/AppStream
gpgcheck=0
enabled=1
[root@localhost ~]#yum clean all    #清除缓存
[root@localhost ~]#yum makechace    #创建缓存

5、利用sed 取出ifconfig命令中本机的IPv4地址

[root@localhost src]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.201  netmask 255.255.255.0  broadcast 10.0.0.255
        inet6 fe80::4dbc:4fb7:9884:df8a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:87:c2:b1  txqueuelen 1000  (Ethernet)
        RX packets 19457  bytes 1635623 (1.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13884  bytes 3424821 (3.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@localhost src]# ifconfig ens33 | sed -n '/inet /s#\(.*inet \)\(.*\)\( n.*\)#\2#gp'
10.0.0.201 

6、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符

[root@localhost src]# cat /etc/fstab | sed -r 's/^#\ ?(.*)/\1/' |sed '/^$/d'
/etc/fstab
Created by anaconda on Sun May  9 16:36:25 2021
Accessible filesystems, by reference, are maintained under '/dev/disk/'.
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
After editing this file, run 'systemctl daemon-reload' to update systemd
units generated from this file.
UUID=31994e11-e2f9-4b75-99e6-e8c67868d9be /                       xfs     defaults        0 0
UUID=b8643245-6aac-440b-8c5c-16a2540200b7 /boot                   xfs     defaults        0 0
UUID=ddc239ec-cb4a-4cde-98ea-94b3a2173d44 /data                   xfs     defaults        0 0
UUID=7cd01928-084d-4f32-87d6-f782032bacce none                    swap    defaults        0 0

7、处理/etc/fstab路径,使用sed命令取出其目录名和基名

#目录名
[root@localhost src]# echo /etc/fstab | sed -nr 's@^(.*)/([^/]+)/?$@\1@p'
/etc
#基名
[root@localhost src]# echo /etc/fstab | sed -nr 's@^(.*)/([^/]+)/?$@\2@p'
fstab
这篇关于Linux基础的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!