Linux - NewbieThis 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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I can't figure out the proper syntax for what I'm trying to do, or maybe a better way of doing it. I'll be using the find command several times but in slightly different ways, using using the same search criteria.
I want to save some search criteria as a variable (I think) and use the value in a find command, something like this:
Crit="-iname '*\.txt' -o -name '*\.log'"
-iname '*\.txt' -o -name '*\.log'
find /directory -type f \( $Crit \) -ls
or essentially echo'ing out that $Crit into the find command.
I've tried several different methods and I'm just not getting it right.
grail, thanks for the ideas and the code correction. I've not posted must here on this site even though I've been a member for years.
Concerning the find command, I always thought you should quote the patterns, but I tried it both ways and checked the man page. The find man page states that "Please note that you should quote patterns as a matter of course, otherwise the shell will expand any wildcard characters in them."
Now with that said, I did try without quotes, but had to escape out the wildcard symbols as well when NOT using the quotes. Otherwise find returned this message:
find: paths must precede expression: some_file_name.txt
This is what appeared to work fine at the command line, not using my little $Crit junk idea:
find . -type f -name \*\.txt
I purposely escaped out the period just to ensure I do find a file with a '.txt' extension and not something like '*btxt' or what not.
I've tried different variations but the previous solution with "set -f" appears to be best so far.
That last idea with the array is awesome. I'll tried that too. I too like "clean" even at the expense of more syntax. I think anyone coming in behind you to read the script will be able to understand the script easier if it's clean and even using some "older" ways of doing things. Everyone in an IT shop is normally at different skill levels.