In catalogs ~/temp/a/foo/and ~/temp/b/foo foo/I have several files with the names bar1, bar2, bar bar1, bar bar2, etc.
I am trying to write a Bash line that copies all of these files to a directory containing "foo" as the last part of the name, in the folder located above the corresponding "foo" folder.
While there are no spaces in the file names, this is not an easy task, but two commands do not work when working with the directory foo foo:
for dir in `find . -type d -name '*foo'` ; do cp $dir/* "$(echo $dir|sed 's_foo__g')" ; done
(The command cpdoes not see the last fooof "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/*"doesn't turn around.)
Attempts to replace $dir/*with "$(echo $dir/*)"even less successful.
Is there an easy way to expand $dir/*to cpunderstand?
uvett source
share