Bash scripting
anyone know how I could do a find command like
find ~ -name 'iads' -print and -exec a mv command like i want to find every occurances of iads and move the files to another locations////sending standard errors to the trash ?? thanks |
Code:
find ~ -name 'iads' -exec mv \{\} location \; |
Oops, forgot to add "2>/dev/null" on the end to redirect stderr. Also, you can still use -print if you want to see the list of files as they're moved.
|
find ~ -name 'iads' -exec mv \{\} location \;
CroMagnon, 1. If you run this on the command prompt you don't need to escape {} right? You need to escape {} ONLY if you run this as a script yes? 2. Also, what would happen if you don't escape \? Why is it that you need \; for an -exec to work? Thanks! -twantrd |
Actually, I escaped {} out of habit. If it works on the command line, it will very likely work in a script. Perhaps it works because the {} is empty (if you don't know what { and } do in the shell, try this: echo {f,c,r}at ). In fact, that must be it, because I've used it unescaped with xargs. Thanks, you've taught me something ;)
The important part is escaping the semicolon, because ; on it's own indicates to the shell that a command line is complete, and it is not passed to find. find requires a literal ; to tell it where the end of parameters for -exec are. It would also work if you put the semicolon in quotes, like ";". |
Ahh, thank you very much for clearing that up!
-twantrd |
All times are GMT -5. The time now is 03:45 AM. |