Linux - Newbie This 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! |
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.
|
|
09-18-2017, 01:27 PM
|
#1
|
LQ Newbie
Registered: Sep 2017
Distribution: Mint, Kali
Posts: 1
Rep:
|
Pathname Expansion with the File program?
Hi, I'm currently reading The Linux Command Line and came across this:
find ~ -type f -name "*.JPG" -size +1M | wc -l
The author noted that he put the quotations around *.JPG to suppress pathname expansion, but why? I thought using the double quotes would eliminate the special meaning of the asterisk. Since the first part of the above line is looking for regular files in the home directory that end with .JPG, I thought we would want to retain the expansion.
|
|
|
09-18-2017, 02:02 PM
|
#2
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,644
|
If you leave off the quotes, then the asterisk will get processed by the shell and the results passed to find. See "man 7 glob" about that.
If you use single or double quotes, then the asterisk will get processed by find as a parameter. That's what you want.
|
|
1 members found this post helpful.
|
09-18-2017, 02:07 PM
|
#3
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
If you did *.JPG it would look for any of your current file names and try to append .JPG to them wether they had that or not. The "*.JPG" is telling find to look for any file ending in .JPG so is making it more clear to find itself.
So say you had a directory with files:
ralph
billybob
suellen.JPG
david
missysue.JPG
Standard expansion of *.JPG would look for ralph.JPG, billybob.JPG, suellen.JPG.JPG, david.JPG and missysue.JPG.JPG and find none of those because they don't exist. On the other hand, by telling find to use "*.JPG" it is saying only find those files that have .JPG at end of name so will only show you suellen.JPG & missysue.JPG.
It often occurs with scripting that expansion is happening at odd locations and you have to do special quoting and/or escaping to make sure it only occurs where you meant it to do so.
|
|
1 members found this post helpful.
|
09-18-2017, 02:08 PM
|
#4
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,644
|
Here's something to compare the difference:
Code:
cd ~/Pictures/
for i in "*.JPG"; do echo "I=$i"; done
for i in *.JPG; do echo "I=$i"; done
The one with the quotes is taken literally and passed to for as-is. The one without the quotes is interpreted by the shell and then the results passed to for.
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 10:57 AM.
|
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
|
|