一
1.获取虚拟机的IP地址
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:7c:e5:62 brd ff:ff:ff:ff:ff:ff
altname enp3s0
inet 192.168.189.128/24 brd 192.168.189.255 scope global dynamic noprefixroute ens160
valid_lft 1600sec preferred_lft 1600sec
inet6 fe80::20c:29ff:fe7c:e562/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@localhost ~]# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.189.128 netmask 255.255.255.0 broadcast 192.168.189.255
inet6 fe80::20c:29ff:fe7c:e562 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:7c:e5:62 txqueuelen 1000 (Ethernet)
RX packets 3668 bytes 3934683 (3.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1972 bytes 660392 (644.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 18 bytes 2112 (2.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18 bytes 2112 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# hostname -I
192.168.189.128
[root@localhost ~]#
2.获取当前系统的时间
Thu Oct 24 09:55:47 AM CST 2024
[root@localhos ~]#
3.设置当前时间为2023年1月1日12:00
···[root@localhost ~]# date -s "20230101 12:00"
Sun Jan 1 12:00:00 PM CST 2023
[root@localhost ~]#
4.从当前目录切换道/root/home目录,并查看/root/home下有哪些文件和目录
bash: cd/root/home: No such file or directory
[root@localhost ~]# cd /
[root@localhost /]# cd home
[root@localhost home]# pwd
/home
[root@localhost home]# ls
redhat
[root@localhost home]#
5.打印当前路径
/home
[root@localhost home]#
二
1.创建/root/dir1/dir2目录
222 anaconda-ks.cfg dabao2.tar.gz Desktop Downloads ip1.log
Pictures Templates yasuo1.tar.bz2
aaa bbb dabao.tar dir1 eee IP1.log Public
Videos yasuo2.zip
aaa_soft ccc dabao.tar.gz Documents ghl Music
QQ_3.2.12_240902_x86_64_01.rpm xiaohei yasuo3.zip
[root@localhos home]# tree /root/dir1/ /root/dir1/
└── dir2
1 directory, 0 files [root@localhos home]#
2.在/root下创建guazai1 guazai2 guazai3......一直到guazai10目录
222 bbb dabao.tar.gz Downloads guazai10 guazai5
guazai9 Pictures Videos yasuo3.zip
aaa ccc Desktop eee guazai2 guazai6
ip1.log Public xiaohei
aaa_soft dabao2.tar.gz dir1 ghl guazai3 guazai7
IP1.log QQ_3.2.12_240902_x86_64_01.rpm yasuo1.tar.bz2
anaconda-ks.cfg dabao.tar Documents guazai1 guazai4 guazai8 Music
Templates yasuo2.zip
[root@localhos home]# ```
3、删除/root/dir1/dir2目录
```[root@localhos home]# rm -rf /root/dir1/dir2 [root@haha home]# ls /root/
222 bbb dabao.tar.gz Downloads guazai10 guazai5
guazai9 Pictures Videos yasuo3.zip
aaa ccc Desktop eee guazai2 guazai6
ip1.log Public xiaohei
aaa_soft dabao2.tar.gz dir1 ghl guazai3 guazai7
IP1.log QQ_3.2.12_240902_x86_64_01.rpm yasuo1.tar.bz2
anaconda-ks.cfg dabao.tar Documents guazai1 guazai4 guazai8 Music
Templates yasuo2.zip
4、在当前路径下创建以你名字命名的文件
total 0
-rw-r--r--. 1 root root 0 Jan 1 12:08 ghl.txt
[root@localhos dir1]#
5、查看/etc/passwd文件的内容,并过滤出包含root的行
[root@localhos dir1]# grep root /etc/passwd root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
xiaohei:x:1009:1009:1111111111111:/root/xiaohei:/bin/bash [root@localhos dir1]#
6、使用 echo命令输出"Hello, World!"到屏幕上。
[root@localhos dir1]#
7、提取/etc/passwd第一列的内容
root
bin
daemon adm
lp
sync
shutdown halt
mail
operator games
ftp
nobody tss
systemd-coredump
dbus
polkitd avahi
colord
rtkit
pipewire clevis
sssd
geoclue flatpak
setroubleshoot libstoragemgmt systemd-oom
gdm
cockpit-ws
cockpit-wsinstance gnome-initial-setup
sshd
chrony dnsmasq tcpdump redhat xm
xiaohei
xiaohua1
[root@localhos dir1]#
8、为/root/anaconda-ks.cfg 文件创建软链接到/下并命名为a.cfg
[root@haha dir1]# cat /a.cfg
# Generated by Anaconda 34.25.3.8 # Generated by pykickstart v3.32 #version=RHEL9
``
9、复制/etc/shadow文件到/root下
```[root@localhos dir1]# cp /etc/shadow /root
[root@localhos dir1]# ls /root/
222 bbb dabao.tar.gz Downloads guazai10 guazai5
guazai9 Pictures Templates yasuo2.zi p
aaa ccc Desktop eee guazai2 guazai6
ip1.log Public Videos yasuo3.zi p
aaa_soft dabao2.tar.gz dir1 ghl guazai3 guazai7
IP1.log QQ_3.2.12_240902_x86_64_01.rpm xiaohei
anaconda-ks.cfg dabao.tar Documents guazai1 guazai4 guazai8 Music
shadow yasuo1.tar.bz2
[root@localhos dir1]#
10、查找以repo结尾的文件
/run/media/root/RHEL-9-3-0-BaseOS-x86_64/media.repo /etc/yum.repos.d/redhat.repo
/var/lib/rhsm/repo_server_val/redhat.repo /usr/share/rhel/secrets/redhat.repo
[root@localhos dir1]#
11、把/etc/gshadow 和/root/home打包压缩为/root/ys.tar.gz
tar: Removing leading `/' from member names /etc/gshadow
tar: Removing leading `/' from hard link targets /home/
/home/redhat/
/home/redhat/.mozilla/
[root@localhos dir1]# tar -tf /root/ys.tar.gz etc/gshadow
home/
home/redhat/
home/redhat/.mozilla/
home/redhat/.mozilla/extensions/ home/redhat/.mozilla/plugins/
home/redhat/.bash_logout
home/redhat/.bash_profile