Monday, July 15, 2013

How to search files and folders with a given partial name in a terminal

If you are looking for a specific file or folder in your filesystem, you need to use the linux/mac/UNIX command find

Type in a terminal the following command:

find path -name "partial name"

Example.
Suppose, you want to run a search across the entire filesystem looking for a file called foo (or containing foo in its name), in this case your command becomes:

find / -name "*foo*"

NOTES:

1) If you really want to start the search from root, keep in mind that as normal user you could not access some directories, so put a sudo in front of the command to become superuser! :

sudo find / -name "*foo*"

2) If you start from root, your search will take some time....

3) You can save the results in a file called my_search.txt in this way:

sudo find / -name "*foo*"> my_search.txt

(the file my_search.txt will be created in your current directory,  the one you get with the command pwd)




No comments:

Post a Comment

Your comment will be visible after approval.