Finding Files in a Directory Tree by Name

Use find to find files in a directory tree by name. Give the name of the directory tree to search through, and use the `−name' option followed by the name you want to find. · To list all files on the system whose file name is `top', type:

$ find / −name top RET

This command will search all directories on the system to which you have access; if you don't have execute permission for a directory, find will report that permission is denied to search the directory. The `−name' option is case sensitive; use the similar `−iname' option to find name regardless of case. · To list all files on the system whose file name is `top', regardless of case, type:

$ find / −iname top RET

This command would match any files whose name consisted of the letters `top', regardless of case−−including `Top', `top', and `TOP'. Use file expansion characters (see section Specifying File Names with Patterns) to find files whose names match a pattern. Give these file name patterns between single quotes.To list all files on the system whose names begin with the characters `top', type:

$ find / −name 'top*' RET

To list all files whose names begin with the three characters `top' followed by exactly three morecharacters, type:

$ find / −name 'top???' RET

To list all files whose names begin with the three characters `top' followed by five or more characters, type:

$ find / −name 'top?????*' RET

To list all files in your home directory tree that end in `.tex', regardless of case, type:

$ find ~ −iname '*.tex' RET

To list all files in the `/usr/share' directory tree with the text `farm' somewhere in their name, type:

$ find /usr/share −name '*farm*' RET

Use `−regex' in place of `−name' to search for files whose names match a regular expression, or a pattern describing a set of strings (see section Regular Expressions−−Matching Text Patterns). To list all files in the current directory tree whose names have either the string `net' or `comm' anywhere in their file names, type:

$ find . −regex '.*\(net\|comm\).*' RET

NOTE: The `−regex' option matches the whole path name, relative to the directory tree you specify, and not just file names.

Posted on: 16/12/2009








0 Comments
If you want to leave a comment please Login or Register
How to backup your data using rsync......
Understanding autoconf......
The Basics of fdisk......
Accessing Memory Using DMA......
The fd Directory......