In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you how to do after Linux file deletion space is not released, the content is simple and easy to understand, I hope you can learn, after learning, there will definitely be gains, let Xiaobian take you to see it.
preface
When the system space usage is too large to clean up space or clean up a file, sometimes disk space is not released after executing the delete command. Many people will be confused when they encounter this situation for the first time. Is it like the recycle bin of the windows system? Delete is just a logical deletion to the recycle bin. In fact, otherwise, linux recycle bin function want to know can communicate with me or check the information to understand, is also a more practical method, here we mainly practice file deletion after the space is not released.
1. Experimental preparation
There are many ways to simulate this scenario, mainly to realize the scenario where the file is occupied. The easiest way is to copy files, another common way is for students who can program or shell skills can write programs or scripts to keep writing content to a file. This time, it is mainly reproduced by copying files quickly.
1.1 Create a slightly larger file
/* Mainly for this file */[root@c7_2 local]# ll -h total 3.0G-rw-r--r--. 1 root root 2.5G May 4 17:43 all_backup.tar.gz/* root directory usage at this time 6.5G */[root@c7_2 ~]# df -lh Filesystem Size Used Avail Use% Mounted ondevtmpfs 1.9G 0 1.@G 0% /devtmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs 1.9G 12M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/centos @ root 46G 6.5G 39G 15% //dev/sda1 1014M 150M 865M 15% /boottmpfs 378M 0 378M 0% /run/user/0
1.2 occupy the file by scp command
/* Start remote copy to other host */[root@c7_2 local]# scp all_backup.tar.gz test@192.168.28.226:/home/test/ The authenticity of host '192.168.28.222 Six.(192.168.28.226)' can't be established.ECDSA key fingerprint is SHA256:QfJb1DogFmdZ0hkeVRvn2VHke+tkZ2+sNljhBBudooc.ECDSA key fingerprint is MD5:2a:8a:63:80:35:17:f7:e9:2a:ea:13:98:eb:26:30:ba.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '192.168.28.226' (ECDSA) to the list of known hosts.test@192.168.28.226's password: all_backup.tar.gz 0% 2432KB 2.4MB/s 17:53 ETA^Z[1]+ Stopped scp all_backup.tar.gz test@192.168.28.226:/home/test Run in the background */[root@c7_2 local]# bg %1 [1]+ scp all_backup.tar.gz test@192.168.28.226:/home/test &
1.3 delete files
/* Delete files */[root@c7_2 local]# rm -f all_backup. tar. gz/* Check disk space, no change */[root@c7_2 local]# df -lh Filesystem Size Used Avail Use% Mounted ondevtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs 1.9G 12M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/centos-root 46G 6.5G 39G 15% //dev/sda1 1014M 150M 865M 15% /boottmpfs 378M 0 378M 0% /run/user/0/* File no longer exists */[root@c7_2 local]# ll -h total 3.0Gdrwxr-xr-x. 2 root root 6 Apr 11 2018 bindrwxr-xr-x. 2 root root 6 Apr 11 2018 etcdrwxr-xr-x. 2 root root 6 Apr 11 2018 gamesdrwxr-xr-x. 2 root root 6 Apr 11 2018 includedrwxr-xr-x. 2 root root 6 Apr 11 2018 libdrwxr-xr-x. 2 root root 6 Apr 15 05:56 lib64drwxr-xr-x. 2 root root 6 Apr 11 2018 libexecdrwxr-xr-x. 2 root root 6 Apr 11 2018 sbindrwxr-xr-x. 5 root root 49 Nov 17 16:46 sharedrwxr-xr-x. 2 root root 6 Apr 11 2018 src
2. Treatment method
You can check which files are open and which processes are using the lsof (list opened files) command.
The lsof command is not available in minimal installation systems, and can be installed via yum first.
yum install -y lsof
2.1 lsof View Files
View all open files and filter out files with deleted status
[root@c7_2 local]# lsof |grep deletedfirewalld 818 root 6u REG 253,0 4096 36061750 /tmp/ffi0SEit6 (deleted)gmain 818 998 root 6u REG 253,0 4096 36061750 /tmp/ffi0SEit6 (deleted)tuned 1180 root 8u REG 253,0 4096 33554962 /tmp/ffio5Nu8r (deleted)gmain 1180 1602 root 8u REG 253,0 4096 33554962 /tmp/ffio5Nu8r (deleted)tuned 1180 1603 root 8u REG 253,0 4096 33554962 /tmp/ffio5Nu8r (deleted)tuned 1180 1605 root 8u REG 253,0 4096 33554962 /tmp/ffio5Nu8r (deleted)tuned 1180 1606 root 8u REG 253,0 4096 33554962 /tmp/ffio5Nu8r (deleted)scp 1798 root 3r REG 253,0 2665433605 104181296 /usr/local/all_backup.tar.gz (deleted)
Found the file we just deleted and opened by that process
2.2 viewing process
Through lsof, it was found that the all_backup.tar.gz file was occupied by the process No. 1798. You can see what the process is.
[root@c7_2 local]# ps -ef|grep 1798root 1798 1729 0 17:47 pts/0 00:00:00 scp all_backup.tar.gz test@192.168.28.226:/home/testroot 1799 1798 2 17:47 pts/0 00:00:03 /usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -l test -- 192.168.28.. 226 scp -t /home/testroot 1868 1806 0 17:49 pts/1 00:00:00 grep --color=auto 1798
The exact copy order we executed earlier.
2.3 free up space
For this query status, the corresponding program needs to be terminated
/* Kill process */[root@c7_2 local]# kill -9 1799 1798/* Space freed */[root@c7_2 local]# df -lh Filesystem Size Used Avail Use% Mounted ondevtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs 1.9G 12M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/mapper/centos-root 46G 4.0G 42G 9% //dev/sda1 1014M 150M 865M 15% /boottmpfs 378M 0 378M 0% /run/user/0
Note: If you want to empty the log continuously, you can use echo " ">filename command to empty the file online, without violence to end the process, if this method is invalid, then consider the end of the process.
3. Conclusion
This article applies primarily to the following scenarios:
Deleted file space not freed Disk full but no file found
Again, if you can use echo " ">filename to empty files online, then there is no need to end the process violently, if this method does not work, then consider ending the process again.
The above is about Linux files deleted after the space is not released how to do, if you have learned knowledge or skills, you can share it to let more people see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.