Читать книгу Linux Bible - Christopher Negus - Страница 160

Searching for files with find

Оглавление

The find command is the best one for searching your filesystem for files based on a variety of attributes. After files are found, you can act on those files as well (using the -exec or -okay option) by running any commands you want on them.

When you run find, it searches your filesystem live, which causes it to run slower than locate, but it gives you an up-to-the-moment view of the files on your Linux system. However, you can also tell find to start at a particular point in the filesystem so that the search can go faster by limiting the area of the filesystem being searched.

Nearly any file attribute that you can think of can be used as a search option. You can search for filenames, ownership, permission, size, modification times, and other attributes. You can even use combinations of attributes. Here are some basic examples of using the find command:

 $ find $ find /etc # find /etc $ find $HOME -ls

Run on a line by itself, the find command finds all files and directories below the current directory. If you want to search from a particular point in the directory tree, just add the name of the directory you want to search (such as /etc). As a regular user, find does not give you special permission to find files that have permissions that make them readable only by the root user. So, find produces a bunch of error messages. Run as the root user, find /etc finds all files under /etc.

A special option to the find command is -ls. A long listing (ownership, permission, size, and so on) is printed with each file when you add -ls to the find command (similar to output of the ls -l command). This option helps you in later examples when you want to verify that you have found files that contain the ownership, size, modification times, or other attributes that you are trying to find.

Linux Bible

Подняться наверх