Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check the space usage in Linux

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to view the use of space in Linux, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Step 1: check the file system usage of the Linux system. You can see that 81% of the root directory "/" has been used.

[root@hostname] # df-hFilesystem Size Used Avail Use% Mounted on/dev/sda6 67G 51G 13G 81% / tmpfs 16G 152K 16G 1% / dev/shm/dev/sda3 99G 188M 94G 1% / arch/dev/sda1 197G 188M 187G 1% / u01/dev/sda2 197G 50G 138G 27% / u02

Step 2: enter the root directory and use the du-sh command to query the space occupied by each directory or file. Because / U02 is a separate file system, it can be ignored. We focus on the root directory, which takes up 47 gigabytes of space.

[root@hostname ~] # cd / [root@hostname /] # du-sh * 20K arch7.6M bin27M boot324K dev36M etc36K home136M lib26M lib6416K lost+found4.0K media0 misc4.0K mnt0 net8.0K opt4.0K orbit-root-- omitted / proc directory statistics error 0 proc47G root # # the root file system uses the largest directory 15m sbin0 selinux4.0K srv0 sys80K tmp20K u0149G u02

Step 3: enter the root directory, which is actually the home directory of the root user. We can guess from the ls command that the program directory of [apache-tomcat-6.0.36-linux] this tomcat is more occupied.

[root@hostname /] # cd root [root@hostname ~] # lsanaconda-ks.cfg apache-tomcat-6.0.36-linux Desktop Documents Downloads install.log install.log.syslog Music Pictures Public Templates Videos

Step 4: through statistics, it is found that [apache-tomcat-6.0.36-linux] this directory indeed occupies 47g. But the problem is not over yet, because since it is the directory of the application, in my experience it is likely that tomcat's log files take up a lot of space.

[root@hostname ~] # du-sh * 4.0K anaconda-ks.cfg47G apache-tomcat-6.0.36-linux4.0K Desktop4.0K Documents4.0K Downloads56K install.log12K install.log.syslog4.0K Music4.0K Pictures4.0K Public4.0K Templates4.0K Videos

Step 5: now that you see the directory of tomcat, it is very likely that the tomcat is running. Use the ps command to see if there is a process of tomcat, and you can generally filter the keyword java. As follows, sure enough, there is a tomcat running. Then it is likely that the log file that takes up the most space is tomcat.

[root@hostname] # ps-ef | grep javaroot 4879 4836 0 08:26 pts/0 00:00:00 grep javaroot 11864 1 47 Aug16? 26-03:11:29 / usr/bin/java-Djava.util.logging.config.file=/root/apache-tomcat-6.0.36-linux/conf/logging.properties-Xms512m-Xmx1024m-XX:PermSize=128M-XX:MaxPermSize=256m-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager-Djava.endorsed.dirs=/root/apache-tomcat-6 .0.36-linux/endorsed-classpath / root/apache-tomcat-6.0.36-linux/bin/bootstrap.jar-Dcatalina.base=/root/apache-tomcat-6.0.36-linux-Dcatalina.home=/root/apache-tomcat-6.0.36-linux-Djava.io.tmpdir=/root/apache-tomcat-6.0.36-linux/temp org.apache.catalina.startup.Bootstrap start

Step 6: enter the tomcat program directory to see which directory takes up the most space. As shown below, it is found that a [fare] directory takes up 46G, while [logs] is a log directory that takes 23m.

[root@hostname ~] # cd apache-tomcat-6.0.36-linux [root@hostname apache-tomcat-6.0.36-linux] # lsbackup bin conf fare lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work [root@hostname apache-tomcat-6.0.36-linux] # du-sh * 92K backup882M bin108K conf46G fare6.8M lib40K LICENSE23M logs4.0K NOTICE12K RELEASE-NOTES16K RUNNING.txt7.9M temp188M webapps7.1M work

Step 7: continue to find out what type of directory or file is stored in the [fare] directory. You can see below that there are many similar log files, such as common.log and pricing.log. After communicating with the developer, determine the exact log file.

