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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-03-2010, 07:59 PM
|
#1
|
|
LQ Newbie
Registered: Mar 2010
Posts: 6
Rep:
|
Find a file in directories without using find command
Hi All,
I am new to linux and trying to find a file in sub directories using find command as:
find . -name *.jpg -type f
But I am unable to get the result as find command is not permitted by the server administrator.
Is there any way to find files without using find command. Kindly help........!!!
Thanks
|
|
|
|
|
Click here to see the post LQ members have rated as the most helpful post in this thread.
|
08-03-2010, 08:11 PM
|
#2
|
|
Senior Member
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,333
Rep:
|
Hya,
I am not quite sure what is your purpose, however, can seek into subdirectories.
Happy Penguins!
|
|
|
1 members found this post helpful.
|
08-03-2010, 08:14 PM
|
#3
|
|
Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594
|
ls has the -R switch (recursive)
EDIT:
I should have thought further ahead on that. As written, it will show you the files, but not where they're located (i.e. full path). The below is better:
Code:
for i in $(ls -R | grep \.jpg); do echo "$(readlink -f "$i")"; done
EDIT 2: This still isn't that useful - it omits the directory tree below the $PWD :/
Last edited by GrapefruiTgirl; 08-03-2010 at 08:46 PM.
Reason: Added afterthought to make useful post.
|
|
|
|
08-03-2010, 08:43 PM
|
#4
|
|
Guru
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian
Posts: 5,339
|
Another thing to try:
whereis [filename]
Wildcards work in the filename, but, if your rights are sufficiently limited, it may not produce the desired results.
|
|
|
|
08-03-2010, 08:50 PM
|
#5
|
|
Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594
|
Gahh!! I'm having a brainless evening here.. My earlier suggestions didn't work well; I tried frankbell's suggestion of `whereis`, and also `which`, but those didn't work. Finally I tried using `locate` and that worked  -- but like frankbell mentioned, `locate` will also not work right if you lack permissions.
Here's an example of something that works, provided you have the permissions:
Code:
sasha@reactor: for i in $(ls -R | grep Argentine); do locate "$i"; done
/home/sasha/Reptile_&_Snake/MISC_other_docs/Argentine_boas.info
/home/sasha/Reptile_&_Snake/snakies_pictures/Occidentalis/B.c.occidentalis.Argentine.2.jpg
/home/sasha/Reptile_&_Snake/snakies_pictures/Occidentalis/B.c.occidentalis.Argentine.3.jpg
/home/sasha/Reptile_&_Snake/snakies_pictures/Occidentalis/B.c.occidentalis.Argentine.jpg
sasha@reactor:
Phew  -- time for sleep I think.
Last edited by GrapefruiTgirl; 08-03-2010 at 08:52 PM.
Reason: Removed unnecesary `echo`
|
|
|
1 members found this post helpful.
|
08-03-2010, 08:56 PM
|
#6
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Rep: 
|
Quote:
Originally Posted by sikanders
find command is not permitted by the server administrator.
|
What about the locate command?
Edit
I was too late with this :P
Last edited by Telengard; 08-03-2010 at 08:58 PM.
|
|
|
|
08-03-2010, 08:58 PM
|
#7
|
|
Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594
|
Quote:
Originally Posted by Telengard
What about the locate command?
|
Good grief  -- look at all the needless crap I've got wrapped around my `locate` command! Works great without all that junk
LMAO :/
Didn't I say it's bedtime?! Hehehe..
P.S. - Is this what they call "cannot see the forest for the trees" ? Or have I got the trees and the forest mixed up?
Last edited by GrapefruiTgirl; 08-03-2010 at 09:00 PM.
|
|
|
|
08-03-2010, 09:01 PM
|
#8
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
if your admin disables find, most probably tools like locate, whereis etc are also disabled ( except if admin only knows about find which i doubt). Then you can just use the shell. (bash, ksh etc)
See here for example
By the way, if there is a policy to restrict commands, why are circumventing it ? If you really need to find your files, then ask your admin to show you how.
|
|
|
2 members found this post helpful.
|
08-03-2010, 09:06 PM
|
#9
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Rep: 
|
Quote:
Originally Posted by ghostdog74
|
That looks like the most promising solution so far. I do think du -h would probably work though, unless the admin was very thorough.
|
|
|
|
08-03-2010, 09:08 PM
|
#10
|
|
Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594
|
I agree - and clicked "helpful" accordingly. Now I'll just go back to searching the forest for trees.
|
|
|
|
08-04-2010, 09:35 PM
|
#11
|
|
LQ Newbie
Registered: Mar 2010
Posts: 6
Original Poster
Rep:
|
Hi All...
Thanks for replying! It helped me a lot in other problems also, but if I want to get the list of all the ".jpg" files then how shoul I proceed, as there are number of sub directories....!!
|
|
|
|
08-04-2010, 09:40 PM
|
#12
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
Quote:
Originally Posted by sikanders
Hi All...
Thanks for replying! It helped me a lot in other problems also, but if I want to get the list of all the ".jpg" files then how shoul I proceed, as there are number of sub directories....!!
|
show what you have done so far.
|
|
|
|
08-04-2010, 11:20 PM
|
#13
|
|
LQ Newbie
Registered: Mar 2010
Posts: 6
Original Poster
Rep:
|
I just tried du -h then it showed the file size and listed all the directories, but I need to find out all the ".jpg" images existing in different sub folders and copy them to a single folder at one place... Kindly help me in this!
|
|
|
|
08-05-2010, 12:15 AM
|
#14
|
|
LQ Newbie
Registered: Mar 2010
Posts: 6
Original Poster
Rep:
|
Here's an example of something that works, provided you have the permissions:
[code]
sasha@reactor: for i in $(ls -R | grep Argentine); do locate "$i"; done
Hey.......!!! Thanks a lot it helped me.....
Using this I found all my .jpg files as:
for i in $(ls -R); do locate "*.jpg" /absolute/path/to/parent/directory; done
Also can you please help me again.......I want to find path to "sik" directory or file wherever existing in sub directories.
Thanks
Last edited by sikanders; 08-05-2010 at 12:17 AM.
|
|
|
|
08-06-2010, 08:47 PM
|
#15
|
|
Guru
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian
Posts: 5,339
|
Thanks for the locate command. That's new one to me. I'm looking forward to trying it.
Aside: The downside of choice is that there are sooooo many choices.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:24 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
|
|