command to identify similar filenames [SOLVED]

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
52ROSt
Level 5
Level 5
Posts: 737
Joined: Mon Apr 14, 2014 10:01 am

command to identify similar filenames [SOLVED]

Post by 52ROSt »

LM 17.3 KDE 64

I have between 1000 - 2000 jpg-files in 2 folders. I can have files with the same name but a different files size and I want to keep both or keep the larger file.

Ist there a terminal command which either
keeps both files with and additional number at the end of the filename
or
keeps the larger files?

Thanks for your help!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29612
Joined: Wed Jul 06, 2011 3:58 am

Re: command to identify similar filenames

Post by xenopeek »

Moved this to the scripting forum as I think the requirement to among files with the same name keep the biggest one might need some scripting. There's a thread here with ideas about how to find duplicates based only on filename, as a start for such a script: https://stackoverflow.com/questions/162 ... ctory-bash

The duplicate searching tools I know are fslint and fdupes (both in the repository) and both have a command line interface (fslint also has a GUI), see information here https://www.pixelbeat.org/fslint/ and here https://github.com/adrianlopezroche/fdupes. I don't know these will do what you want.

I'd suggest to give fdupes a try first and just let it find duplicates in both directories and see if that list what you'd expect (use fdupes -S -r dir1 dir2 to recurse and show filesizes). If the list is short enough just delete by hand perhaps. See its manpage for more options.
Image
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: command to identify similar filenames

Post by rene »

Déjà Vu: viewtopic.php?f=18&t=266622&hilit=stat#p1456053

That script synchronizes two directories, keeping only the bigger one of same-named files.
User avatar
52ROSt
Level 5
Level 5
Posts: 737
Joined: Mon Apr 14, 2014 10:01 am

Re: command to identify similar filenames

Post by 52ROSt »

viewtopic.php?f=18&t=266622&hilit=stat# ... 3@xenopeek
Moving it to the Scripting Forum is no issue at all. Next time I will go with similar questions to the Scripting Forum.

Thanks for the very usefull fdupes command. I could use it to find out the I only had files with the same name and same size. Lucky me!


@rene
Thanks for the hint with the very interesting bash script. I saved the link for the future
Locked

Return to “Scripts & Bash”