首页 / 面试 / linux基础命令之企业面试题
linux基础命令之企业面试题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux基础命令之企业面试题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含6202字,纯文字阅读大概需要9分钟。
内容图文
![linux基础命令之企业面试题](/upload/InfoBanner/zyjiaocheng/1087/74cf064c4b774c91a7c50ae84cb822fe.jpg)
创建模拟数据:
[root@linzhongniao ~]# mkdir linzhongniao
[root@linzhongniao ~]# cd linzhongniao
[root@linzhongniao linzhongniao]# ls
[root@linzhongniao linzhongniao]# mkdir ext/linzhongniao test zhangsan lisi wanger -p
[root@linzhongniao linzhongniao]# touch nishishei linzhongniao wodi.gz nimei.gz
分析过程:要完成此题,要先想如何区分目录和文件?
方法:
(1)根据颜色区分文件和目录
(2)ls –l输出结果中以d(全拼directory)开头的就是目录。
(3)通过给目录加标识,然后过滤带标识的,就过滤出目录(ls –F或ls -p)-F表示不同的文件加不同的标识,-p表示只给目录加斜线。
linux基础命令
(4) 通过find查找指定类型的文件(-d 就是目录)
实战:方法一:
[root@linzhongniao linzhongniao]# ls -l
total 20
drwxr-xr-x. 3 root root 4096 Jul 3 15:29 ext
-rw-r--r--. 1 root root0 Jul 3 15:31 linzhongniao
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 lisi
-rw-r--r--. 1 root root0 Jul 3 15:31 nimei.gz
-rw-r--r--. 1 root root0 Jul 3 15:31 nishishei
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 test
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 wanger
-rw-r--r--. 1 root root0 Jul 3 15:31 wodi.gz
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 zhangsan
[root@linzhongniao linzhongniao]# ls -l|grep "^d" 《==尖括号表示以什么开头
drwxr-xr-x. 3 root root 4096 Jul 3 15:29 ext
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 lisi
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 test
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 wanger
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 zhangsan
方法二:
[root@linzhongniao linzhongniao]# ls -F
ext/ lisi/ nishishei wanger/ zhangsan/
linzhongniao nimei.gz test/ wodi.gz
[root@linzhongniao linzhongniao]# ls -F|grep "/$" 《== “/$”以斜杠结尾
ext/
lisi/
test/
wanger/
zhangsan/
方法三:
-maxdepth 1深度为1,最底层目录,因为第二层也会有目录那么不用这个参数有可能不准确,查找文件也是可以用的。
[root@linzhongniao linzhongniao]# find ./ -maxdepth 1 -type d ! -name "."
./ext
./wanger
./test
./zhangsan
./lisi
方法四:awk的过滤功能
[root@linzhongniao linzhongniao]# ls -l|awk ‘/^d/‘
drwxr-xr-x. 3 root root 4096 Jul 3 15:29 ext
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 lisi
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 test
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 wanger
drwxr-xr-x. 2 root root 4096 Jul 3 15:29 zhangsan
方法五:
[root@linzhongniao linzhongniao]# ls -F|sed -n ‘/\/$/p‘
ext/
lisi/
test/
wanger/
zhangsan/
2.删除apache日志
已知apache服务的访问日志文件按天记录在服务器本地目录/app/logs下,由于磁盘紧张,现在要求只能保留最近7天的访问日志。请问如何解决?
模拟数据
[root@linzhongniao ~]# cat chuangjianrizhi.sh
for n in `seq 15`
do
date -s "2018/07/$n"
touch /app/logs/access_www_$(date +%F).log
done
date -s ‘2018/07/16‘
[root@linzhongniao ~]# ls -lrt /app/logs/
total 0
-rw-r--r--. 1 root root 0 Jul 1 00:00 access_www_2018-07-01.log
-rw-r--r--. 1 root root 0 Jul 2 00:00 access_www_2018-07-02.log
-rw-r--r--. 1 root root 0 Jul 3 00:00 access_www_2018-07-03.log
-rw-r--r--. 1 root root 0 Jul 4 00:00 access_www_2018-07-04.log
-rw-r--r--. 1 root root 0 Jul 5 00:00 access_www_2018-07-05.log
-rw-r--r--. 1 root root 0 Jul 6 00:00 access_www_2018-07-06.log
-rw-r--r--. 1 root root 0 Jul 7 00:00 access_www_2018-07-07.log
-rw-r--r--. 1 root root 0 Jul 8 00:00 access_www_2018-07-08.log
-rw-r--r--. 1 root root 0 Jul 9 00:00 access_www_2018-07-09.log
-rw-r--r--. 1 root root 0 Jul 10 00:00 access_www_2018-07-10.log
-rw-r--r--. 1 root root 0 Jul 11 00:00 access_www_2018-07-11.log
-rw-r--r--. 1 root root 0 Jul 12 00:00 access_www_2018-07-12.log
-rw-r--r--. 1 root root 0 Jul 13 00:00 access_www_2018-07-13.log
-rw-r--r--. 1 root root 0 Jul 14 00:00 access_www_2018-07-14.log
-rw-r--r--. 1 root root 0 Jul 15 00:00 access_www_2018-07-15.log
解答:删除七天前的
先查看一下七天前的日志文件
[root@linzhongniao ~]# find /app/logs/ -type f -mtime +7
/app/logs/access_www_2018-07-07.log
/app/logs/access_www_2018-07-05.log
/app/logs/access_www_2018-07-08.log
/app/logs/access_www_2018-07-02.log
/app/logs/access_www_2018-07-03.log
/app/logs/access_www_2018-07-01.log
/app/logs/access_www_2018-07-04.log
/app/logs/access_www_2018-07-06.log
删除七天前的日志文件
方法一:fine结合xargs
[root@linzhongniao ~]# find /app/logs/ -type f -mtime +7|xargs rm -f
[root@linzhongniao ~]# ls -lrt /app/logs/
total 0
-rw-r--r--. 1 root root 0 Jul 9 00:00 access_www_2018-07-09.log
-rw-r--r--. 1 root root 0 Jul 10 00:00 access_www_2018-07-10.log
-rw-r--r--. 1 root root 0 Jul 11 00:00 access_www_2018-07-11.log
-rw-r--r--. 1 root root 0 Jul 12 00:00 access_www_2018-07-12.log
-rw-r--r--. 1 root root 0 Jul 13 00:00 access_www_2018-07-13.log
-rw-r--r--. 1 root root 0 Jul 14 00:00 access_www_2018-07-14.log
-rw-r--r--. 1 root root 0 Jul 15 00:00 access_www_2018-07-15.log
方法二:find结合-exec
[root@linzhongniao ~]# find /app/logs/ -type f -mtime +7 -exec rm -f {} \;
[root@linzhongniao ~]# ls -lrt /app/logs/
total 0
-rw-r--r--. 1 root root 0 Jul 9 00:00 access_www_2018-07-09.log
-rw-r--r--. 1 root root 0 Jul 10 00:00 access_www_2018-07-10.log
-rw-r--r--. 1 root root 0 Jul 11 00:00 access_www_2018-07-11.log
-rw-r--r--. 1 root root 0 Jul 12 00:00 access_www_2018-07-12.log
-rw-r--r--. 1 root root 0 Jul 13 00:00 access_www_2018-07-13.log
-rw-r--r--. 1 root root 0 Jul 14 00:00 access_www_2018-07-14.log
-rw-r--r--. 1 root root 0 Jul 15 00:00 access_www_2018-07-15.log
方法三:先用find查找出来在用rm删除
[root@linzhongniao ~]# rm -f `find /app/logs/ -type f -mtime +7`
[root@linzhongniao ~]# ls -lrt /app/logs/
total 0
-rw-r--r--. 1 root root 0 Jul 9 00:00 access_www_2018-07-09.log
-rw-r--r--. 1 root root 0 Jul 10 00:00 access_www_2018-07-10.log
-rw-r--r--. 1 root root 0 Jul 11 00:00 access_www_2018-07-11.log
-rw-r--r--. 1 root root 0 Jul 12 00:00 access_www_2018-07-12.log
-rw-r--r--. 1 root root 0 Jul 13 00:00 access_www_2018-07-13.log
-rw-r--r--. 1 root root 0 Jul 14 00:00 access_www_2018-07-14.log
-rw-r--r--. 1 root root 0 Jul 15 00:00 access_www_2018-07-15.log
3.装完系统后,希望让网络文件NFS,仅在3级别上开机自启动,该如何做?
第一种文件配置方法,可以把要重启的服务器的命令放在/etc/rc.local里。
解答:全部关掉然后开启需要的级别的服务。
[root@linzhongniao ~]# chkconfig nfs on
[root@linzhongniao ~]# chkconfig --list nfs
nfs 0:off 1:off 2:on3:on4:on5:on6:off
[root@linzhongniao ~]# chkconfig nfs off
[root@linzhongniao ~]# chkconfig --list nfs
nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@linzhongniao ~]# chkconfig --level 3 nfs on
[root@linzhongniao ~]# chkconfig --list nfs
nfs 0:off 1:off 2:off 3:on4:off 5:off 6:off
也可以将2345都开启
[root@linzhongniao ~]# chkconfig --level 2345 nfs on
[root@linzhongniao ~]# chkconfig --list nfs
nfs 0:off 1:off 2:on3:on4:on5:on6:off
原文:http://blog.51cto.com/14021533/2300792
内容总结
以上是互联网集市为您收集整理的linux基础命令之企业面试题全部内容,希望文章能够帮你解决linux基础命令之企业面试题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。