Search code examples
linuxfilefindcopyingcp

Linux copying selected files from directories and naming them after the directory name


lets say I have (linux/unix)

/directory/1/file.wmv
/directory/2/file.wmv
/directory/3/file.wmv

I want to copy these .wmv files into a single directory /example/ with files named after directory names they were in like so 1.wmv, 2.wmv, 3.wmv,


Solution

  • for i in {1..10}
    do
        cp /directory/$i/file.wmv /example/$i.wmv
    done