You are not logged in.
Hi!
I'm trying to...
cp $(find | grep odt) ../all
(get all odt's from subfolders and copy to ../all)
But obviously that one only copies the odt that don't have spaces in their path.
1) How do I do that one the right way? (Can't somehow just escape \" \" around the find-stuff, so I guess I gotta find the right thing . Also I need some "putting-stuff-together-thing".+."to get the \" to the expression thing without it getting into the \\command executed\\ dammit. Sometimes I think, maybe this bash-thing isn't meant to be used/learned solely by trial & error )?
2) Does someone know a good "general bash syntax" chart with condensed information? Something very compact without "useless words" in between ?
thx!
Last edited by whoops (2009-05-07 10:44:40)
Offline
cp "$(find | grep)" ... would take care of the spaces, but a better way would be this:
find ./ -name '*odt*' | while read file; do
cp "$file" ../all
done
adjust the -name 'whatever' as needed
there are probably other ways.
Last edited by brisbin33 (2009-05-06 18:47:45)
//github/
Offline
cp "$(find | grep)"
[i]I tried that one - the whole find-output is inside the quotes which results in a three site "filename" that doesn't exist. So if I want to try the wrong way... maybe I can find a way to replace all \n by "".
$(find | grep odt | [regexp program I don't know the name of] ("\n", "\"\""))
(edit:
The other one seems to do the same, although I first thought it worked as it was doing something with the hd a whole lot longer than the first one.)
edit2:
Oh, it does work, just something strange after that, I will see...
Last edited by whoops (2009-05-06 19:00:55)
Offline
the good old "find and xargs combo":
find . -iname *\.odt -type f -print0 | xargs -0 -I cp {} ../all
i think this should work.
Offline
cp "$(find | grep)" ... would take care of the spaces, but a better way would be this:
find ./ -name '*odt*' | while read file; do cp "$file" ../all done
adjust the -name 'whatever' as needed
there are probably other ways.
for this you'll need smth like
while read file; do
cp "$file" ../all
done < <(find ./ -name '*odt*')
Offline
"xargs -I" will still do 1 file at a time so the command is run a lot of times
You can use -printf to surround the files in single quotes and interpret it with eval.
eval cp $(find -maxdepth 1 -type f -printf "'%f' ") backup/
Offline
brisbin33 wrote:cp "$(find | grep)" ... would take care of the spaces, but a better way would be this:
find ./ -name '*odt*' | while read file; do cp "$file" ../all done
adjust the -name 'whatever' as needed
there are probably other ways.
for this you'll need smth like
while read file; do cp "$file" ../all done < <(find ./ -name '*odt*')
lolwut?
$ mkdir all
$ mkdir test
$ touch test/something{1,2,3,4}.odt
$ cd test/
$ touch something\ else{1,2,3}.odt
$ ls
something1.odt something3.odt something else1.odt something else3.odt
something2.odt something4.odt something else2.odt
$ find ./ -name '*.odt' | while read file; do cp "$file" ../all/; done
$ ls ../all/
something1.odt something3.odt something else1.odt something else3.odt
something2.odt something4.odt something else2.odt
edit: made the example better.
Last edited by brisbin33 (2009-05-06 19:48:25)
//github/
Offline
Really sorry guys, but please read man pages.
$ find test/ -iname \*.odt -exec cp {} all/ \;
HTH
heyoooh, i always forget about that one.
/me goes to replace many a while loops...
//github/
Offline
Thanks, got it, me learned something !
find test/ -iname \*.odt -exec cp {} all/ \;
Yes, I was familiar with that one, but didn't want to be limited to find (more stuff like that to do later).
while read file; do
cp "$file" ../all
done < <(find ./ -name '*odt*')
I think I like that syntax most - for me it's easiest to remember / understand / alter.
xargs looks very useful - gotta take a closer look at that later.
Offline
best bash FAQ around:
http://wooledge.org:8000/BashFAQ
should answer most of your questions.
Offline