A little bash script help...

Soldato
Joined
18 Oct 2002
Posts
7,139
Location
Ironing
I've never taken the time to learn bash properly, and so I need a little help doing a very simple job:

I'm in a directory, and I've got a bunch of sub-directories, and a file. I want to copy that file into each of the subdirectories, but only those that start with a digit [0-9]. Basically this:

Code:
foreach directory in directorylist {

if directory =~ /[0-9](.*)/ {
copy file.txt directory/
}

}

How would I do this in bash?
 
Code:
find /path/to/directory -regex ".*/[0-9]+.*" -type d -exec cp /path/to/file {} \;

A little crude and may need tweaking, but should work, looks in the parent directory for things beginning with a number (uses the whole path though I think) of type directory and for each one found copies the file into them :).
 
Back
Top Bottom