Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are two folders named Folder1 and Folder2. Folder1 has files with name:For example S-080001-0-0.xml with its corresponding same files in Folder2 named S-080001-0-0.xml

The change in Folder2 is that,for same file in Folder1 which is S-080001-0-0.xml,Folder 2 contains multiple files with different value after hyphen,like -080001-0-0.xml,-080001-0-1.xml,-080001-0-2.xml,-080001-0-3.xml. My challenge is to move all the files of same name from these two folders.

share|improve this question
Please explain. Do you want to add Folder1/S-080001-0-0.xml after, e.g., Folder2/S-080001-0-5.xml as Folder2/S-080001-0-6-xml? Combine them somehow? – vonbrand Feb 26 '13 at 10:19

If you want to compare based on filename then you can use below :

find folder1/ folder2/ -type f -printf %f"\n" | sort |  uniq -c | \
awk '( $1 >= 2 ) {print "mv -vf folder1/"$2,"other_dir/","&&","mv -vf folder2/"$2,"other_dir/"}'

it will just print command on terminal , it will not execute that , if you see output is proper then just append | sh at the last then it will execute that command

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.