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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-29-2012, 06:27 AM
|
#1
|
LQ Newbie
Registered: Nov 2011
Posts: 18
Rep: 
|
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.
|
|
|
04-29-2012, 06:28 AM
|
#2
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Use find's -d option.
|
|
|
04-29-2012, 06:33 AM
|
#3
|
LQ Newbie
Registered: Nov 2011
Posts: 18
Original Poster
Rep: 
|
not working find's -d
|
|
|
04-29-2012, 06:36 AM
|
#4
|
LQ Newbie
Registered: Nov 2011
Posts: 18
Original Poster
Rep: 
|
i am using Red hat Enterprise Linux 5.4
Thanks 4 replay
|
|
|
04-29-2012, 06:38 AM
|
#5
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Sorry, should be -type d
|
|
|
04-29-2012, 06:42 AM
|
#6
|
LQ Newbie
Registered: Nov 2011
Posts: 18
Original Poster
Rep: 
|
so the full command should be
find / -name -type d abir* or
find / -type d abir*
Thanks 4 replay
|
|
|
04-29-2012, 06:50 AM
|
#7
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Code:
find / -type d -name 'abir*'
The single quotes avoid abir* being changed by the shell file name expansion
|
|
|
04-29-2012, 06:57 AM
|
#8
|
LQ Newbie
Registered: Nov 2011
Posts: 18
Original Poster
Rep: 
|
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
|
|
|
04-29-2012, 07:06 AM
|
#9
|
LQ Newbie
Registered: Nov 2011
Posts: 18
Original Poster
Rep: 
|
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
|
|
|
04-29-2012, 07:19 AM
|
#10
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
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 ?
|
|
|
04-29-2012, 07:33 AM
|
#11
|
LQ Newbie
Registered: Nov 2011
Posts: 18
Original Poster
Rep: 
|
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
|
|
|
04-29-2012, 08:18 AM
|
#12
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,038
|
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.
|
|
|
04-29-2012, 10:31 AM
|
#13
|
LQ Newbie
Registered: Nov 2011
Posts: 18
Original Poster
Rep: 
|
it works.
Thanks
|
|
|
04-29-2012, 11:32 AM
|
#14
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,038
|
No problem. Please mark as SOLVED once you have a solution.
|
|
|
All times are GMT -5. The time now is 12:54 AM.
|
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
|
|