LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 11-03-2006, 05:41 AM   #1
HLM01
LQ Newbie
 
Registered: Nov 2006
Posts: 3

Rep: Reputation: 0
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.
 
Old 11-03-2006, 05:48 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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.
 
Old 11-03-2006, 06:06 AM   #3
HLM01
LQ Newbie
 
Registered: Nov 2006
Posts: 3

Original Poster
Rep: Reputation: 0
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?

Last edited by HLM01; 11-03-2006 at 06:14 AM.
 
Old 11-03-2006, 07:45 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
 
Old 01-30-2008, 07:45 PM   #5
myint45
LQ Newbie
 
Registered: Aug 2006
Posts: 10

Rep: Reputation: 0
Quote:
Originally Posted by HLM01 View Post
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?
 
Old 01-30-2008, 07:50 PM   #6
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
This thread is over a year old - the poster has long passed (or failed) by now.
 
Old 01-31-2008, 12:11 AM   #7
HLM01
LQ Newbie
 
Registered: Nov 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Doesn't time fly, eh?

I passed my test. Somehow...
 
Old 01-31-2008, 05:23 PM   #8
myint45
LQ Newbie
 
Registered: Aug 2006
Posts: 10

Rep: Reputation: 0
Smile

Quote:
Originally Posted by HLM01 View Post
Doesn't time fly, eh?

I passed my test. Somehow...

Glad to hear it; working in the field yet?
 
  


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 shell scripting using if else nautz Linux - General 10 11-07-2006 10:47 AM
Bash shell scripting Sco Linux - Newbie 1 11-09-2004 12:58 PM
Help with I/O on bash shell scripting Dave6383 Programming 1 06-03-2004 06:24 PM
some bash shell scripting eltongeoff Linux - Newbie 2 10-22-2003 02:10 PM
BASH Shell scripting help ewarmour Linux - General 8 05-25-2002 08:10 AM


All times are GMT -5. The time now is 01:07 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration