Skip to content

Instantly share code, notes, and snippets.

@HirbodBehnam
Created July 28, 2024 08:28
Show Gist options
  • Save HirbodBehnam/b86d4b6318c47bf9b80fbd1ec08906a0 to your computer and use it in GitHub Desktop.
Save HirbodBehnam/b86d4b6318c47bf9b80fbd1ec08906a0 to your computer and use it in GitHub Desktop.
Deduplicate files with symbolic links
# Use https://github.com/sreedevk/deduplicator then use
# jq 'map(. + {key: (.hash + (.size | tostring))}) | group_by(.key) | map([.[] | .path[22:]])' dup.json
# to get the changed.json file.
# The script must be ran as admin.
$a = cat changed.json | ConvertFrom-Json
foreach ($duplicate_files in $a)
{
foreach ($file in ($duplicate_files | Select-Object -Skip 1)) {
Write-Host "Deleting", $file
Remove-Item $file
$relative_path = [IO.Path]::GetRelativePath([IO.Path]::GetDirectoryName($file), $duplicate_files[0])
Write-Host "Linking", $file, "to", $relative_path
cmd /c mklink $file $relative_path
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment