LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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



Reply
 
Search this Thread
Old 08-03-2010, 08:59 PM   #1
sikanders
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Rep: Reputation: 0
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.
Old 08-03-2010, 09:11 PM   #2
kaz2100
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,455

Rep: Reputation: 84
Hya,

I am not quite sure what is your purpose, however,
Code:
du -h
can seek into subdirectories.

Happy Penguins!
 
1 members found this post helpful.
Old 08-03-2010, 09:14 PM   #3
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Code:
ls -R | grep \.jpg
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 09:46 PM. Reason: Added afterthought to make useful post.
 
Old 08-03-2010, 09:43 PM   #4
frankbell
Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Mageia, Mint
Posts: 8,243

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
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.
 
Old 08-03-2010, 09:50 PM   #5
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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 09:52 PM. Reason: Removed unnecesary `echo`
 
1 members found this post helpful.
Old 08-03-2010, 09:56 PM   #6
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by sikanders View Post
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 09:58 PM.
 
Old 08-03-2010, 09:58 PM   #7
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by Telengard View Post
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 10:00 PM.
 
Old 08-03-2010, 10:01 PM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
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.
Old 08-03-2010, 10:06 PM   #9
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by ghostdog74 View Post
That looks like the most promising solution so far. I do think du -h would probably work though, unless the admin was very thorough.
 
Old 08-03-2010, 10:08 PM   #10
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
I agree - and clicked "helpful" accordingly. Now I'll just go back to searching the forest for trees.
 
Old 08-04-2010, 10:35 PM   #11
sikanders
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Original Poster
Rep: Reputation: 0
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....!!
 
Old 08-04-2010, 10:40 PM   #12
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by sikanders View Post
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.
 
Old 08-05-2010, 12:20 AM   #13
sikanders
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Original Poster
Rep: Reputation: 0
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!
 
Old 08-05-2010, 01:15 AM   #14
sikanders
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Thumbs up

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 01:17 AM.
 
Old 08-06-2010, 09:47 PM   #15
frankbell
Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Mageia, Mint
Posts: 8,243

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
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.
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Telling find command to ignore directories LinuxGeek Linux - Software 10 08-17-2011 09:39 AM
[SOLVED] command to find a specific word in directories and subdirectories? siranjeevi Linux - Newbie 4 06-09-2010 10:19 AM
How to find directories that do not have a certain file subsonix Programming 5 05-29-2010 01:56 PM
copying directories recursively with find command nanda22 Linux - Newbie 1 09-01-2008 08:39 AM
mount command cant find smb directories but file-browsers can map to them. robertbas Linux - Networking 2 09-21-2006 04:12 AM


All times are GMT -5. The time now is 10:03 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration