There are at least three ways to find files when you don't know their exact location:
* find
If you have a rough idea of the directory tree the file might be in (or even if you don't and you're prepared to wait a while) you can use find:
$ find directory -name targetfile -print
find will look for a file called targetfile in any part of the directory tree rooted at directory. targetfile can include wildcard characters. For example:
$ find /home -name "*.txt" -print 2>/dev/null
will search all user directories for any file ending in ".txt" and output any matching files (with a full absolute or relative path). Here the quotes (") are necessary to avoid filename expansion, while the 2>/dev/null suppresses error messages (arising from errors such as not being able to read the contents of directories for which the user does not have the right permissions).
find can in fact do a lot more than just find files by name. It can find files by type (e.g. -type f for files, -type d for directories), by permissions (e.g. -perm o=r for all files and directories that can be read by others), by size (-size) etc. You can also execute commands on the files you find. For example,
$ find . -name "*.txt" -exec wc -l '{}' ';'
counts the number of lines in every text file in and below the current directory. The '{}' is replaced by the name of each file found and the ';' ends the -exec clause.
For more information about find and its abilities, use man find and/or info find.
* which (sometimes also called whence) command
If you can execute an application program or system utility by typing its name at the shell prompt, you can use which to find out where it is stored on disk. For example:
$ which ls
/bin/ls
* locate string
find can take a long time to execute if you are searching a large filespace (e.g. searching from / downwards). The locate command provides a much faster way of locating all files whose names match a particular search string. For example:
$ locate ".txt"
will find all filenames in the filesystem that contain ".txt" anywhere in their full paths.
One disadvantage of locate is it stores all filenames on the system in an index that is usually updated only once a day. This means locate will not find files that have been created very recently. It may also report filenames as being present even though the file has just been deleted. Unlike find, locate cannot track down files on the basis of their permissions, size and so on.
* find
If you have a rough idea of the directory tree the file might be in (or even if you don't and you're prepared to wait a while) you can use find:
$ find directory -name targetfile -print
find will look for a file called targetfile in any part of the directory tree rooted at directory. targetfile can include wildcard characters. For example:
$ find /home -name "*.txt" -print 2>/dev/null
will search all user directories for any file ending in ".txt" and output any matching files (with a full absolute or relative path). Here the quotes (") are necessary to avoid filename expansion, while the 2>/dev/null suppresses error messages (arising from errors such as not being able to read the contents of directories for which the user does not have the right permissions).
find can in fact do a lot more than just find files by name. It can find files by type (e.g. -type f for files, -type d for directories), by permissions (e.g. -perm o=r for all files and directories that can be read by others), by size (-size) etc. You can also execute commands on the files you find. For example,
$ find . -name "*.txt" -exec wc -l '{}' ';'
counts the number of lines in every text file in and below the current directory. The '{}' is replaced by the name of each file found and the ';' ends the -exec clause.
For more information about find and its abilities, use man find and/or info find.
* which (sometimes also called whence) command
If you can execute an application program or system utility by typing its name at the shell prompt, you can use which to find out where it is stored on disk. For example:
$ which ls
/bin/ls
* locate string
find can take a long time to execute if you are searching a large filespace (e.g. searching from / downwards). The locate command provides a much faster way of locating all files whose names match a particular search string. For example:
$ locate ".txt"
will find all filenames in the filesystem that contain ".txt" anywhere in their full paths.
One disadvantage of locate is it stores all filenames on the system in an index that is usually updated only once a day. This means locate will not find files that have been created very recently. It may also report filenames as being present even though the file has just been deleted. Unlike find, locate cannot track down files on the basis of their permissions, size and so on.

















rin2


![[-] [-]](images/tech//collapse.gif)


