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 am in the root directory and i need to search for a specific file in the sysconfig directory, is there any way to search this directory for a file?
If you've got locate/slocate/mlocate on your system you can also type:
Code:
locate filename
Locate is typically faster than find over a large structure, but requires you to generally crontab the updatedb program to run daily/weekly/monthly... and it's results are only as recent as the last time the updatedb ran.
I very seldom know the exact name of a file so I use "krusader" to do my file search. Just open krusader, go to "tools" in the top toolbar. Click on search. If the file name is "johnwenttotown" just type in john, on the second line type in"/" to search all. It will give you every file that starts with john and what directory they are in. If you click on it, it will take you to that file.
If you only know part of the filename you can use wildcards with find (piping find's output to grep is a less efficient way of doing the same thing). If it's an ordinary file (not a directory, a device file ...) then you can speed find along by specifying so. If you are not running the find as root then find will generate a lot of error messages when it can't enter directories; you don't need to see these because you can't reach any files in those directories. Combining all the above
Code:
find / -type f -iname '*foo*' 2>/dev/null
The single quotes around *foo* are required in case there are any files matching *foo* in the current directory.
I find the easiest way to do this is by using the following, its quick and dirty and it works
...<SNIP>...
Use the more for page viewing if a long list. Otherwise you can remove it.
Am I wrong in doing it this way?
It works so I am not complaining.
You're not wrong, but you miss some of the more advanced features of find...
Will find any file with .htm under /var/www and chown it to apache:apache and change the perms to 644. Then change every directory under /var/www to 755 and chown them to apache:apache also.
You can accomplish this with piping also but its generally far easier using the advanced structures of find... and for me personally, "-iname filename" or " | grep filename" I'll take the one with the lesser amount of typing, plus to make grep case insensitive you'd also have to add -i which makes it longer yet. Economy of typing.
Honestly though, that's one of the great things about unix, there are 10 different ways you can go about many tasks.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.