初学linux练习

张开发
2026/4/10 8:51:22 15 分钟阅读

分享文章

初学linux练习
1.在root用户的主目录下创建两个目录分别为haha和hehe复制hehe目录到haha目录并重命名为apple。 [rootlocalhost ~]# mkdir /root/{haha,hehe} [rootlocalhost ~]# cp -r hehe haha [rootlocalhost ~]# mv haha apple 2.将hehe目录移动到apple目录下在haha目录下创建一个普通文件为heihei.txt。 ~~~ [rootlocalhost ~]# mv hehe /root/apple [rootlocalhost ~]# touch /apple/heihei.txt ~~~ 3.在终端中显示当前系统时间时间格式为月日时 ~~~ [rootlocalhost ~]# date %m-%d %H ~~~ 4.截取当前日期的年月日显示在文件A.txt 中 ~~~ [rootlocalhost ~]# touch A.txt [rootlocalhost ~]# date | cut -d -f1-4 A.txt ~~~ 5.用户配置/etc/passwd文件将34 字段分别截取出来写入文件UID和文件GID文件 [rootlocalhost ~]# cat /etc/passwd | cut -d : -f3-4 UID [rootlocalhost ~]# cat /etc/passwd | cut -d : -f3-4 GID 6.通过一句话在当前终端显示当前系统一共有多少用户 ~~~ [rootlocalhost ~]# echo 当前终端显示系统用户为 wc -l /etc/passwd | cut -d : -f 1 ~~~ 7、列出/etc/passwd文件中所有用户名:分割开每一行中第一个字段就是用户名 ~~~ [rootlocalhost ~]# cat /etc/passwd | cut -d : -f1 | sort ~~~ 8、将/etc/passwd中内容按照冒号隔开的第三个字符从大到小排序后输出所有内容 ~~~ [rootlocalhost ~]# sort -t : -k 3 -n /etc/passwd ~~~ 9、列出/etc/passwd中的第20行-25行内容 ~~~ head -25 | tail -6 /etc/passwd ~~~ 10、切割出你的ip地址和mac地址 ~~~ [rootlocalhost ~]# ip a |grep global | cut -d -f6 | cut -d / -f1 [rootlocalhost ~]# ip a |grep link/ether | cut -d -f6 ~~~ 11、通过:切割出/etc/passwd中的最后一个字段并进行重复内容的重复次数统计 ~~~ [rootlocalhost ~]# cat /etc/passwd | cut -d : -f7 | sort | uniq -c ~~~ 12、通过df -h显示文件系统使用情况过滤显示/ 系统现在剩余大小在终端提示用户当前/系统的剩余大小为xx ~~~ [rootlocalhost ~]# echo 当前/系统的剩余大小为df -h / | grep -v Avail | cut -d -f9 ~~~ 13、查找/var所有的日志文件*.log备份在自定义的日志目录下/logfile。 ~~~ [rootlocalhost ~]# mkdir -p /logfile [rootlocalhost ~]# find /var -name *.log -exce cp -t {} /logdile \ ~~~ 14、将备份好的所有日志文件进行压缩格式为.gz 包名为all_log_backup.tar.gz。 ~~~ [rootlocalhost ~]# cd /var/logfile [rootlocalhost ~]# tar -czf all_log_backup.tar.gz*.log ~~~ 15、将压缩包中的文件解压到/root目录 ~~~ [rootlocalhost ~]# tar -xzf all_log_backup.tar.gz -C /root ~~~

更多文章