Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Does anyone have any ideas, i mean codes on how to write a bash script for locate file.
e.g:
This utility shows you all files and directories that have a specific
substring in the name.
Press '?' for help, 'q' for quit or enter your search terms:
Kuala bin
I have searched for two terms for you,
Kuala, which has three hits:
/usr/share/zoneinfo/Asia/Kuala_Lumpur
/usr/share/zoneinfo/posix/Asia/Kuala_Lumpur
/usr/share/zoneinfo/right/Asia/Kuala_Lumpur
bin, which has 2312 hits. Are you sure you want to see all of those? [Y/n]
n
Press '?' for help, 'q' for quit or enter your search terms:
Sorry, you didn't enter any search term.
Press '?' for help, 'q' for quit or enter your search terms:
q
Thanks for being here, come again.
$
I want to know the codes for an output like above.
The question that was given by my teacher is to locate file(s) by by keyword.
Above is the example of the output.
I would appreciate it if you could help me.
Thanks in advance.
grail,
the main important thing is the shell script codes for locate file(s).
It doesn't necessarily have to be exactly as stated above.
Any creative ideas would be great.
Thanks in advance.
:-)
I want to know the codes for an output like above.
The question that was given by my teacher is to locate file(s) by by keyword.
Above is the example of the output.
I would appreciate it if you could help me.
Thanks in advance.
So your teacher gave you an assignment with suggested output...and you'd like us to write your script for you? Sorry, no. We will be glad to ASSIST you..post what you've written so far, what you've tried, and where you're stuck, and we'll help you out. Otherwise, there are THOUSANDS of bash scripting guides you can easily find with Google, like this one: http://tldp.org/LDP/abs/html/
Read the man pages on the find command, and look up the case statements in bash scripting.
So your teacher gave you an assignment with suggested output...and you'd like us to write your script for you? Sorry, no. We will be glad to ASSIST you..post what you've written so far, what you've tried, and where you're stuck, and we'll help you out. Otherwise, there are THOUSANDS of bash scripting guides you can easily find with Google, like this one: http://tldp.org/LDP/abs/html/
Read the man pages on the find command, and look up the case statements in bash scripting.
You're so provocative. I never ask you to practically DO my assignment. Any little tips would do. I already have the output. I just wanna brush it up a bit.
It was my lecturer himself who asked me to ask questions from this page.
Last edited by Tinkster; 08-05-2011 at 08:25 PM.
Reason: Language clean-up....
afiqrahim I'd like to ask you to not get personal. Other people
have the right to comment on your actions/questions, it's not your
right to get all the answers you desire, it's a privilege you're
granted to be asking questions. How people respond will not always
be what you expect or want to hear, just get over it.
TBOne, please try to be a bit kinder on people, specially new ones.
Yes, I've read ESR's "How to ask questions" and his idea of netiquette.
The problem is that we're not all the same, not all with the
same background, and obviously not all the same cultural backgrounds -
be that regarding the country/culture of origin, or even simple things
as age. I got my frustrations with nooblets over the years, all barging
in asking the same thing in the same demanding way; but let's face it -
neither of us is going to change this, and it will just make you bitter
and twisted, and give you ulcers in the end if you work yourself up over
these things.... so, for the sake of keeping LQ a friendly community,
and your personal well-being (as well as my time spent on moderation
rather than technical support), please tone it down.
Well ok, I'll give you a few suggestions. First of all, read the Advanced Bash-Scripting Guide or perhaps another Bash tutorial on the net, there are plenty of those, just do a search.
In order to solve your problem, familiarize yourself with variables and how to assign values to them, so you can understand statements like this:
Code:
MESSAGE="Press '?' for help, 'q' for quit or enter your search terms: "
echo -n $MESSAGE
Read about loops, how they work and how to use them. This is a simple example of a while loop:
Code:
while true; do
echo "it's true"
done
Have a look at the Bash manpage and read about the read command, you'll need that one to get user input in your script. Type "man bash" or "help read" for more information.
Study the Testing and Branching chapter and learn how to write a case statement. This will help you determine the value of a variable and perform actions based on that value. For instance:
Code:
case "$i" in
q|Q) echo "Thanks for being here, come again."
exit;;
esac
Finally, read the manpage for the find command: man find. This command will search for files based on the parameters you specify on the command line.
When you know and combine all these concepts, you'll be able to write your script. That should get you started. But next time, try to do a little research on your own, ask your instructor or search the web. And if you're really stuck, post again, ask smart questions, and people will help you.
You're so provocative. I never ask you to practically DO my assignment. Any little tips would do. I already have the output. I just wanna brush it up a bit.
I did give you little tips. Told you to read up on the find command, gave you a link to a scripting tutorial site, and even told you what to look up ON that tutorial to do what you wanted.
You have OUTPUT of the script, and specifically asked if someone had "codes" on how to write a bash script to locate a files. You didn't post any of your work, and based on your question, it sure seemed like you were asking us to write it for you.
Quote:
It was my lecturer himself who asked me to ask questions from this page.
Really? Your teacher told you to come here and ask for a bash script?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.