3

I have a portable disk with contents like this:

/media/usb1/CBCradio3/1.wav
/media/usb1/CBCradio3/2.wav
/media/usb1/CBCradio3/3.wav
/media/usb1/CBCradio3/4.wav
/media/usb1/podcasts/1.wav
/media/usb1/podcasts/2.wav
/media/usb1/podcasts/3.wav

And a hard drive with contents like this:

/home/user/Music/CBCradio3/2.wav
/home/user/Music/CBCradio3/3.wav
/home/user/Music/radio12/1.wav
/home/user/Music/radio12/2.wav

I want to copy the data over, however, if a foldername inside /Music/ already exists, it should ignore it.

In other words, I don't want folders to end up with mixed data. If I use regular copy to copy over the drive, I end up with content like this:

/home/user/Music/CBCradio3/1.wav <--added to folder
/home/user/Music/CBCradio3/2.wav
/home/user/Music/CBCradio3/3.wav
/home/user/Music/CBCradio3/4.wav <--added to folder
/home/user/Music/podcasts/1.wav <--added whole folder
/home/user/Music/podcasts/2.wav <--added whole folder
/home/user/Music/podcasts/3.wav <--added whole folder
/home/user/Music/radio12/1.wav
/home/user/Music/radio12/2.wav

But I don't want it to merge content, if a folder exists, it should skip copying content. How can I achieve this?

  • I tried copying in mc and thunar but it merges folder contents.
  • The directories below .../usb1/ do not contain further sub-directories.
0

2 Answers 2

5

Going by your description, this is not a recursive problem: if foo exists both in the source and the destination, then foo will not be copied, end of story. Therefore a simple shell loop solves the problem.

source=/media/usb1
destination=/home/user/Music
test -d "$destination" || mkdir -- "$destination"
for x in "$source"/*; do
  if ! [ -e "$destination/$x" ]; then
    cp -Rdp "$x" "$destination/"
  fi
done

(But note that the requirement is problematic. For example, if a copy is interrupted, you'll end up with a partial directory in the destination and no way to resume, or even to know that there's something to resume.)

0
0

Sometimes it is not very convenient to use tools such as rsync or others, if you need to have a look first to select/deselect some of the files before copying them over (or not)

So you may want to use a text-console "graphical" tool that will show you both directories and allow you to compare their content, and will allow to "synchronize" them.

For exemple: https://en.wikipedia.org/wiki/Double_Commander

It has many capabilities, including the one you may want to try:

Directory compare: Directories (all or only selected) can be compared and synchronized both symmetrically (two-way) and asymmetrically (one-way). This feature shows differences between two locations by directory and subdirectory, and can make a fully automatic backup of files that have been added, changed or deleted.

A variant as a text-only (inside your terminal) interface would be the old but still being updated until this year : mc, aka https://en.wikipedia.org/wiki/Midnight_Commander. The https://en.wikipedia.org/wiki/Comparison_of_file_managers shows that it also can : synchronize directories, now. Highly recommended to give it a try, as the ability to move around with just keypresses makes it a breeze.

Of course those tools make interruption & restarting later on very easy, as the next comparison will be fresh.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.