Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Move (cover) file into folder with the same name at a different location

unfortunately I have not found a solution for this yet. I would like to run through a folder (incl. subfolders) to find all files with "cover" or "Cover" in the name and then move those into a folder with the same name as its current parent folder, but that new folder is in a different location. So

1st location:

/mnt/folder1/
-- subfolder 1
---- file.mp3 
---- cover.jpg
-- subfolder 2
---- file2.mp3
---- cover1.jpg

2nd location:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/mnt/test/folder2
-- subfolder 1
---- otherfile.mp3 
---- **cover from subfolder 1 goes here**
-- subfolder 2
---- otherfile2.mp3
---- **cover from subfolder 1 goes here**

The cover files should go from the first location to the second location. I have found out how I can find all the files (find . -type f -name "*Cover*.*") but no idea how to move them, as I cannot understand, how I bring this command into the "for f in *cover*.*; do" format.

Thanks for some guidance!

>Solution :

With absolute paths:

src='/mnt/folder1/'
dst='/mnt/test/folder2'

(
    cd "$src" &&
    find -type f -name '*[Cc]over*' \
        -exec echo mv -iv -- {} "$dst"/{} \;
)

This will display the mv commands that would be run.

To actually move the files, remove echo.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading