If I don't know what directory a file is located how would I write the command
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.
If I don't know what directory a file is located how would I write the command
I am now trying to learn file location and have been watching videos on youtube but I have decided this is not a good idea because I am learning but some of the videos have people that have less knowledge than me. I have learned about a find command that would directly find a file but lets say I have a file that I have no clue what directory it is in how would I locate it? I am not talking about a specific file just any in general file.
Thanks
LOL so if I wanted to find a file named hollysdog and I didn't know what directory it was located in I would type find / -hollysdog foo.txt
Then I could find the directory this file is located in? I know this is basic but I have to crawl before I can walk so please bear with me.
This will find a file or directory named hollysdog regardless of case. It will match hollysdog whether iit is all lowercase, upper or in between.
Code:
find / -iname "*hollysdog*"
Same as above but it will list all instances of hollysdog. The * is a wildcard for any character(s) before and after hollysdog
If you're looking for file(s) only and want to skip directories add -type f
If you're looking for directories only add -type d
PS: You can start a search from any directory. Just replace / for the desired directory or you can use a (.) period to search from a current directory.
You are correct and that will find the exact match.
But I use -iname in this example and this will do a case insensitive search of the pattern in case hollysdog is a mixed case of lowercase and uppercase characters
Well we're both right. If the OP uses -name for exact match search and doesn't yield no results he can then use -iname for case insensitive search. I personally use both where appropriate.
Yes, but so what? I was answering a question from the OP, and then you felt the need to tell me that what I said was correct while sliding in the implication that your answer was superior. You're new to LQ so I'll leave it at that.
find has got 3 components.
(1) Find from where?. In this case, find from root and hence /
(2) Find what criterion? lets say the name of the file is hollysdog. Then -name hollysdog . or use -iname hollysdog
(3) Do what? Default is to list the files "found" matching the criterion.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.