FSlint 可以找到重复的文件。但是假设有 10,000 首歌曲或图像,并且只想找到那些相同但名称不同的文件?现在,我得到一个列表,其中包含数百个重复项(在不同的文件夹中)。我希望名称一致,所以我只想看到名称不同的相同文件,而不是名称相同的相同文件。
具有高级参数(或不同程序)的 FSlint 可以实现这一点吗?
如果您同意脚本打印具有相同和不同文件名的所有重复文件,您可以使用以下命令行:
find . -type f -exec sha256sum {} \; | sort | uniq -w64 --all-repeated=separate | cut -b 67-
Run Code Online (Sandbox Code Playgroud)
对于示例运行,我使用以下目录结构。具有相似名称(和不同编号)的文件具有相同的内容:
.
??? dir1
? ??? uname1
? ??? uname3
??? grps
??? lsbrelease
??? lsbrelease2
??? uname1
??? uname2
Run Code Online (Sandbox Code Playgroud)
现在让我们看看我们的命令做了一些魔法:
$ find . -type f -exec sha256sum {} \; | sort | uniq -w64 --all-repeated=separate | cut -b 67-
./lsbrelease
./lsbrelease2
./dir1/uname1
./dir1/uname3
./uname1
./uname2
Run Code Online (Sandbox Code Playgroud)
由新行分隔的每个组由内容相同的文件组成。不列出非重复文件。
我有另一个更灵活且易于使用的解决方案供您使用!
复制下面的脚本并将其粘贴到/usr/local/bin/dupe-check(或任何其他位置和文件名,您需要 root 权限)。
通过运行以下命令使其可执行:
sudo chmod +x /usr/local/bin/dupe-check
Run Code Online (Sandbox Code Playgroud)
正如/usr/local/bin在每个用户的 PATH 中一样,每个人现在都可以直接运行它而无需指定位置。
首先,您应该查看我的脚本的帮助页面:
$ dupe-check --help
usage: dupe-check [-h] [-s COMMAND] [-r MAXDEPTH] [-e | -d] [-0]
[-v | -q | -Q] [-g] [-p] [-V]
[directory]
Check for duplicate files
positional arguments:
directory the directory to examine recursively (default '.')
optional arguments:
-h, --help show this help message and exit
-s COMMAND, --hashsum COMMAND
external system command to generate hashes (default
'sha256sum')
-r MAXDEPTH, --recursion-depth MAXDEPTH
the number of subdirectory levels to process: 0=only
current directory, 1=max. 1st subdirectory level, ...
(default: infinite)
-e, --equal-names only list duplicates with equal file names
-d, --different-names
only list duplicates with different file names
-0, --no-zero do not list 0-byte files
-v, --verbose print hash and name of each examined file
-q, --quiet suppress status output on stderr
-Q, --list-only only list the duplicate files, no summary etc.
-g, --no-groups do not group equal duplicates
-p, --path-only only print the full path in the results list,
otherwise format output like this: `'FILENAME'
(FULL_PATH)´
-V, --version show program's version number and exit
Run Code Online (Sandbox Code Playgroud)
您会看到,要获取当前目录(和所有子目录)中具有不同文件名的所有文件的列表,您需要该-d标志和任何有效的格式选项组合。
我们仍然假设相同的测试环境。具有相似名称(和不同编号)的文件具有相同的内容:
.
??? dir1
? ??? uname1
? ??? uname3
??? grps
??? lsbrelease
??? lsbrelease2
??? uname1
??? uname2
Run Code Online (Sandbox Code Playgroud)
所以我们只需运行:
$ dupe-check
Checked 7 files in total, 6 of them are duplicates by content.
Here's a list of all duplicate files:
'lsbrelease' (./lsbrelease)
'lsbrelease2' (./lsbrelease2)
'uname1' (./dir1/uname1)
'uname1' (./uname1)
'uname2' (./uname2)
'uname3' (./dir1/uname3)
Run Code Online (Sandbox Code Playgroud)
这是脚本:
sudo chmod +x /usr/local/bin/dupe-check
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4748 次 |
| 最近记录: |