Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting all files from various folders and copying them with unique names

Tags:

linux

bash

Currently using this command to get all my "fanart" from my TV folder, and dump it into a single folder.

find /volume1/tv/ -type f \( -name '*fanart.jpg'* -o -path '*/fanart/*.jpg' -o -path '*/extrafanart/*.jpg' \) -exec cp {} /volume1/tv/_FANART \;

Here's the issue: a lot of these files have the same name, and can't be dumped into the same folder. Example:

  • Folder A
    • fanart.jpg
  • Folder B
    • fanart.jpg

Is there a way to copy these files from their respective folders and give them a unique name in the destination folder? Name needn't be anything descriptive, random is just fine.

Thanks!

like image 210
Big Millz Avatar asked Sep 28 '22 18:09

Big Millz


People also ask

Is there a way to copy all folder names?

1] Using Windows Explorer Go to the folder in which you want to copy the names using Explorer. If you want a complete list, use Ctrl + A to select all or select required folders. Click on the Home tab on the top menu, and then click on Copy Path. Finally, open Notepad or Excel or any text and paste.

How do I copy only the names of files?

USING CTRL+C AND CTRL+V TO COPY FILE NAMES IN EXCEL If you want to copy the name of a file in Excel, use CTRL+C and CTRL+V. The keyboard shortcut is Ctrl+c, followed by Ctrl+v on your PC or Command+c followed by Command+v on Mac.


1 Answers

find /volume1/tv/ -type f \( -name '*fanart.jpg'* -o -path '*/fanart/*.jpg' -o -path '*/extrafanart/*.jpg' \) -exec cp --backup=numbered  {} /volume1/tv/_FANART \;

..

cp --backup=numbered  {}

If the file exists, this will not overwrite but make a backup with a number assigned.

The files will be hidden. Ctrl+H to view hidden files

like image 104
repzero Avatar answered Oct 01 '22 08:10

repzero