Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
|
|
12-08-2009, 01:04 PM
|
#1
|
LQ Newbie
Registered: Nov 2004
Location: Dallas
Distribution: Suse 9.1
Posts: 15
Rep:
|
Find command to search wildcard in path?
All,
I need a command to search for any file in a directory like so:
/home/*/upload/* and then change permissions any file in that directory.
Find doesn't seem to match what I need. Any help?
|
|
|
12-08-2009, 01:16 PM
|
#2
|
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833
Rep:
|
You sure find doesn't work...
Code:
find /home/*/upload/* -type f -exec chmod 700 {} \;
If that doesn't work perhaps explain why and I can revise it or find another solution.
|
|
|
12-08-2009, 01:18 PM
|
#3
|
LQ Newbie
Registered: Nov 2004
Location: Dallas
Distribution: Suse 9.1
Posts: 15
Original Poster
Rep:
|
You can't put wild cards in find's path. I could probably do a bash script, but I am drawing a blank.
Even a while loop with something like echo /home/path/*/upload to a variable would work and then running chmod 755 $variable/*
|
|
|
12-09-2009, 03:16 PM
|
#4
|
ELF Statifier author
Registered: Oct 2007
Posts: 676
Rep:
|
Quote:
Originally Posted by markdjones82
You can't put wild cards in find's path. I could probably do a bash script, but I am drawing a blank.
Even a while loop with something like echo /home/path/*/upload to a variable would work and then running chmod 755 $variable/*
|
What about
Code:
find /home -type d -name upload -exec chmod 700 \{\}/* \;
|
|
|
12-09-2009, 08:17 PM
|
#5
|
Senior Member
Registered: Aug 2006
Posts: 2,697
|
Quote:
Originally Posted by markdjones82
You can't put wild cards in find's path.
|
yes you can. what OS platform are you on.
|
|
|
12-10-2009, 06:35 AM
|
#6
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083
|
Completely ignore this post, I missed the point.
Last edited by i92guboj; 12-10-2009 at 10:14 AM.
|
|
|
12-10-2009, 09:55 AM
|
#7
|
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833
Rep:
|
Funny the find worked perfectly for me when I tested it against...
/home/*/Maildir/* (with a -print instead of -exec) *shrug*
Did you actually try it with the wildcards or are you assuming?
|
|
|
12-10-2009, 10:13 AM
|
#8
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083
|
Interestingly enough, it works with paths but not files names (i.e. for -iname * or -name *). So you are right, I just got confused or so it seems.
Sorry for the disruption.
|
|
|
12-10-2009, 10:42 AM
|
#9
|
ELF Statifier author
Registered: Oct 2007
Posts: 676
Rep:
|
Quote:
Originally Posted by i92guboj
Interestingly enough, it works with paths but not files names (i.e. for -iname * or -name *). So you are right, I just got confused or so it seems.
Sorry for the disruption.
|
When you use it as -iname * (and your CURRENT DIRECTORY is not empty) shell will expand * to the list of all files in the directory, so you (most likely) get syntax error, like if you write
Code:
find ... -name a.c b.c c.o
But if no expansions happened or if multiple arguments correct from the find POV of view, it will work.
Talking about * expansions.
Some time ago I tried to move my c files to the other directory.
I intended to write
But by mistake typed only
And to my bad luck I had only two c files !
So after expansions command looked like
And mv was happy to overwrite my file2.c
If I had more than two files, than command would be
Code:
[prompt]$ mv file1.c file.2 file.3c
mv: target `file3.c' is not a directory
But as I already said - bad luck.
|
|
|
12-10-2009, 02:30 PM
|
#10
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by ghostdog74
yes you can. what OS platform are you on.
|
The -path test provides that functionality but it may not be needed because the shell will expand /home/*/upload/* before calling find.
Surprisingly (I was surprised) the path [path ...] part of find's syntax does not have to comprise directories:
Code:
c:~/d$ cd /tmp
c:/tmp$ touch foo
c:/tmp$ find foo
foo
|
|
|
12-10-2009, 07:32 PM
|
#11
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,417
|
the -name option can have wildcards in single quotes eg
-name '*.dat'
so it (*) gets interpreted by the find cmd, not the current shell
|
|
|
12-11-2009, 01:51 AM
|
#12
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by chrism01
the -name option can have wildcards in single quotes eg
-name '*.dat'
so it (*) gets interpreted by the find cmd, not the current shell
|
Thanks chrism01 but as I understand the OP ( /home/*/upload/* and then change permissions any file in that directory) it is directories that are to be wildcarded.
|
|
|
12-11-2009, 02:02 AM
|
#13
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,417
|
Yeah, I should have pointed out that was a response to post #8
|
|
|
All times are GMT -5. The time now is 11:39 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
|
|