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. |
Use find's -d option.
|
not working find's -d
|
i am using Red hat Enterprise Linux 5.4
Thanks 4 replay |
Sorry, should be -type d
|
so the full command should be
find / -name -type d abir* or find / -type d abir* Thanks 4 replay |
Code:
find / -type d -name 'abir*' |
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 |
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 |
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 ? |
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 |
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 Take it off if this is not the case. |
it works.
Thanks |
No problem. Please mark as SOLVED once you have a solution.
|
All times are GMT -5. The time now is 11:34 PM. |