LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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-24-2011, 05:25 AM   #31
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297

Hi,

If you don't know up front where the files are then you need to include the search for them in your script, for example with find. You could ask (echo) in your script to provide full path and file when executing, or ask for just a file name and run find from within your script. The first thing you'll need to check in order to avoid loosing time is if the file exists (with or without the mentioning of a path). If it doesn't, give an output to the user that the file doesn't exist. Find in its simplest form is used like this:
Code:
find / <filename>
(you can substitute / for any search path if you want to limit your search to a certain directory but since you mentioned the whole disk I left it as such)
Of course you'd also need to make sure that you're getting the correct file if duplicates are found.

Kind regards,

Eric

Last edited by EricTRA; 09-24-2011 at 05:29 AM.
 
Old 09-24-2011, 05:51 AM   #32
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
What's wrong with giving the full paths?
 
Old 09-24-2011, 05:54 AM   #33
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi Nylex,

In case your question is addressed to me, I'm providing a two way solution. If the 'enduser' knows the full path to both files then it would work without a search and for sure it would significantly reduce execution time. If the enduser doesn't know then a find can search the entire harddisk.

Kind regards,

Eric
 
Old 09-24-2011, 05:55 AM   #34
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Sorry Eric, that was to the OP; I hadn't seen your post. Oops!
 
Old 09-24-2011, 07:02 AM   #35
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
I still don't like the idea of the script finding the files. I would even consider it a bad practice (maybe except fore some special cases where it may be useful). I, personally, would be afraid to use a script that would search files anywhere else than in the path I specify. I would think that it is up to the enduser to find the files to compare. As this is your homework, your teacher will certainly use valid paths/filenames with your script (except to test error handling), so you are not required to make your script search for them unless the assignment explicitly states otherwise.
 
Old 09-24-2011, 07:47 AM   #36
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi millgates,

In post #30 the OP stated that he needs the script to search on the whole disk. Why would it be bad practice in a classroom environment to use a script to do that? Provided the permissions are set up correctly there is little harm that can be done, assuming the script will not run as root. As you stated yourself, it's homework so everything should be explore-able at any level in order to learn / teach something. After all it's not a production environment and up to the teacher to show the students the possible dangers. Where it to be used in a production environment, you'd be very right.

Kind regards,

Eric
 
Old 09-24-2011, 07:58 AM   #37
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by EricTRA View Post
Hi millgates,

In post #30 the OP stated that he needs the script to search on the whole disk. Why would it be bad practice in a classroom environment to use a script to do that? Provided the permissions are set up correctly there is little harm that can be done, assuming the script will not run as root. As you stated yourself, it's homework so everything should be explore-able at any level in order to learn / teach something. After all it's not a production environment and up to the teacher to show the students the possible dangers. Where it to be used in a production environment, you'd be very right.

Kind regards,

Eric
Well in a classroom environment it does not hurt. The OP said he needs to search the whole hdd "because I have to show this script not on my computer", not "because the teacher said so". It made an impression to me that the OP is worried about the files being in different place on the teacher's computer and teacher not knowing how to use the script properly or not supplying valid paths to the files. So I only wanted to say that he doesn't have to worry about that and make the script search the hdd just in case the teacher does not know where the files are, unless the searching part is the point of the homework and specified in the assignment
 
  


Reply



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
script to compare users in files s_linux Programming 7 04-05-2011 10:34 AM
Please help on making a compare script Magil Programming 7 12-14-2009 05:13 AM
Script to compare file size nazs Programming 6 05-24-2006 10:10 AM
I'm looking for a perlscript to compare size of 2 files cccc Programming 5 02-28-2004 04:45 PM
Help with a Directory Compare Script bullfrog Linux - General 1 02-04-2003 08:05 AM

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

All times are GMT -5. The time now is 07:25 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
Open Source Consulting | Domain Registration