LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help with Bash shell scripting (http://www.linuxquestions.org/questions/linux-newbie-8/help-with-bash-shell-scripting-498205/)

HLM01 11-03-2006 05:41 AM

Help with Bash shell scripting
 
Hello,

Firstly, I'll admit right now that this is for an assignment and that according to the rules, members are not supposed to do my homework. However, I'm hoping that I can at least get some advice on what to do, some useful commands and what they do etc. I've seen so much information online, and just can't get my head around it at all.

The problem: How would I go about searching all directories for all files of a certain name, and then move them into a specific folder. The script should ignore the files already in that folder.

Now I know how to move files, how to search to some extent, loop and perform If statements. It's putting it all together that is a problem for me.

For example, I can use the command find / -name myfile to find the files, but then what?

Hope I can get some help.

acid_kewpie 11-03-2006 05:48 AM

well done for coming clean and obviously we're not going to give a full example, but i'd suggest you explore the -exec option of find.

HLM01 11-03-2006 06:06 AM

I've taken a look at that, and it seems I'm supposed to be able to execute a command (mv in this case) to whatever I'm searching for. Or maybe I'm wrong.

I tried guessing how to use it after looking at the man info, and obviously it didn't work. I'm using

[EDIT: New code after some searching. Still doesn't work.]

find / -name myfile -exec mv /mydir {} \;

Obivously this is not the right way, but am I headed in the right direction?

timmeke 11-03-2006 07:45 AM

Quote:

Now I know how to move files
Are you sure? Check the order of your "mv" parameters...

You may also want to restrict find to regular files (not dirs, symlinks and stuff). Checkout -type for that.

myint45 01-30-2008 07:45 PM

Quote:

Originally Posted by HLM01 (Post 2488596)
I've taken a look at that, and it seems I'm supposed to be able to execute a command (mv in this case) to whatever I'm searching for. Or maybe I'm wrong.

I tried guessing how to use it after looking at the man info, and obviously it didn't work. I'm using

[EDIT: New code after some searching. Still doesn't work.]

find / -name myfile -exec mv /mydir {} \;

Obivously this is not the right way, but am I headed in the right direction?


You are missing an argument on mv..where are you going to move it to?

gilead 01-30-2008 07:50 PM

This thread is over a year old - the poster has long passed (or failed) by now.

HLM01 01-31-2008 12:11 AM

Doesn't time fly, eh?

I passed my test. Somehow...

myint45 01-31-2008 05:23 PM

Quote:

Originally Posted by HLM01 (Post 3040655)
Doesn't time fly, eh?

I passed my test. Somehow...


Glad to hear it; working in the field yet?


All times are GMT -5. The time now is 12:59 PM.