Linux下如何尋找相同文件?

Linux下如何尋找相同文件?

Linux下如何尋找相同文件?


資料來源: https://mp.weixin.qq.com/s?__biz=MzU3NTgyODQ1Nw==&mid=2247491537&idx=2&sn=9bacb3178f143ff4415548f0b127b0ad&chksm=fd1c6757ca6bee41777cfe0fda83556f1e385c459ee098fc248c76aa76be836e15e35106521d&scene=126&sessionid=1592786048&key=2eaef6333c5ec5d2663c5d22b0f36837677b728066676bd1925a4153252fa81c87292744299c967cd282393d5315395240a6ee51243321d0f47b8522bb9c329abc30962c34c8027d78ff42642591287b&ascene=1&uin=MjIwODk2NDgxNw%3D%3D&devicetype=Windows+10+x64&version=62090523&lang=zh_TW&exportkey=AvlkPF32lZjgOA%2BH4V9eJ7E%3D&pass_ticket=gLXJBYBdM3KuCBrQtEskXmIhQhdajwK5AX8G8d7WwNZbF5CIYK5K9pMfHipa%2FNLD


方法01.

$ 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


方法02.

ls -i | sort -n | more
 ...
 788000 myfile    <==
 788000 mytwin    <==
 801865 Name_Labels.pdf
 786692 never leave home angry
 920242 NFCU_Docs
 800247 nmap-notes

 


方法03.

$ find . -samefile myfile
./myfile
./save/mycopy
./mytwin


方法04.

$ 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


方法05.

#!/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

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *