I am making a file sync program. In order to increase the efficiency of the syncs, I have it sync/copy over only the new files/folders from the source. Anyway, when I copy directories into the sync I use ‘cp pR itemName, because it preserves the attributes of the directory and the icon (if it is present). But, unfortunately it also copies all of the contained files in that directory… I do not want the children copied (excepting some invisible files), I want to copy one item at a time. Is there a way that I can programatically copy a directory, by itself (without including it’s child files) but still retaining it’s attributes (like Date Created and icon)?
Share
You want to use rsync.
Rsync creates a list of all the files and copies only the ones that have been modified. This is really fast.
i do
but, to answer your question, you can list the fils and exclude one you dont want with grep and using xargs, run your action.
lets say you ran ls and this is what you got
and lets say that you wanted everything, just not anything in the music folder or the movies folder
you can do:
notice movies and Music were not listed. Well now you can run xargs and do the action. Since i dont want to delete anything, im not gonna do it, but this is what it would look like
the -I command for xargs takes the input from the last command, and gives it a nickname, in my case “xx” so that you can call commands on xx knowing that they are each an element of the last command. Hope that helped.