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

What if the space is not freed after Linux deletes the file?

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

Share

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

This article mainly explains "what to do if the space is not released after Linux deletes the file", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what to do if the space is not released after Linux deletes the file"!

When the system uses too much space and needs to clean up space or a file, sometimes the disk space is not released after executing the delete command. Many people will be confused when they encounter this situation for the first time. Are they considering whether deletion is just a logical deletion to the Recycle Bin like the Recycle Bin in the windows system? In fact, the linux Recycle Bin function can communicate with me or check the information to understand, it is also a more practical method, here we mainly practice the problem of unreleased space after file deletion. Preface

1. Experimental preparation

There are many ways to simulate this scenario, mainly by implementing the scenario in which the file is occupied. The easiest way is to copy files, and another common way is that students who are good at programming or shell can write programs or scripts to write content into a file constantly. This time, it can be reproduced quickly by copying files.

1.1 create a slightly larger file

/ * mainly operate on this file * / [root@c7_2 local] # ll-h total 3.0GMurray RWMUR Murray. 1 root root 2.5G May 4 17:43 all_backup.tar.gz / * Root directory usage 6.5 G * / [root@c7_2 ~] # df-lh Filesystem Size Used Avail Use% Mounted ondevtmpfs 1.9G 0 1.9G 0 / devtmpfs 1.9G 0 1.9G 0 0 / dev/shmtmpfs 1.9G 12M 1.9G 1% / runtmpfs 1.9G 0 1.9G 0 0 / sys/fs/cgroup/dev/mapper/centos-root 46G 6.5g 39G 15% / / dev/sda1 1014M 150M 865M 15% / boottmpfs 378M 0378M 0% / run/user/0

1.2 use the scp command to occupy the file

/ * start remote copying to other hosts * / [root@c7_2 local] # scp all_backup.tar.gz test@192.168.28.226:/home/test/ The authenticity of host '192.168.28.226 (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 file * / [root@c7_2 local] # rm-f all_backup.tar.gz / * View 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 0378m 0% / run/user/0/* file is no longer in * / [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 use the lsof (list opened files) command to see which files have been opened and which process the files are occupied by.

The lsof command is not available on minimized installed systems. You can install it through yum first.

Yum install-y lsof

2.1 lsof View Files

View all open files and filter out files with deleted status (deleted)

[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 04096 33554962 / tmp/ffio5Nu8r (deleted) tuned 1180 1603 root 8u REG 253 04096 33554962 / tmp/ffio5Nu8r ( Deleted) tuned 1180 1605 root 8u REG 253 deleted 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 View the process

Through lsof, it is found that the all_backup.tar.gz file is occupied by process 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

It is the copy command that we carried out before.

2.3 Free Space

For this kind of query status, you need to end the corresponding program.

/ * kill the corresponding process * / [root@c7_2 local] # kill-9 1799 1798amp * Space has been released * / [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 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 0378M 0% / run/user/0

Note: if you want to empty the log continuously, you can use the echo "> filename command to empty the file online, without the need for violence to end the process, and then try to end the process if this method is invalid.

3. Conclusion

This article is mainly applicable to the following scenarios:

Delete file space not freed

The disk is full but the file cannot be found.

Again, if you can use the echo "" > filename command to empty the file online, you don't need to end the process violently, and try to end the process again if this method doesn't work.

At this point, I believe that everyone on the "Linux delete files after the space is not released how to do" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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