Usando find
e gawk
-
Instale
gawk
sudo apt-get install gawk
-
Entre na sua pasta ou substitua o
.
após o comandofind
pelo seu nome de pasta, por exemplo:find ~/my_video_duplicates f -iname …
-
Teste o comando
O comando abaixo mostra apenas os candidatos remover
find . -type f -iname "*_8000.mp4" -print0 | \ while read -d $'
' file; do \ gawk -F_ '{ \ a=gensub(/\_8000\./, "_3800.", "g" , $0); \ system("if [ -f \""a"\" ]; then echo \""a"\" will be deleted; fi")}' <<< "$file";\ donefind . -type f -iname "*_8000.mp4" -print0 | \ while read -d $'
' file; do \ gawk -F_ '{ \ a=gensub(/\_8000\./, "_3800.", "g" , $0); \ system("if [ -f \""a"\" ]; then rm \""a"\"; fi")}' <<< "$file";\ done% ls -og total 3 -rw-rw-r-- 1 0 Jul 14 19:37 xxxx_yyy_720_3800.mp4 -rw-rw-r-- 1 0 Jul 14 19:20 xxxx_yyy_720_8000.mp4 -rw-rw-r-- 1 0 Jul 14 19:21 aaaa_yyy_720_8000.mp4
-
Verifique novamente se você está na pasta correta ou substitua o
.
após o comandofind
pelo seu nome de pasta, por exemplo:find ~/my_video_duplicates f -iname …
-
Se tiver certeza, execute o comando abaixo
% find . -type f -iname "*_8000.mp4" -print0 | \ while read -d $'
' file; do \ gawk -F_ '{ \ a=gensub(/\_8000\./, "_3800.", "g" , $0); \ system("if [ -f \""a"\" ]; then echo \""a"\" will be deleted; fi")}' <<< "$file";\ done ./xxxx_yyy_720_3800.mp4 will be deleted% find . -type f -iname "*_8000.mp4" -print0 | \ while read -d $'
' file; do \ gawk -F_ '{ \ a=gensub(/\_8000\./, "_3800.", "g" , $0); \ system("if [ -f \""a"\" ]; then rm \""a"\"; fi")}' <<< "$file";\ done% ls -og total 2 -rw-rw-r-- 1 0 Jul 14 19:20 xxxx_yyy_720_8000.mp4 -rw-rw-r-- 1 0 Jul 14 19:21 aaaa_yyy_720_8000.mp4
Exemplo
-
A situação inicial
sudo apt-get install gawk
-
A corrida a seco
find . -type f -iname "*_8000.mp4" -print0 | \ while read -d $'
' file; do \ gawk -F_ '{ \ a=gensub(/\_8000\./, "_3800.", "g" , $0); \ system("if [ -f \""a"\" ]; then echo \""a"\" will be deleted; fi")}' <<< "$file";\ donefind . -type f -iname "*_8000.mp4" -print0 | \ while read -d $'
' file; do \ gawk -F_ '{ \ a=gensub(/\_8000\./, "_3800.", "g" , $0); \ system("if [ -f \""a"\" ]; then rm \""a"\"; fi")}' <<< "$file";\ done% ls -og total 3 -rw-rw-r-- 1 0 Jul 14 19:37 xxxx_yyy_720_3800.mp4 -rw-rw-r-- 1 0 Jul 14 19:20 xxxx_yyy_720_8000.mp4 -rw-rw-r-- 1 0 Jul 14 19:21 aaaa_yyy_720_8000.mp4
-
A remoção
% find . -type f -iname "*_8000.mp4" -print0 | \ while read -d $'
' file; do \ gawk -F_ '{ \ a=gensub(/\_8000\./, "_3800.", "g" , $0); \ system("if [ -f \""a"\" ]; then echo \""a"\" will be deleted; fi")}' <<< "$file";\ done ./xxxx_yyy_720_3800.mp4 will be deleted% find . -type f -iname "*_8000.mp4" -print0 | \ while read -d $'
' file; do \ gawk -F_ '{ \ a=gensub(/\_8000\./, "_3800.", "g" , $0); \ system("if [ -f \""a"\" ]; then rm \""a"\"; fi")}' <<< "$file";\ done% ls -og total 2 -rw-rw-r-- 1 0 Jul 14 19:20 xxxx_yyy_720_8000.mp4 -rw-rw-r-- 1 0 Jul 14 19:21 aaaa_yyy_720_8000.mp4
-
A situação final
%pre%