As we all know, there is no recycle bin concept in linux. Once the rm command deletes a file, it cannot be found. But in fact, there is still a saving problem. Previously, I knew a concept and a saving problem, but I didn't know how to save it in detail. So this time we will proceed with the actual operation.
In fact, why is there a saving problem? Before that, you need to have a rough understanding of the ext3 file system. When we create a file in the ext3 file system, it first applies for an inode number in the inode table of the ext3 file system, and then writes the file information and data. So what is the inode number? Inode consists of two parts: metadata, metadata, and the file name, size, permission, and access time, that is, information except the content and data of this file ., A new file "testfile" is created. We can use the stat command to view its information;
The other is a pointer. This Pointer Points to the block data area where the real data is stored. So when we look at the content of a file, we usually find the corresponding inode number through the file name, and then find the real data through the pointer in the inode number.
A file corresponds to an inode number, regardless of the size of the file to 1, 2 K, or 1, 2 GB. When we create a file system, the inode table is automatically created. Our inode number also belongs to the inode table. Of course, the default inode table also has a size. After the default upper limit is reached, we cannot create a file. We can use the "df-I" command to view the inode usage of each file system. Generally, the default division is sufficient. Of course, if your server handles small emails and small files, you can adjust the inode table size to make it bigger ., We can see the total number of inode in each file system, the number of inode used, the remaining number, and the percentage occupied;
So when we execute the command "rm-f testfile", what we delete is the association of the file name and inode corresponding to this file. The data is still in progress, at the same time, the inode used by this file is marked as available, so you should not create new files, that is, do not do any action on this file system, I think everyone knows this. If you create a new file, in the ext3 file system, the new file will reuse the inode that was previously marked as available, and your data will be in danger.
For example, the inode Number of the test file is 98315, and a new file is created after deletion. The inode Number of the test file uses the same inode number that was previously spare. Of course, this is different in different file systems. For example, in the RedHat GFS file system, the inode Number of the deleted file will be retained, the new file uses the new inode. Of course, in GFS, you can also use commands to clear invalid inode and restore it to a usable state.