I am trying to compile CyanogenMod and in the vendor files I have to manually find same files and then copy them. In a folder, there are 400+ files and it is very hard to copy them one-by-one.
I was thinking if there is a way to select the common files in both folders? It'll make my life a lot easier.
What you're probably looking for is:
Here, the
--existing
option ensures that only files already present in thedestination
directory are copied from thesource
directory-a
makes the copying recursive and preserves symbolic links, special & device files, modification times, group, owner, and permissionsIf you want to perform a dry-run to see what will be copied, use:
In either case, notice there is no slash after specifying the destination directory.
On the command line you can use the MV command and some wildcards.
Move all the files in dirs subdirs to here
Same but just files starting with prefix
If you have to find the same files, you could also look at
fdupes
, and parse its output. It checks if two (or more) files are really, really the same, even if they do not have the same file name.You can combine it with something that compares the filenames.
(Side note: Using
fdupes
to delete redundant files can be dangerous - e.g. with ripped DVDs. Each DVD track has a subtitle file and it's backup, which are identical but have a different filename suffix. VLC player won't play the DVDs if one of the files is missing. So I have to rebuild these files...)solution:
explanation:
diff
can output differences by file names. Exampleto get only the identical files use grep:
now to only get the filename use
awk
to get the 2nd column: