1.获取虚拟机的IP地址。
[root@lq ~]# ip addr
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:fb:16:83 brd ff:ff:ff:ff:ff:ff
altname enp3s0
inet 192.168.21.128/24 brd 192.168.21.255 scope global dynamic noprefixroute ens160
valid_lft 906sec preferred_lft 906sec
inet6 fe80::20c:29ff:fefb:1683/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@lq ~]#
2.获取当前系统时间
[root@lq ~]# date
Sat Jan 11 16:52:29 CST 2025
3.设置当前的时间为2023年1月1日12:00
[root@lq ~]# date
Sat Jan 11 16:52:29 CST 2025
[root@lq ~]# date "+%Y-%m-%d %H:%M:%S"
2025-01-11 16:58:55
[root@lq ~]# date -s "2023-01-01 12:00:00"
Sun Jan 1 12:00:00 CST 2023
[root@lq ~]# date "+%Y-%m-%d %H:%M:%S"
2023-01-01 12:00:08
4.从当前目录切换到/root/home目录,并查看/root/home下有哪些文件和目录
[root@lq ~]# cd /root/home/
[root@lq home]# ls -a
. .. her
[root@lq home]# cd
[root@lq ~]#
5.打印当前的路径
[root@lq ~]# pwd
/root
二、
1.创建/root/dir1/dir2目录
[root@lq ~]# mkdir -p /root/dir1/dir2
[root@lq ~]# ls
1.txt Documents Videos file1 file8.xz k_soft.txt yasuo1.tar
111 Downloads a_hard.txt file3 file9.xz li.txt yasuo1.tar.gz
111.txt Music aaa file4 home lq yasuo2.zip
3.txt Pictures anaconda-ks.cfg file5 hxy.txt lq.txt
4.txt Public dabao.tar file6 ip.log lsw
Desktop Templates dir1 file7 ip.txt lsw.txt
2.在/root下创建guazai1、guazai2、guazai3......一直到guazai10目录
[root@lq ~]# mkdir guazai1 guazai2 guazai3 guazai4 guazai5 guazai6 guazai7 guazai8 guazai9[root@lq ~]# ls
1.txt Documents Videos file1 file8.xz guazai5 hxy.txt lq.txt
111 Downloads a_hard.txt file3 file9.xz guazai6 ip.log lsw
111.txt Music aaa file4 guazai1 guazai7 ip.txt lsw.txt
3.txt Pictures anaconda-ks.cfg file5 guazai2 guazai8 k_soft.txt yasuo1.tar
4.txt Public dabao.tar file6 guazai3 guazai9 li.txt yasuo1.tar.gz
Desktop Templates dir1 file7 guazai4 home lq yasuo2.zip
3.删除/root/dir1/dir2目录
[root@lq ~]# rm -r /root/dir1
rm: descend into directory '/root/dir1'? y
rm: remove directory '/root/dir1/dir2'? y
rm: remove directory '/root/dir1'? y
[root@lq ~]# ls
1.txt Downloads aaa file6 guazai4 hxy.txt lsw
111 Music anaconda-ks.cfg file7 guazai5 ip.log lsw.txt
111.txt Pictures dabao.tar file8.xz guazai6 ip.txt yasuo1.tar
3.txt Public file1 file9.xz guazai7 k_soft.txt yasuo1.tar.gz
4.txt Templates file3 guazai1 guazai8 li.txt yasuo2.zip
Desktop Videos file4 guazai2 guazai9 lq
Documents a_hard.txt file5 guazai3 home lq.txt
4.在当前路径下创建以你名字命名的文件
[root@lq ~]# touch lsw.txt
[root@lq ~]# ls
1.txt Downloads aaa file6 guazai4 hxy.txt lsw
111 Music anaconda-ks.cfg file7 guazai5 ip.log lsw.txt
111.txt Pictures dabao.tar file8.xz guazai6 ip.txt yasuo1.tar
3.txt Public file1 file9.xz guazai7 k_soft.txt yasuo1.tar.gz
4.txt Templates file3 guazai1 guazai8 li.txt yasuo2.zip
Desktop Videos file4 guazai2 guazai9 lq
Documents a_hard.txt file5 guazai3 home lq.txt
5.查看/etc/passwd文件的内容,并过滤出包含root的行
[root@lq ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
tss:x:59:59:Account used for TPM access:/:/usr/sbin/nologin
systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
colord:x:997:995:User for colord:/var/lib/colord:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/:/sbin/nologin
pipewire:x:996:993:PipeWire System Daemon:/run/pipewire:/usr/sbin/nologin
clevis:x:995:992:Clevis Decryption Framework unprivileged user:/var/cache/clevis:/usr/sbin/nologin
sssd:x:994:991:User for sssd:/:/sbin/nologin
geoclue:x:993:990:User for geoclue:/var/lib/geoclue:/sbin/nologin
flatpak:x:992:989:User for flatpak system helper:/:/sbin/nologin
setroubleshoot:x:991:988:SELinux troubleshoot server:/var/lib/setroubleshoot:/usr/sbin/nologin
libstoragemgmt:x:986:986:daemon account for libstoragemgmt:/:/usr/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
cockpit-wsinstance:x:985:984:User for cockpit-ws instances:/nonexisting:/sbin/nologin
gnome-initial-setup:x:984:983::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
chrony:x:983:982:chrony system user:/var/lib/chrony:/sbin/nologin
dnsmasq:x:982:981:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/usr/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
redhat:x:1000:1000:redhat:/home/redhat:/bin/bash
[root@lq ~]# grep "root" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@lq ~]#
6.使用echo
命令输出"Hello, World!"到屏幕上。
[root@lq ~]# echo "Hello, World!"
Hello, World!
7.提取/etc/passwd第一列的内容
[root@lq ~]# head -n 1 /etc/passwd
root:x:0:0:root:/root:/bin/bash
8,为/root/anaconda-ks.cfg 文件创建软链接到/下并命名为a.cfg
[root@lq ~]# echo aaa > /root/anaconda-ks.cfg
[root@lq ~]# cat /root/anaconda-ks.cfg
aaa
[root@lq ~]# ln -s /root/anaconda-ks.cfg /a.cfg
[root@lq ~]# cat /a.cfg
aaa
[root@lq ~]#
9.复制/etc/shadow文件到/root下
[root@lq ~]# cp /etc/shadow /root/
cp: overwrite '/root/shadow'? y
[root@lq ~]#
10.查找以repo结尾的文件
[root@lq ~]# cp /etc/shadow /root/
cp: overwrite '/root/shadow'? y
[root@lq ~]# find / -name "*.repo"
/run/media/root/RHEL-9-5-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@lq ~]#
11.把/etc/gshadow 和/root/home打包压缩为/root/ys.tar.gz
[root@lq ~]# tar -czvf /root/ys.tar.gz /etc/gshadow /root/home
tar: Removing leading `/' from member names
/etc/gshadow
tar: Removing leading `/' from hard link targets
/root/home/
/root/home/her/
[root@lq ~]# ll -h /root/ys.tar.gz
-rw-r--r--. 1 root root 497 Jan 11 19:18 /root/ys.tar.gz
[root@lq ~]# tar -tf /root/ys.tar.gz
etc/gshadow
root/home/
root/home/her/
[root@lq ~]#