[root@hostname apache-tomcat-6.0.36-linux] # cd fare [root@hostname fare] # lscommon.log common.log.2017-09-21 common.log.2017-10-03 pricing.log.2017- 09-10 pricing.log.2017- 09-22 pricing.log.2017- 10-04common.log.2017-09-10 common.log.2017-09-22 common.log.2017-10-04 pricing.log.2017- 09-11 pricing.log.2017- 09-23 pricing.log.2017-10-05common.log.2017-09-11 common.log.2017-09-23 common.log.2017-10-05 pricing.log.2017-09-12 pricing.log.2017-09-24 pricing.log.2017-10-06common.log.2017-09-12 common.log.2017-09-24 common.log.2017-10-06 pricing.log.2017-09-13 pricing.log.2017-09-25 pricing.log.2017-10-07common .log.2017-09-13 common.log.2017-09-25 common.log.2017-10-07 pricing.log.2017-09-14 pricing.log.2017-09-26 pricing.log.2017-10-08common.log.2017-09-14 common.log.2017-09-26 common.log.2017-10-08 pricing.log.2017-09-15 pricing.log.2017-09-27 pricing.log.2017-10-09common.log.2017-09-15 common.log. 2017-09-27 common.log.2017-10-09 pricing.log.2017-09-16 pricing.log.2017-09-28 spring.logcommon.log.2017-09-16 common.log.2017-09-28 common.zip pricing.log.2017-09-17 pricing.log.2017-09-29 struts2.logcommon.log.2017-09-17 common.log.2017-09-29 framework.log pricing.log.2017-09-18 pricing.log.2017-09- 30 xwork2.logcommon.log.2017-09-18 common.log.2017-09-30 hibernate.log pricing.log.2017-09-19 pricing.log.2017-10-01common.log.2017-09-19 common.log.2017-10-01 hibernate.log.2017-01-03 pricing.log.2017-09-20 pricing.log.2017-10-02common.log.2017-09-20 common.log.2017-10-02 pricing.log pricing.log.2017-09-21 pricing.log.2017-10-03

Step 8: continue to check which directory or file takes up the most space, and it is found that the files related to common.log and pricing.log take up the most space, all above 700m. At this point, it has been identified that the reason that takes up the most "/" space in the root directory is that tomcat has too many log files, and each log file is very large.

[root@hostname fare] # du-sh * | sort-h0 framework.log0 hibernate.log.2017-01-030 spring.log0 struts2.log0 xwork2.log4.0K hibernate.log17M common.zip215M pricing.log216M common.log667M pricing.log.2017-10-08668M common.log.2017-10-08674M common.log.2017-10-05674M pricing.log.2017-10-05678M common.log.2017-10-07678M pricing.log.2017-10-07679M common.log.2017-10-06679M pricing. Log.2017-10-06683M common.log.2017-10-04683M pricing.log.2017-10-04690M pricing.log.2017-09-10691M common.log.2017-09-10711M common.log.2017-09-12711M pricing.log.2017-09-12719M pricing.log.2017-09-11720M common.log.2017-09-11737M common.log.2017-09-30737M pricing.log.2017-09-28737M pricing.log.2017-09-30738M common.log.2017-09-28742M common.log.2017 -0929742M pricing.log.2017-0929744M pricing.log.2017-10-09745M common.log.2017-10-09751M common.log.2017-10-01751M pricing.log.2017-10-01754M common.log.2017-0913754M pricing.log.2017-0913760M common.log.2017-10-03760M pricing.log.2017-10-03783M pricing.log.2017-10-02784M common.log.2017-10-02791M pricing.log.2017-0918792M common.log.2017-09m 18797M common.log.2017-09-27797M pricing.log.2017-09-27804M common.log.2017-09-17804M common.log.2017-09-19804M pricing.log.2017-09-17804M pricing.log.2017-09-19808M common.log.2017-09-26808M pricing.log.2017-09-26815M pricing.log.2017-09-24816M common.log.2017-09-24821M common.log.2017-09-14821M pricing.log.2017-09-14821M pricing.log.2017-09-23822M common. Log.2017-09-23826M common.log.2017-09-25826M pricing.log.2017-09-25827M common.log.2017-09-16827M pricing.log.2017-09-15827M pricing.log.2017-09-16828M common.log.2017-09-15831M common.log.2017-09-22831M pricing.log.2017-09-22851M common.log.2017-09-21851M pricing.log.2017-09-21860M common.log.2017-09-20860M pricing.log.2017-09-20

Step 9: from the command rule of the file, you can see that the log file date is retained for one month, and check whether the root user has a regular plan to delete the log file. As shown in the following command, there is indeed a plan for log file deletion at 03:15 every morning. However, due to too many log files and the size of the root directory space, the proportion of root directory space is too high. When automatic monitoring tools such as zabbix are deployed, alarms will be sent automatically.

[root@hostname ~] # crontab-l15 3 * / u02 xargs rm name rmpound log _ pricing.sh [root @ hostname ~] # cat / u02/shell/rm_log_pricing.shfind / root/apache-tomcat-6.0.36-linux/bin/fare/-name "common.log.2*"-mtime + 30 | xargs rm-ffind / root/apache-tomcat-6.0.36-linux/bin/fare/-name "pricing.log.2*"- Mtime + 30 | xargs rm-f how to check the space usage in Linux Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report