实训day06

1. 使⽤ls查看/etc/⽬录下所有的⽂件信息

[root@localhost ~]# ls -l /etc/

总用量 1312

-rw-r--r--.  1 root root       16 7月  12 02:29 adjtime

-rw-r--r--.  1 root root     1518 6月   7 2013 aliases

-rw-r--r--.  1 root root    12288 7月  12 02:42 aliases.db

drwxr-xr-x.  2 root root     4096 7月  11 21:30 alternatives

-rw-------.  1 root root      541 4月  11 2018 anacrontab

-rw-r--r--.  1 root root       55 4月  11 2018 asound.conf

drwxr-x---.  3 root root       43 7月  12 02:27 audisp

drwxr-x---.  3 root root       83 7月  12 02:42 audit

drwxr-xr-x.  2 root root       33 7月  11 20:08 bash_completion.d

2. 使⽤ls查看/etc/⽬录下名包含“a”字⺟的⽂件或者⽬录信息

[root@localhost ~]# ls -l /etc/ | grep a

-rw-r--r--.  1 root root       16 7月  12 02:29 adjtime

-rw-r--r--.  1 root root     1518 6月   7 2013 aliases

-rw-r--r--.  1 root root    12288 7月  12 02:42 aliases.db

drwxr-xr-x.  2 root root     4096 7月  11 21:30 alternatives

-rw-------.  1 root root      541 4月  11 2018 anacrontab

-rw-r--r--.  1 root root       55 4月  11 2018 asound.conf

drwxr-x---.  3 root root       43 7月  12 02:27 audisp

drwxr-x---.  3 root root       83 7月  12 02:42 audit

drwxr-xr-x.  2 root root       33 7月  11 20:08 bash_completion.d

-rw-r--r--.  1 root root     2853 4月  11 2018 bashrc

-rw-r--r--.  1 root root       38 4月  29 2018 centos-release

-rw-r--r--.  1 root root       51 4月  29 2018 centos-release-upstream

3. 使⽤ls查看/etc/⽬录下以".conf"结尾的⽂件信息

[root@localhost ~]# ls -l /etc/ | grep .conf$

-rw-r--r--.  1 root root       55 4月  11 2018 asound.conf

-rw-r--r--.  1 root root     1108 4月  13 2018 chrony.conf

-rw-r--r--.  1 root root     1285 4月  11 2018 dracut.conf

-rw-r--r--.  1 root root      112 4月  11 2018 e2fsck.conf

-rw-r--r--.  1 root root       38 4月  11 2018 fuse.conf

-rw-r--r--.  1 root root      842 11月  6 2016 GeoIP.conf

-rw-r--r--.  1 root root        9 6月   7 2013 host.conf

-rw-r--r--.  1 root root     7265 7月  12 02:27 kdump.conf

-rw-r--r--.  1 root root      590 4月  11 2018 krb5.conf

-rw-r--r--.  1 root root       28 2月  28 2013 ld.so.conf

-rw-r-----.  1 root root      191 10月 12 2017 libaudit.conf

-rw-r--r--.  1 root root     2391 10月 13 2013 libuser.conf

-rw-r--r--.  1 root root       19 7月  12 02:29 locale.conf

4. 使⽤ls查看/etc/⽬录中以"y"字⺟开头的⽂件信息

[root@localhost ~]# ls -l /etc/ | grep ^y

5. find查找/var/⽬录中以“.log”⽂件

[root@localhost ~]# find /var/ -type f -name '*.log'

/var/log/tuned/tuned.log

/var/log/audit/audit.log

/var/log/anaconda/anaconda.log

/var/log/anaconda/X.log

/var/log/anaconda/program.log

/var/log/anaconda/packaging.log

/var/log/anaconda/storage.log

/var/log/anaconda/ifcfg.log

/var/log/anaconda/ks-script-ua9yku.log

/var/log/anaconda/ks-script-zomTMx.log

/var/log/anaconda/journal.log

/var/log/boot.log

/var/log/vmware-vmsvc.log

/var/log/yum.log

/var/log/mysqld.log

6. 在opt⽬录下创建test⽬录

[root@localhost ~]# mkdir /opt/test

7. 在test⽬录中创建abc.txt,def.txt.ghi.txt,xxx.txt.yyy.txt五个⽂件

[root@localhost ~]# touch /opt/test/abc.txt /opt/test/def.txt /opt/test/ghi.txt /opt/test/xxx.txt /opt/test/yyy.txt

8. 修改以上5个⽂件的最后修改时间分别为15,14,13,12,11,10⽇

[root@localhost ~]# touch -m -d '2024-7-15 00:00' /opt/test/abc.txt

[root@localhost ~]# touch -m -d '2024-7-14 00:00' /opt/test/def.txt

[root@localhost ~]# touch -m -d '2024-7-13 00:00' /opt/test/ghi.txt

[root@localhost ~]# touch -m -d '2024-7-12 00:00' /opt/test/xxx.txt

[root@localhost ~]# touch -m -d '2024-7-11 00:00' /opt/test/yyy.txt

9. 在test⽬录下创建a⽬录

[root@localhost ~]# mkdir /opt/test/a

10. 将以上5个⽂件复制⼀份到a⽬录中

[root@localhost ~]# cp /opt/test/*.txt /opt/test/a/

[root@localhost ~]# ls /opt/test/a

abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt

11. 将a⽬录⽂件做成bak.tar.gz⽂件保存到家⽬录中

[root@localhost ~]# tar -zcvf bak.tar.gz /opt/test/a

12. 使⽤find删除test⽬录下3天前的⽂件

[root@localhost ~]# find /opt/test/ -mtime +3 -exec rm -rf {} \;

