linux week3

 

2.如何快速的回到 上⼀一次所在的位置 

cd An argument of - is equivalent to $OLDPWD. 
cd -  #cd $OLDPWD cd - #快速的回到 上⼀一次所在的位置 
cd .  #当前目录 复制/移动 
cd .. #进入当前⽬目录的上级⽬目录 
cd ~  #进入当前⽬目录的家⽬目录 回⽼老老家 
cd    #进⼊当前⽬目录的家⽬目录 等同于cd ~
 
 
 

第4题 

已知apache/nginx服务的访问⽇日志按天记录在服务器本地⽬目录/app/logs 下,由于磁盘空间紧张,现在要求只能保留留最近7天访问⽇日志!请问如何解决? 请给出解决 办法或配置或处理理命令。(提示:可以从apache服务配置上着手,也可以从⽣生成出来的日志上着手。)
 
模拟环境
mkdir -p /app/logs 
cd /app/logs 
for time in {01..15};do date -s "201806$time"; touch access_www_$(date +%F).log ;done
date -s "20170520" 
1.
[root@web02 logs]# find /app/logs -type f -mtime +7 |xargs ls -lrt
-rw-r--r-- 1 root root 0 6月 1 00:00 /app/logs/access_www_2018-06-01.log
-rw-r--r-- 1 root root 0 6月 2 00:00 /app/logs/access_www_2018-06-02.log
-rw-r--r-- 1 root root 0 6月 3 00:00 /app/logs/access_www_2018-06-03.log
-rw-r--r-- 1 root root 0 6月 4 00:00 /app/logs/access_www_2018-06-04.log
-rw-r--r-- 1 root root 0 6月 5 00:00 /app/logs/access_www_2018-06-05.log
-rw-r--r-- 1 root root 0 6月 6 00:00 /app/logs/access_www_2018-06-06.log
-rw-r--r-- 1 root root 0 6月 7 00:00 /app/logs/access_www_2018-06-07.log
找出/app/logs下⾯面以.log结尾的并且修改时间是7天之前的⽂文件并删除(ls -l) 
 
[root@web02 logs]# find /app/logs -type f -name "*.log" -mtime +7 |xargs ls -lrt
 
2.
[root@web02 logs]# ls -lrt $(find /app/logs -type f -name "*.log" -mtime +7)
3.
[root@web02 logs]# find /app/logs -type f -name "*.log" -mtime +7 -exec ls -l {} \;
4.
通过系统软件对⽇日志进⾏行行切割
 

猜你喜欢

转载自www.cnblogs.com/wenyule/p/8c0bf725342edef852d2006bde03ce62.html