bash script that printout the full paths of all the files under the directory
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
bash script that printout the full paths of all the files under the directory
Write a bash script that printout the full paths of all the files under the directory of interest and its sub-directories that match certain pattern
- Take two inputs from the user: one is the full path to the directory and the other is the pattern of interest
For example,
>> myscript.sh /home/student/master_project/test_directory comp
Your program "myscript.sh" will need to look into "/home/student/master_project/test_directory" and print out all the files that has "comp" in it.
The challenge is you do not know how many levels of subdirectories are there, so you need to use suitable loop control to cover all sub-directories.
what have you tried so far and where are you stuck.
did your attempt print out an error message. please provide your source code so someone would be able to help correct your mistake.
what have you tried so far and where are you stuck.
did your attempt print out an error message. please provide your source code so someone would be able to help correct your mistake.
Its for my sister. She is not well. She wants to submit it as an assignment. I dont know Linux. So i thought someone may help me here.
Please take a moment to read through the LQ rules:
Quote:
Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an LQ member.
If your sister is so unwell that she cannot use a computer on her own, I fail to see how she could possibly manage a class in GNU/Linux.
My condolences. I really hope she feels better soon. When she does, she is more than welcome to post her efforts here so that I and others will be able to help her out if needed.
Its for my sister. She is not well. She wants to submit it as an assignment. I dont know Linux. So i thought someone may help me here.
Sorry, but this makes very little sense.
If your sister is so very ill that she cannot even type, why is she in school and/or expected to turn in assignments? If she just has a minor illness, then she is PERFECTLY able to post a question herself, or at the very least, give you what she has done so far, towards 'her' assignment. It seems much more likely that this is YOUR homework, and you're playing a sympathy card, trying to get someone to hand you a script.
Good. The script found all the files containing the keyword "comp" in tmpdir and its sub-directories. For this, I used not a single loop, and the script itself is three (3) lines. If you skip the
Code:
exit 0
It can be two (2) lines. But I recommend that you (oh, sorry, your sister) makes it mandatory to always include a proper exit status in her scripts. It is bad practice not to.
So, on second thought, when your sister gets better, tell her to go find a PROPER course in GNU/Linux, because this one seems pretty awful.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.