[root@localhost ~]# ls /opt/test/

a  abc.txt  def.txt  ghi.txt  xxx.txt

13. find删除opt⽬录下3天内的⽂件

find /opt/ -type f -mtime -3 -exec rm -rf {} \;

14. find删除正好第三天的⽂件

find /opt/ -type f -mtime 3 -exec rm -rf {} \;

15. 将/opt/test/a⽬录中的⽂件复制i⼀份到/opt/test/⽬录下

cp -r /opt/test/a/ /opt/test/

16. 创建⽬录/opt/test0

mkdir /opt/test0

17. 在/opt/test0/⽬录中创建三个⽂件 a.mp4(5M),b.mp4(20M),c.mp4(80M)

[root@kk test0]# dd if=/dev/zero of=/opt/test0/a.mp4 bs=5M count=1

记录了1+0 的读入

记录了1+0 的写出

5242880字节(5.2 MB)已复制,0.00789588 秒,664 MB/秒

[root@kk test0]# dd if=/dev/zero of=/opt/test0/b.mp4 bs=20M count=1

记录了1+0 的读入

记录了1+0 的写出

20971520字节(21 MB)已复制,0.0454609 秒,461 MB/秒

[root@kk test0]# dd if=/dev/zero of=/opt/test0/c.mp4 bs=80M count=1

记录了1+0 的读入

记录了1+0 的写出

83886080字节(84 MB)已复制,0.180239 秒,465 MB/秒

18. 创建⽬录/opt/test0/b/

[root@kk test0]# mkdir /opt/test0/b

19. 将/op t/test0/中的⽂件复制⼀份/opt/test0/b/⽬录中

[root@kk test0]# cp -r /opt/test0/ /var/test0/

[root@kk test0]# cp -r /var/test0 /opt/test0/b/

cp:是否覆盖"/opt/test0/b/test0/a.mp4"? y

cp:是否覆盖"/opt/test0/b/test0/b.mp4"? y

cp:是否覆盖"/opt/test0/b/test0/c.mp4"? y

20. find查询/opt/test0/⽬录中⽂件⼤于20M的,并删除

[root@kk test0]# find /opt/test0/ -type f -size +20M -exec rm -rf {} \;

21. find查询/opt/test0/⽬录中⽂件⼩于20M的⽂件并删除

[root@kk test0]# find /opt/test0/ -type f -size -20M -exec rm -rf {} \;

22. find查找/opt/test0/⽬录中⽂件size为20M的⽂件并删除

[root@kk test0]# find /opt/test0/ -type f -size 20M -exec rm -rf {} \;

23. /opt/test0/b中的⽂件复制⼀份到/opt/test0中

[root@kk test0]# cp -r /opt/test0/b/ /opt/test0/

24. 打开新的虚拟主机

25. 将家⽬录中的bak.tar.gz⽂件上传到新主机的/opt⽬录中

scp /bak.tar.gz root@192.168.2.188:/opt/

26. 将新主机的/e tc/skel/⽬录下载到 当前主机的/opt⽬录中

scp -r root@192.168.2.188:/etc/skel /opt/

27. 设置计划任务,每周3将/e tc/yum.repos.d/⽬录下的.repo⽂件压缩保存到tmp,在⽂件

名中添加时间戳

  • 12
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的C语言万年历的实训报告,供您参考: 一、实训目的 本次实训的主要目的是通过编写一个简单的C语言万年历程序,巩固C语言基本语法和编程思想,提高编程能力和解决问题的能力。 二、实训要求 1、能够使用C语言基本语法和控制语句编写程序。 2、能够使用数组来存储和操作数据。 3、能够使用函数来实现模块化编程。 4、能够使用指针来操作内存中的数据。 5、能够使用文件来读取和写入数据。 三、实训内容 1、程序功能 本程序实现了一个简单的万年历功能,可以通过输入年份和月份来显示该月的日历。 2、程序实现 以下是本程序的主要代码实现: ```c #include <stdio.h> // 判断是否为闰年 int is_leap_year(int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { return 1; } else { return 0; } } // 获取某个月份的总天数 int get_days(int year, int month) { int days[] = {31, 28 + is_leap_year(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; return days[month - 1]; } // 获取某个日期是星期几 int get_weekday(int year, int month, int day) { if (month == 1 || month == 2) { year--; month += 12; } int c = year / 100; int y = year % 100; int w = y + y / 4 + c / 4 - 2 * c + 26 * (month + 1) / 10 + day - 1; w = (w % 7 + 7) % 7; return w; } // 显示日历 void show_calendar(int year, int month) { int days = get_days(year, month); int weekday = get_weekday(year, month, 1); printf(" 日 一 二 三 四 五 六\n"); int i; for (i = 0; i < weekday; i++) { printf(" "); } for (i = 1; i <= days; i++) { printf("%2d ", i); if ((weekday + i) % 7 == 0) { printf("\n"); } } if ((weekday + days) % 7 != 0) { printf("\n"); } } int main() { int year, month; printf("请输入年份:"); scanf("%d", &year); printf("请输入月份:"); scanf("%d", &month); if (month < 1 || month > 12) { printf("月份输入错误!\n"); return 1; } printf(" %d年%d月\n", year, month); show_calendar(year, month); return 0; } ``` 四、实训总结 通过本次实训,我学会了如何使用C语言来编写一个简单的万年历程序,巩固了C语言基本语法和编程思想,加强了对函数、数组、指针、文件等概念和用法的理解,提高了编程能力和解决问题的能力。同时,我也意识到在编程过程中需要注重代码的规范、可读性和可维护性,这对于日后的开发工作非常重要。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值