So here's my situation. I have a lot of files on my local in 3 directories. I have a subset of those files + ~30 on a server in a more organized 10 directories. I'd like to move the files on the local machine to match their directory on the server (ideally I'd copy the ~30 additional at the same time but if not I can do that manually). Does anyone have any suggestions on how to achieve this?

Okay let me illustrate. My local has files broken down like this in 3 directories: [ A B .... F ] [ G H ... P ] [ Q R .... W ]

My server has [ A B C ] [ D E F ] [ G H I J K ] [ L M N O P ] [ Q R ] [ S T U ] [ V W X Y Z]

I'd like to move the files I have locally into their corresponding local directory based on what directory they are in on the server (without transferring any files) [] is a directory, letter is a file.

closed as unclear what you're asking by Rui F Ribeiro, roaima, G-Man, Stephen Rauch, Romeo Ninov Dec 13 '17 at 8:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Your question is not entirely clear to me; rsync could come in handy. – simlev Dec 12 '17 at 16:46
  • @simlev I wrote an example to demonstrate the structure. I'm checking out rsync now. – Nate Dec 12 '17 at 16:51
  • 1
    Uhm..you could just mirror the server directory and files to the local filesystem, then search and delete any duplicate files in the local filesystem. If you don't want to transfer, you could save a list of files on the server, then programmatically check if a file is in the list and in a particular directory, then move it to that directory on the local filesystem. Is there any criteria for storing a file to a certain directory, other than it being on that directory on the server? – simlev Dec 12 '17 at 16:55
  • So is the first directory actually called A B .... F, or is this intended to show that some unnamed directory contains files whose names only begin with the letters A, B, C, D, E, F, or does it signify something else? Similarly, what does the server directory name A B C actually denote? – roaima Dec 12 '17 at 21:21

If there are no duplicate names among the files

  1. obtain a list of files from the server (typically the output of find, relative to their common directory), and transfer it on the local
  2. on the local, move all the files to the same directory (using find [...] -exec mv -t some/staging/directory {} \;
  3. on the local, with the CWD as the common directory execute something like:

    while read f; 
       mkdir -p $(dirname "$f")
       mv -v "some/staging/directory/$(basename $f)" "$f"
    done < files_on_server.lst

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