第二天课堂练习
一、
1、获取虚拟机的IP地址
[root@wangzerui ~]# ip a
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:4c:aa:78 brd ff:ff:ff:ff:ff:ff
altname enp3s0
inet 192.168.59.128/24 brd 192.168.59.255 scope global dynamic noprefixroute ens160
valid_lft 1471sec preferred_lft 1471sec
inet6 fe80::20c:29ff:fe4c:aa78/64 scope link noprefixroute
valid_lft forever preferred_lft forever
2、获取当前系统的时间
[root@wangzerui ~]# date
Sat Jan 11 09:29:47 PM CST 2025
3、设置当前的时间为2023年1月1日12:00
[root@wangzerui ~]# date -s 20230101
Sun Jan 1 12:00:00 AM CST 2023
4、从当前目录切换到/root/home目录,并查看/root/home下有哪些文件和目录
[root@wangzerui ~]# ls /root
111 333 444.txt anaconda-ks.cfg Desktop Downloads Music Public Videos zhenggqu.txt
222 444 4.txt a.txt Documents error.txt Pictures Templates WZR.txt
5、打印当前的路径
二、
1、创建/root/dir1/dir2目录
[root@wangzerui ~]# mkdir dir1
[root@wangzerui ~]# mkdir dir2
2、在/root下创建guazai1、guazai2、guazai3…一直到guazai10目录
[root@wangzerui ~]# mkdir /root/zhengque.txt/guazai1/guazi2/guazi3/guazi4/guazi5/guazi6/guazi7/guazi8/guazi9/guazi10
mkdir: cannot create directory
mkdir: cannot create directory ‘/root/zhengque.txt/guazai1/guazi2/guazi3/guazi4/guazi5/guazi6/guazi7/guazi8/guazi9/guazi10’: No such file or directory
bash: mkdir:: command not found…
Similar command is: ‘mkdir’
3、删除/root/dir1/dir2目录
[root@wangzerui ~]# rm dir1 -r
rm: remove directory ‘dir1’? y
[root@wangzerui ~]# rm dir2 -r
rm: remove directory ‘dir2’? y
4、在当前路径下创建以你名字命名的文件
[root@wangzerui ~]# touch WZR.txt
5、查看/etc/passwd文件的内容,并过滤出包含root的行
[root@wangzerui ~]# cat /etc/passwd/root
cat: /etc/passwd/root: Not a directory
6、使用echo
命令输出"Hello, World!"到屏幕上。
[root@wangzerui ~]# echo Holle World
Holle World
7、提取/etc/passwd第一列的内容
[root@wangzerui ~]# head -1 /etc/passwd
root❌0:0:root:/root:/bin/bash
8、为/root/anaconda-ks.cfg 文件创建软链接到/下并命名为a.cfg
[root@wangzerui ~]# in -s /root/anaconda-ks.cfg /root/a.cfg
-bash: syntax error near unexpected token `in’
9、复制/etc/shadow文件到/root下
[root@wangzerui ~]# cp /etc/shadow/root
cp: missing destination file operand after ‘/etc/shadow/root’
Try ‘cp --help’ for more information.
10、查找以repo结尾的文件
[root@wangzerui ~]# fing ./root -name “repo”
bash: fing: command not found…
11、把/etc/gshadow 和/root/home打包压缩为/root/ys.tar.gz
[root@wangzerui ~]# tar -cfg /root/ye.tar.gz/etc/gahadow/root/home
tar: Removing leading `/’ from member names
tar: /root/ye.tar.gz/etc/gahadow/root/home: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors