Skip to main content
Name collisions
Source Link
Chris Davies
  • 128.4k
  • 16
  • 179
  • 324

It's a little strange having all the directory paths start with ... Personally I'd recommend you go up a level and copy/move/link the files into the nominated child directory.

However, this will allow for the .. and ensure you don't end up trying to copy files that have previously been copied

find ../ -mindepth 3 -type f -name '*.txt' -exec cp --target-directory . -- {} + 

You can drop in ln for cp if linking is sufficient instead of copying. Likewise mv if moving is the desired intent.

  Use cp -p if you want to try and keep permissions, timestamps, etc.

Note that if you have two or more files with the same name, all but the last copied will be overwritten. If you're using mv all but the last will be lost. If you're using ln only the first will be successfully linked.

It's a little strange having all the directory paths start with ... Personally I'd recommend you go up a level and copy/move/link the files into the nominated child directory.

However, this will allow for the .. and ensure you don't end up trying to copy files that have previously been copied

find ../ -mindepth 3 -type f -name '*.txt' -exec cp --target-directory . -- {} + 

You can drop in ln for cp if linking is sufficient instead of copying. Likewise mv if moving is the desired intent.

  Use cp -p if you want to try and keep permissions, timestamps, etc.

It's a little strange having all the directory paths start with ... Personally I'd recommend you go up a level and copy/move/link the files into the nominated child directory.

However, this will allow for the .. and ensure you don't end up trying to copy files that have previously been copied

find ../ -mindepth 3 -type f -name '*.txt' -exec cp --target-directory . -- {} + 

You can drop in ln for cp if linking is sufficient instead of copying. Likewise mv if moving is the desired intent. Use cp -p if you want to try and keep permissions, timestamps, etc.

Note that if you have two or more files with the same name, all but the last copied will be overwritten. If you're using mv all but the last will be lost. If you're using ln only the first will be successfully linked.

Source Link
Chris Davies
  • 128.4k
  • 16
  • 179
  • 324

It's a little strange having all the directory paths start with ... Personally I'd recommend you go up a level and copy/move/link the files into the nominated child directory.

However, this will allow for the .. and ensure you don't end up trying to copy files that have previously been copied

find ../ -mindepth 3 -type f -name '*.txt' -exec cp --target-directory . -- {} + 

You can drop in ln for cp if linking is sufficient instead of copying. Likewise mv if moving is the desired intent.

Use cp -p if you want to try and keep permissions, timestamps, etc.