command line - How to copy set of files and folder structure with identical names but different file extensions - Ask Ubuntu


let me preface saying linux novice sure. looking way copy files of same name different file extension.

some background:

i have large collection of music. vast majority in .flac format. in order play collection in car transcoded of different file formats. have library of source .flac files , identical matching .mp3 , .m4a (aac) transcoded libraries, due various file formats supported cars own. have flash drive in car supports aac , mp3 playback, not flac. on flash drive music have selected larger library on computer. have no want lots of complete albums , have files on flashdrive hand picked larger library.

now, sold our old car , bought new one, , 1 supports flac playback. rather manually matching flac tracks on new flash drive mp3 tracks on old one, wondering if possible via terminal match contents flashdrive1 computer1 master library, , copy corresponding matched filenames desired filetype , appropriate folder structure flashdrive2

tl:dr

take contents from:

flashdrive1     \artist         \album             \01 tracktitle.mp3              02 tracktitle.mp3 

find corresponding .flac version identical file structure , naming scheme, different file format within:

computer1     \artist         \album             \01 tracktitle.flac              | 02 tracktitle.flac              | 03 tracktitle.flac 

copy to:

flashdrive2     \artist         \album             \01 tracktitle.flac               | 02 tracktitle.flac 

*in hypothetical, track 03 being omitted because not exist on flashdrive1 , therefore not want on flashdrive2

i know have invoke find , set filetype , grep involved, having trouble coming proper syntax. have googled similar questions haven't been able find achieve looking do. if haven't looked hard enough, feel free flame me. appreciated.

instead of grep, might use sed:

find /path/to/flashdrive -iname '*.mp3' -printf '%p\0' |  sed -z 's/\.mp3$/.flac/' |   rsync -ap --files-from=- -0 /path/to/computer1 /path/to/flashdrive  --dry-run 

in order:

  • find find mp3 files , print relative paths, separated ascii nul character (\0)
  • sed replace .mp3 , end .flac, using -z process nul-delimited limes.
  • rsync copy files while retaining directory structure , permissions (-a), reading in file paths copy stdin (--files-from=-), using nul-delimited lines (-0).

the --dry-run used simulate copying, observe output , run again without option if looks ok.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User