LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 12-08-2009, 01:04 PM   #1
markdjones82
LQ Newbie
 
Registered: Nov 2004
Location: Dallas
Distribution: Suse 9.1
Posts: 15

Rep: Reputation: 0
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?
 
Old 12-08-2009, 01:16 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
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.
 
Old 12-08-2009, 01:18 PM   #3
markdjones82
LQ Newbie
 
Registered: Nov 2004
Location: Dallas
Distribution: Suse 9.1
Posts: 15

Original Poster
Rep: Reputation: 0
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/*
 
Old 12-09-2009, 03:16 PM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by markdjones82 View Post
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 \{\}/* \;
 
Old 12-09-2009, 08:17 PM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by markdjones82 View Post
You can't put wild cards in find's path.
yes you can. what OS platform are you on.
 
Old 12-10-2009, 06:35 AM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Completely ignore this post, I missed the point.

Last edited by i92guboj; 12-10-2009 at 10:14 AM.
 
Old 12-10-2009, 09:55 AM   #7
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
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?
 
Old 12-10-2009, 10:13 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
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.
 
Old 12-10-2009, 10:42 AM   #9
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by i92guboj View Post
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
Code:
mv *.c some_dir
But by mistake typed only

Code:
mv *.c
And to my bad luck I had only two c files !
So after expansions command looked like
Code:
mv file1.c file2.c
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.
 
Old 12-10-2009, 02:30 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by ghostdog74 View Post
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
 
Old 12-10-2009, 07:32 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,417

Rep: Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785
the -name option can have wildcards in single quotes eg

-name '*.dat'

so it (*) gets interpreted by the find cmd, not the current shell
 
Old 12-11-2009, 01:51 AM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by chrism01 View Post
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.
 
Old 12-11-2009, 02:02 AM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,417

Rep: Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785
Yeah, I should have pointed out that was a response to post #8
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed - multiline search/replace with wildcard troubles Yalla-One Programming 4 12-29-2008 01:01 PM
MYSQL search query by column name using wildcard AQG Programming 9 08-07-2007 10:41 AM
how to unzip all files with a wildcard path? adamrosspayne Linux - Newbie 12 06-20-2006 02:16 PM
Find command using 2 search conditions nifflerX Linux - General 8 07-15-2005 02:37 PM
pattern search through find command. abhi Linux - Newbie 2 04-11-2005 11:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration