linux - I want to copy different folders & a file in them (same for all folders) to another folder - unix -


say have multiple folders, many files in each, file i'm interested in "xyz.p" :

~/home/a/xyz.p

~/home/b/xyz.p

~/home/c/xyz.p

~/home/d/xyz.p

now want copy each of these folder 1 file "xyz.p" directory:

~/trial/a/xyz.p

~/trail/b/xyz.p

~/trail/c/xyz.p

~/trail/d/xyz.p

i not want copy other files folder a, b, c, d.

for i've tried using long shell scripts not working.

i found easiest way tackle problem write simple script.

#!/bin/bash  startdir="home" targetdir="test"  filename="xyz.p"  dir in 'a' 'b' 'c' 'd';   cp -rfv $startdir/$dir/$filename $targetdir/$dir/$filename done 

this script takes file startdir/subdir , puts in targetdir/subdir directory.

the sub-directories can put list in single quotes on line of command.

the -rfv means copy recursive(include subdirectories), forced, , verbose(tell doing).

the output script me

$./moveit.sh `home/a/xyz.p' -> `test/a/xyz.p' `home/b/xyz.p' -> `test/b/xyz.p' `home/c/xyz.p' -> `test/c/xyz.p' `home/d/xyz.p' -> `test/d/xyz.p' 

hope helpful.
please try little more research before asking though :)


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -