LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-26-2004, 07:35 PM   #1
Gunslinger_ROL
Member
 
Registered: Jun 2004
Posts: 43

Rep: Reputation: 15
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
 
Old 09-26-2004, 08:26 PM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Code:
find ~ -name 'iads' -exec mv \{\} location \;
Note the space between 'location' and the escaped semicolon!
 
Old 09-26-2004, 08:28 PM   #3
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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.
 
Old 09-28-2004, 02:34 AM   #4
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
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
 
Old 09-28-2004, 03:45 AM   #5
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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 ";".
 
Old 09-28-2004, 12:37 PM   #6
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
Ahh, thank you very much for clearing that up!

-twantrd
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting help (su ...) shwong Linux - General 1 11-02-2005 01:26 PM
Bash scripting pete1234 Programming 1 09-27-2005 02:48 AM
bash scripting vadon Linux - Newbie 6 05-10-2005 05:07 AM
need help with bash scripting rich2oo1 Programming 2 12-17-2003 01:50 PM
HELP with BASH scripting atwah Linux - Newbie 6 09-09-2003 02:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration