This is a n00b question I am asked a lot.
Several ways to do this.
Easy way is to use the find command (search your directory)
The general format is: find path -name expression
find -name 'potato*'
Yields:
./potato_head.jpg
./recipes/potato.txt
./recipes/potato.wp
./wp51/recipes/potato.txt
./wp51/recipes/potato.wp
The period (dot) at the beginning says the file is located in the currently logged in account.
You may be wondering about a couple of things:
1. Why does the search expression have SINGLE quotes?
That’s so we can search for a string with special characters in it.
2. Why do you have an asterisk (*) at the end of the search string?
That’s so it will match ANYTHING that starts with the word BEFORE the asterisk (*)
3. What if I want to search the entire hard drive?
sudo find / -name 'potato*'
/ indicates the root directory.
Now this does search the entire hard drive. The sudo is necessary because you have to have permission to read other directories other then your own.
Another method is to use locate. We’ll discuss that in another post.
How did you do? Did you find the file you were looking for?
Related Articles
3 users responded in this post
I find that the locate command is really easy to use because it doesn’t need any flags to be used; simply typing locate filename works as is and returns the same results as find does.
locate command requires you to install and configure the database (another post).
find works on any *nix system.
Wayno
[…] the previous post I showed you how to use the find command. Find works on any Linux system. But it does require some […]