[SOLVED] Display contents of the file searched by grep or find command
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
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.
Display contents of the file searched by grep or find command
I have lots of directories in a certain directory and I am trying to find a specific file present in there. I used grep command recursively and was able to locate the file being present in there, but I don't know where it is present exactly. So, how can I use cat on that file to display the contents of that file?
By default, the utility grep will tell you which file the pattern was found in along with the line on which it was found. If you want to see just the file name, try adding the -l option to it.
One you've found the file, you can use a pager like less or more to see it one page at a time. Despite the name less is greater than more and for whichever one you choose, you'll want to take a look at the manual page.
I found the file by using grep -l command, but how do I find in which directory that file is present? Can I display the contents of the file without knowing where exactly that file is present in the directory structure? Thank you for the answer.
Last edited by SecureShell; 06-13-2019 at 08:32 AM.
When I do grep -l, it does not provide the complete path of where the file is present, it just gives me the long description of the file, along with the name of the file. The question I want to ask is how do I find the complete path of the file?
When I do grep -l, it does not provide the complete path of where the file is present, it just gives me the long description of the file, along with the name of the file.
That is a very nonstandard implementation of grep.
What is the OS and platform where you are seeing this?
What is the output when you run "type grep" ?
Oh..I understand now. I was doing it all wrong. Actually I am trying to find a file with specific size in the given directory structure. So, for that, I was using grep -l -R command and was piping the output to the grep command as grep <filesize> to find that file. But it gives me a long description of the file without the path of the file. Is there any way to find the path of that file?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.