hello everyone , I'm Liang Xu .

With the use of computers , There will be a lot of garbage in the system , The most typical is that the same file is saved to different locations , As a result, the disk space is occupied , The system is running more and more slowly .

So if your computer space is in a hurry , You can try to delete a file like this , Free up some space . stay Linux lower , We can identify the inode Value to find the same file in the system .

inode Is a data structure , All the information in the file is recorded , In addition to file name and file content . If two or more files have the same inode
value , Even if they have different filenames , Different location , Their content , owner , Authority is the same , We can see it as the same document .

This type of document is actually called 「 Hard link 」. Hard links have the same inode value , But the file names are different . And soft links are shortcuts , It points to the target file , But it has its own inode
value .
$ ls -l my* -rw-r--r-- 4 liangxu liangxu 228 Apr 12 19:37 myfile lrwxrwxrwx 1
liangxu liangxu 6 Apr 15 11:18 myref -> myfile -rw-r--r-- 4 liangxu liangxu 228
Apr 12 19:37 mytwin
We can't directly know which files in the same directory have the same inode value , But it's not hard to recognize . In fact, we only need to use ls -i command , And then inode
Value to sort , You can find them directly .
$ ls -i | sort -n | more ... 788000 myfile <== 788000 mytwin <== 801865
Name_Labels.pdf 786692 never leave home angry 920242 NFCU_Docs 800247 nmap-notes
In the first column of this result , Is the corresponding inode value . So we can see it at a glance , Which files have the same inode value .

If you just want to find the corresponding hard link file of a file , We can use find command , Add another -samefile Options to quickly find .
$ find . -samefile myfile ./myfile ./save/mycopy ./mytwin
These files are all the same inode value , If you don't believe it, you can use it again ls Command to see more information :
$ find . -samefile myfile -ls 788000 4 -rw-r--r-- 4 liangxu liangxu 228 Apr 12
19:37 ./myfile 788000 4 -rw-r--r-- 4 liangxu liangxu 228 Apr 12 19:37
./save/mycopy 788000 4 -rw-r--r-- 4 liangxu liangxu 228 Apr 12 19:37 ./mytwin

We can see , In addition to the filename , These filenames have exactly the same information . Careful friends may notice , In section 2 column ( Number of hard connections ) yes 4, In fact, the only documents we found were 3 individual , It means there's another file to share with them
inode value , It's just that we didn't find out through this order .

As a lazy man , It's a lot of trouble to knock orders every time , Find out the same file in the directory directly through the script !
#!/bin/bash # seaches for files sharing inodes prev="" # list files by inode
ls -i | sort -n > /tmp/$0 # search through file for duplicate inode #s while
read line do inode=`echo $line | awk '{print $1}'` if [ "$inode" == "$prev" ];
then grep $inode /tmp/$0 fi prev=$inode done < /tmp/$0 # clean up rm /tmp/$0
Operation results :
$ ./findHardLinks 788000 myfile 788000 mytwin
Yes, of course , You can also use find command , according to inode value , Find all the same files in the system .
$ find / -inum 788000 -ls 2> /dev/null 788000 4 -rw-r--r-- 4 liangxu liangxu
228 Apr 12 19:37 /tmp/mycopy 788000 4 -rw-r--r-- 4 liangxu liangxu 228 Apr 12
19:37 /home/liangxu/myfile 788000 4 -rw-r--r-- 4 liangxu liangxu 228 Apr 12
19:37 /home/liangxu/save/mycopy 788000 4 -rw-r--r-- 4 liangxu liangxu 228 Apr
12 19:37 /home/liangxu/mytwin
In this order , We redirect the error message to /dev/null In this special document , So when we search for paths that we don't have access to , It won't be full permission
denied .

Technology
©2019-2020 Toolsou All rights reserved,
Hackbar Using the tutorial Hack Bar 2.1.2 Press F9 No response ( Essence )2020 year 6 month 26 day C# Class library Enum( Extension method ) Novices play hiss HI3520D Development board ( One , upgrade ) Theory and formula derivation of univariate linear regression and multiple linear regression Dijkstra Algorithmic Python realization - Shortest path problem Thoughts on multi tenant system python read , write in txt Text content vs2017, establish C++Win32 Windows Forms Application python Dynamic programming for single source shortest path