In the directories ~/temp/a/foo/
and ~/temp/b/foo foo/
I have some files named bar1
, bar2
, bar bar1
, bar bar2
, etc.
I am trying to write a line of Bash that copies all these files in a directory containing "foo" as last part of the name to the folder above the respective "foo" folder.
As long as there are no spaces in the file names, this is an easy task, but the two following commands fail when dealing with the foo foo
directory:
for dir in `find . -type d -name '*foo'` ; do cp $dir/* "$(echo $dir|sed 's_foo__g')" ; done
(The cp
command fails to see the last foo
of "foo foo"
as part of the same directory name.)
for dir in `find . -type d -name '*foo'` ; do cp "$dir/*" "$(echo $dir|sed 's_foo__g')" ; done
("$dir/*"
is not expanded.)
Attempts like replacing $dir/*
with "$(echo $dir/*)"
have been even less successful.
Is there an easy way to expand $dir/*
so that cp
understands?