I'm just getting to grips with the Linux Terminal but I still make mistakes:

I recently erroneously managed to copy all of the files contained within a directory (including all sub-directories) into another directory.

Is there any easy way to identify all of the files contained within the original folder (including sub-directories) and delete each file from another directory? eg: Folder /source contains files file1 and file2 and a sub directory /source/sub contains files file3 and file4.

Folder /destination contains files file1, file2, file3, file4, file5 and file6.

How can I parse /source and its subdirectories for files and delete only these files from /destination so that /destination is left containing only file5 and file6?

Very many thanks.

1 Answer 1


You could go through each file manually, reading from a list (maybe output from ls -lR source or find source -type f) and deleting the duplicate from the destination folder...

Or use find and md5sum to check for really identical files (not just similar-named files), comparing a sorted md5sum output for each folder, finding duplicate lines, and deleting the offending duplicate files from one folder.

Or (probably best) you could use a duplicate file finding program, like fdupes or fslint, they can both find duplicate files, one even has a nice GUI. Just make sure to point them only at your desired "source" and "destination" folders.

See this other questions for some options (changing the "move to somewhere else" into "delete"):

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .