LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-29-2012, 06:27 AM   #1
rabir
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Rep: Reputation: Disabled
Question How To grep only directory


Hi Everyone.

i am newbie at Linux n trying to find out a file in which directory. as
find / -name abir* but
results shows as
/root/Desktop/abir/abir.sh
/root/Desktop/abir/abir.txt

but i need only directory as
/root/Desktop/abir/

Thanks in Advance for Help.

Last edited by rabir; 04-29-2012 at 06:45 AM.
 
Old 04-29-2012, 06:28 AM   #2
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
Use find's -d option.
 
Old 04-29-2012, 06:33 AM   #3
rabir
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
not working find's -d
 
Old 04-29-2012, 06:36 AM   #4
rabir
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
i am using Red hat Enterprise Linux 5.4

Thanks 4 replay
 
Old 04-29-2012, 06:38 AM   #5
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
Sorry, should be -type d
 
Old 04-29-2012, 06:42 AM   #6
rabir
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
so the full command should be
find / -name -type d abir* or
find / -type d abir*

Thanks 4 replay
 
Old 04-29-2012, 06:50 AM   #7
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
Code:
find / -type d -name 'abir*'
The single quotes avoid abir* being changed by the shell file name expansion
 
Old 04-29-2012, 06:57 AM   #8
rabir
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
still not working
i try it as
find / -type d -name 'abir*' &
find / -type d -name "abir*" &
find / -type d -name abir* &&
find / -name abir* -type d


thanks 4 replay
 
Old 04-29-2012, 07:06 AM   #9
rabir
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
is there any option that extract only directory as

v1=/root/Desktop/abir/abir.txt

from that variable i can take only the part of

v2=/root/Desktop/abir/

thanks 4 help
 
Old 04-29-2012, 07:19 AM   #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
If directory /root/Desktop/abir exists and is reachable by the user (does ls -d /root/Desktop/abir work?) then find / -type d -name 'abir*' should work.

If it does not work, is there any output?

What is the output of type find ?
 
Old 04-29-2012, 07:33 AM   #11
rabir
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
i usually work as root. so no problem to reach any directory.

i also make some practice on your command as
if any name in the directory as "abir" then it works as

/root/Desktop/abir

but
if the directory is /root/Desktop/rabir/abir.txt

then your command is not working .

but i need only the directory that the file stay in ?

thanks for response
 
Old 04-29-2012, 08:18 AM   #12
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,038

Rep: Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203
I think you are saying that you wish to search for files containing abir but return the directory they reside in. Is this correct?

Assuming yes, try this:
Code:
find / -type f -name 'abir*' -printf "%h\n" | uniq
I put the uniq in as your examples show that there might be more than one abir file in a directory and every occurrence will return the directory name.
Take it off if this is not the case.
 
Old 04-29-2012, 10:31 AM   #13
rabir
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
it works.

Thanks
 
Old 04-29-2012, 11:32 AM   #14
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,038

Rep: Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203
No problem. Please mark as SOLVED once you have a solution.
 
  


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
grep root directory mahendra singh Linux - Newbie 3 03-06-2011 08:51 AM
How to configure 'grep' to ignore 'No such file or directory n179911 Linux - Newbie 4 07-08-2009 04:14 AM
grep a directory with date order ust Linux - Newbie 4 02-16-2009 02:17 AM
problem with grep in root directory river_jetties Linux - Software 3 01-22-2007 01:10 PM
how to grep a specifc directory irfanhab Linux - General 3 12-19-2005 08:44 PM

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

All times are GMT -5. The time now is 12:54 AM.

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