Linux - NewbieThis 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.
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.
Have you looked at the 'find' command. It has a lot of options, such as setting type to regular file, specifying the desired path, and even things like newer / older than a particular time. A simple example, assuming I am interpreting your examples correctly, would be like:
The search directory or directories are given separately from the filename, so if you want to find a particular file, file.txt, in directory /home/me/myfiles you would search by:
find /home/me/myfiles -name file.txt
You can also search more than one directory for filenames or patterns, for example:
find /etc /var -name '*.log'
The find utility is a very powerful search tool. Refer to the man pages for more information.
i think i didn't formulate my question right. Let me clarify :
i want to search for the pattern "dir2/dir3/file.txt", not from the current directory, but across several other directories.
The idea is that the same file (file.txt) maybe in several directories and to uniquely identify the right one i need to bring the 2 directories (above it) into equation...
hope this helps . If not - please let me know.
So in Noway2's example, i can't use dir1/dir2 as a starting search directory - because i should be able to search in any directory.
smth like this :
find directory_Blah -name 'dir2/dir3/file.txt'
I probably should also note that i'm stuck on Solaris. ( don't have gnu here )
To Tink:
man find
/regex
Pattern not found
.
I did RTFM and nothing caught my eye. I tried playing with ' and \ as well as adding * instead of /. But that didn't help. apparently i'm missing smth obvious.
i think i didn't formulate my question right. Let me clarify :
i want to search for the pattern "dir2/dir3/file.txt", not from the current directory, but across several other directories.
The idea is that the same file (file.txt) maybe in several directories and to uniquely identify the right one i need to bring the 2 directories (above it) into equation...
hope this helps . If not - please let me know.
So in Noway2's example, i can't use dir1/dir2 as a starting search directory - because i should be able to search in any directory.
smth like this :
find directory_Blah -name 'dir2/dir3/file.txt'
I probably should also note that i'm stuck on Solaris. ( don't have gnu here )
To Tink:
man find
/regex
Pattern not found
.
I did RTFM and nothing caught my eye. I tried playing with ' and \ as well as adding * instead of /. But that didn't help. apparently i'm missing smth obvious.
Yeah, the find that comes with Solaris by default is an antique,
doesn't know half the features of GNU find.
Easiest will be to find . -type f | grep dir1/dir2/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.