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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
08-10-2009, 10:24 AM
|
#1
|
Member
Registered: Jul 2009
Posts: 36
Rep:
|
Bash script with find command
Hello,
If I run a command like:
find /home/myname/testlog.*
I will end up with all files that starts with "testlog."
If I put this into a bash script I end up with all files that starts with "testlog.*" and that is not what I want.
How to sort this out? Any ideas?
Best regards
Johan
|
|
|
08-10-2009, 11:25 AM
|
#2
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep:
|
Quote:
Originally Posted by dexznrl
If I run a command like:
find /home/myname/testlog.*
I will end up with all files that starts with "testlog."
|
No, not completely correct. You will end up with all files in the working directory that starts with "testlog." plus all files and sub-directories below any sub-directory that has a name that starts with "testlog."
Quote:
Originally Posted by dexznrl
If I put this into a bash script I end up with all files that starts with "testlog.*" and that is not what I want.
|
If you only want files in the directory /home/myname/ with names that start with "testlog." do:
Code:
ls /home/myname/testlog.*
I you want all files with names that start with "testlog." in any sub-directory below /home/myname/ do:
Code:
find -type f -name "testlog.*"
|
|
|
08-10-2009, 11:34 AM
|
#3
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
Quote:
Originally Posted by Hko
I you want all files with names that start with "testlog." in any sub-directory below /home/myname/ do:
Code:
find -type f -name "testlog.*"
|
I think you probably mean:
Code:
find /home/myname -type f -name "testlog.*"
--- rod.
|
|
|
08-10-2009, 12:42 PM
|
#4
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep:
|
Quote:
Originally Posted by theNbomr
I think you probably mean:
Code:
find /home/myname -type f -name "testlog.*"
|
Yes, you're right about that.
My mistake.
|
|
|
08-10-2009, 12:43 PM
|
#5
|
Member
Registered: Jul 2009
Posts: 36
Original Poster
Rep:
|
Excellent help
Thank you everybody for all your help.
|
|
|
08-10-2009, 01:19 PM
|
#6
|
Senior Member
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
|
also if you only need the filename and not include the prefix directories, use
Code:
find /home/myname -type f -name "testlog.*" -printf '%f\n'
|
|
|
08-10-2009, 01:52 PM
|
#7
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
That -printf argument was one I never knew about. That's going to be one I use a lot. Thanks.
--- rod.
|
|
|
All times are GMT -5. The time now is 01:34 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|