Forum     

Go Back   Digit Technology Discussion Forum > Software > Open Source
Register FAQ Calendar Mark Forums Read

Open Source A place where you can talk to like-minded people about the fastest growing software movement today! Discuss anything and everything about Open Source software and Operating Systems.


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 01-06-2007, 02:43 PM   #1 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default using the ls command and grep to get the whole path


I have been using the following command to search for files on my hard disk

ls -R | grep pattern
to find files named pattern or something.

But the problem is that i am unable to find the whole path. So then I have to search again trying in increments of 5 lines or so before that. Like
ls -R |grep -B 5 pattern
and if the path is not listed then
ls -R |grep -B 10 pattern
and so on. finally I get the path.

There has got to be a simpler way right?
I tried searching but am not able to make much sense out of them. Can someone please help?
__________________
Life is too short. Have fun.
ilugd is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 01-06-2007, 02:48 PM   #2 (permalink)
In Pursuit of "Happyness"
 
kalpik's Avatar
 
Join Date: May 2005
Location: New Delhi
Posts: 3,432
Default Re: using the ls command and grep to get the shole path

Try the locate/slocate/find commands
__________________
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
kalpik is offline  
Old 01-06-2007, 02:55 PM   #3 (permalink)
Coming back to life ..
 
it_waaznt_me's Avatar
 
Join Date: Nov 2003
Location: A bit closer to heaven
Posts: 1,997
Default Re: using the ls command and grep to get the shole path

Why dont you use a command like this :

find . -ls -name searchpattern
__________________
Sleight of hand and twist of fate...
On a bed of nails she makes me wait...
And I wait without you ...
With or without you ..
----
Batty = Too Busy Now !!!
it_waaznt_me is offline  
Old 01-06-2007, 03:01 PM   #4 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: using the ls command and grep to get the shole path

I use the locate command to search the filesystem. However, if you've just created a file which you want to search for, you'll have to rebuild the database with the rehash command. The only disadvantage with locate is that you can't tell it to search just under a particular directory, ie it will always search the entire filesystem. However, this can be remedied with a grep.

eg,

Code:
This will locate PATTERN wherever it occurs in any filename :
$ locate PATTERN

This will locate PATTERN if it is regex :
$ locate --regex PATTERN

This will filter based on a directory :
$ lcoate --regex PATTERN | grep <directory path>
EDIT : It's updatedb, and not rehash, sorry. rehash is for completion.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --

Last edited by Sykora; 01-06-2007 at 04:58 PM.
Sykora is offline  
Old 01-06-2007, 03:43 PM   #5 (permalink)
left this forum longback
 
praka123's Avatar
 
Join Date: Sep 2005
Location: -
Posts: 7,536
Default Re: using the ls command and grep to get the shole path

^is it slocate now?and u need to run or cron "updatedb" .
__________________
left this forum long back.Admin Can Delete this Account and posts Permanantly.Thank You
Get GNU/Linux - http://getgnulinux.org
praka123 is offline  
Old 01-06-2007, 05:44 PM   #6 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default Re: using the ls command and grep to get the shole path

i most probably will be disabling any indexing services (locate uses indexes, right?) so i don't really want to do that. What i am really wondering about is whether there is a way to make ls or ll or any such directory listing commands list the whole path of a file in each line. Grep will take care of the rest, i hope.
__________________
Life is too short. Have fun.
ilugd is offline  
Old 01-06-2007, 06:20 PM   #7 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: using the ls command and grep to get the shole path

AFAIK, the cron job for the database is enabled by default. You don't have to do anything.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 06-06-2007, 02:36 AM   #8 (permalink)
El mooooo
 
eddie's Avatar
 
Join Date: Jan 2006
Location: India
Posts: 1,414
Default Re: using the ls command and grep to get the whole path

Try the following script. It will not give you exact path but if you run it in a folder along with less command then you can know the exact location and the depth of the file in the current directory.
Attached Files
File Type: txt tree.txt (1.9 KB, 4 views)
__________________
Windows users shouldn't get to use the real computers. They know just enough to be dangerous.
eddie is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want help with Path of Neo debsuvra Gamerz 2 31-05-2007 10:36 AM
COMMAND & CONQUER UPDATE - EA shoots out Command & Conquer 3 demo techtronic Gamerz 1 28-02-2007 12:18 PM
The Matrix: Path of Neo anilthomas26 Gamerz 8 03-10-2005 01:54 AM
The Matrix: Path of Neo tarey_g Gamerz 20 21-03-2005 07:09 PM

 
Latest Threads
- by Sujeet
- by soumya
- by clmlbx
- by Charan
- by reddick

Advertisement




All times are GMT +5.5. The time now is 12:37 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2