Search code examples
basharchive

Making archive from files with same names in different directories


I have some files with same names but under different directories. For example, path1/filea, path1/fileb, path2/filea, path2/fileb,....

What is the best way to make the files into an archive? Under these directories, there are many other files under these directories that I don't want to make into the archive. Off the top of my head, I think of using Bash, probably ar, tar and other commands, but am not sure how exactly to do it.

Renaming the files seems to make the file names a little complicated. I tend to keep the directory structure inside the archive. Or I might be wrong. Other ideas are welcome!

Thanks and regards!


EDIT:

Examples would be really nice!


Solution

  • What I have used to make a tar ball for the files with same name in different directories is

    $find <path> -name <filename> -exec tar -rvf data.tar '{}' \;
    
    i.e. tar [-]r --append
    

    Hope this helps.