LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 07: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, 08:11 PM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,832

Rep: Reputation: 108Reputation: 108
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, 08:14 PM   #3
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
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 08:46 PM. Reason: Added afterthought to make useful post.
 
Old 08-03-2010, 08:43 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
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, 08:50 PM   #5
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

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

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

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
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 09:00 PM.
 
Old 08-03-2010, 09:01 PM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
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, 09:06 PM   #9
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 148Reputation: 148
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, 09:08 PM   #10
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
I agree - and clicked "helpful" accordingly. Now I'll just go back to searching the forest for trees.
 
Old 08-04-2010, 09: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, 09:40 PM   #12
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
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-04-2010, 11:20 PM   #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, 12: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 12:17 AM.
 
Old 08-06-2010, 08:47 PM   #15
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
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



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 08:39 AM
[SOLVED] command to find a specific word in directories and subdirectories? siranjeevi Linux - Newbie 4 06-09-2010 09:19 AM
How to find directories that do not have a certain file subsonix Programming 5 05-29-2010 12:56 PM
copying directories recursively with find command nanda22 Linux - Newbie 1 09-01-2008 07:39 AM
mount command cant find smb directories but file-browsers can map to them. robertbas Linux - Networking 2 09-21-2006 03:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:53 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