特殊:Badtitle/NS100:Find:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第4行: | 第4行: | ||
The GNU find command search files within within a directory and its subdirectories according to several criteria such as name, size and time of last read/write. It performs actions on the files found, by default it prints the name of the files. | The GNU find command search files within within a directory and its subdirectories according to several criteria such as name, size and time of last read/write. It performs actions on the files found, by default it prints the name of the files. | ||
The GNU find command is installed on every Ubuntu system. This page is complemented by the manual('man') page for find which can be read by issuing the command "man find". | The GNU find command is installed on every Ubuntu system. This page is complemented by the manual('man') page for find which can be read by issuing the command "man find". | ||
(See Self:BasicCommands for a quick introduction to the command line) | (See Self:[[UbuntuHelp:BasicCommands|BasicCommands]] for a quick introduction to the command line) | ||
== The Basics == | == The Basics == | ||
The general syntax for using finds is: | The general syntax for using finds is: |
2007年12月4日 (二) 10:29的版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/find }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/af | • {{#if: UbuntuHelp:find|Afrikaans| [[::Find/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/ar | • {{#if: UbuntuHelp:find|العربية| [[::Find/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/az | • {{#if: UbuntuHelp:find|azərbaycanca| [[::Find/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/bcc | • {{#if: UbuntuHelp:find|جهلسری بلوچی| [[::Find/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/bg | • {{#if: UbuntuHelp:find|български| [[::Find/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/br | • {{#if: UbuntuHelp:find|brezhoneg| [[::Find/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/ca | • {{#if: UbuntuHelp:find|català| [[::Find/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/cs | • {{#if: UbuntuHelp:find|čeština| [[::Find/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/de | • {{#if: UbuntuHelp:find|Deutsch| [[::Find/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/el | • {{#if: UbuntuHelp:find|Ελληνικά| [[::Find/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/es | • {{#if: UbuntuHelp:find|español| [[::Find/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/fa | • {{#if: UbuntuHelp:find|فارسی| [[::Find/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/fi | • {{#if: UbuntuHelp:find|suomi| [[::Find/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/fr | • {{#if: UbuntuHelp:find|français| [[::Find/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/gu | • {{#if: UbuntuHelp:find|ગુજરાતી| [[::Find/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/he | • {{#if: UbuntuHelp:find|עברית| [[::Find/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/hu | • {{#if: UbuntuHelp:find|magyar| [[::Find/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/id | • {{#if: UbuntuHelp:find|Bahasa Indonesia| [[::Find/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/it | • {{#if: UbuntuHelp:find|italiano| [[::Find/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/ja | • {{#if: UbuntuHelp:find|日本語| [[::Find/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/ko | • {{#if: UbuntuHelp:find|한국어| [[::Find/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/ksh | • {{#if: UbuntuHelp:find|Ripoarisch| [[::Find/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/mr | • {{#if: UbuntuHelp:find|मराठी| [[::Find/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/ms | • {{#if: UbuntuHelp:find|Bahasa Melayu| [[::Find/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/nl | • {{#if: UbuntuHelp:find|Nederlands| [[::Find/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/no | • {{#if: UbuntuHelp:find|norsk| [[::Find/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/oc | • {{#if: UbuntuHelp:find|occitan| [[::Find/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/pl | • {{#if: UbuntuHelp:find|polski| [[::Find/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/pt | • {{#if: UbuntuHelp:find|português| [[::Find/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/ro | • {{#if: UbuntuHelp:find|română| [[::Find/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/ru | • {{#if: UbuntuHelp:find|русский| [[::Find/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/si | • {{#if: UbuntuHelp:find|සිංහල| [[::Find/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/sq | • {{#if: UbuntuHelp:find|shqip| [[::Find/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/sr | • {{#if: UbuntuHelp:find|српски / srpski| [[::Find/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/sv | • {{#if: UbuntuHelp:find|svenska| [[::Find/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/th | • {{#if: UbuntuHelp:find|ไทย| [[::Find/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/tr | • {{#if: UbuntuHelp:find|Türkçe| [[::Find/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/vi | • {{#if: UbuntuHelp:find|Tiếng Việt| [[::Find/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/yue | • {{#if: UbuntuHelp:find|粵語| [[::Find/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/zh | • {{#if: UbuntuHelp:find|中文| [[::Find/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/zh-hans | • {{#if: UbuntuHelp:find|中文(简体)| [[::Find/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:find | UbuntuHelp:find | {{#if: | :}}Find}}/zh-hant | • {{#if: UbuntuHelp:find|中文(繁體)| [[::Find/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:find|:Find|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :Find/zh | | {{#ifexist: Find/zh | | {{#ifeq: {{#titleparts:Find|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Find|1|-1|}} | zh | | }}
What Is find?
The GNU find command search files within within a directory and its subdirectories according to several criteria such as name, size and time of last read/write. It performs actions on the files found, by default it prints the name of the files. The GNU find command is installed on every Ubuntu system. This page is complemented by the manual('man') page for find which can be read by issuing the command "man find". (See Self:BasicCommands for a quick introduction to the command line)
The Basics
The general syntax for using finds is:
find [-H] [-L] [-P] [path...] [expression]
We will ignore the options [-H] [-L] [-P] for now , please refer to man find to learn their meaning, and start with the [path...]. find search a directory and its subdirectories, before any expression you should specify the directory or the directories where find will start searching
find . # search within the current directory find /home/user1 /home/user2 #search within the directories home/user1 /home/user2 find # same as find . , by default GNU find uses the current directory if no path is specified
The above commands will print the names of all the files present in the hierarchy below the starting directories passed to find as arguments. "files" can be link, directories, hidden files ...
Searching Files With A Specific Name
Of course, find would just be a poor version of ls without the [expression] part, let's start by the most common and perhaps most simple example:
find dir -name 'myfile'
The test -name 'name' will only search for an exact match of the name. This means that the above command will find, in the directory dir, a file named "myfile" but not a file named "myfile.txt" or "thisismyfile". If you are looking for a file with "myfile" in the name somewhere, you should instead use the following:
find dir -name '*myfile*'
Here, the * is a wildcard, and can stand for any number of characters (number, letter, space...). It is a basic form of a pattern. See the find manual page for more on patterns. The most important thing here is: Do not forget to put quotes around your pattern. If the pattern is not quoted, it will be replace by the shell by the list of files matching the pattern in the current directory. For example, if your current directory contains the file mytestfile and the directory myfiles, and the myfiles directory that has the file test.txt.
$ ls myfiles mytestfile $ ls myfiles/ test.txt
and we run the above find command
$ find . -name *test* #<-- wrong ./mytestfile
Not exactly what we expected. What has happened is the shell (Command Line Interface program) has interpreted *test* and matched it to mytestfile. mytestfile is what the shell passed as an argument to the find command. We need to stop the shell interpreting *test* before passing it to find. We do this by putting single quotes (') around the pattern. You might have used an unquoted pattern before and it was working, this is because if the pattern doesn't match anything in the current directory the shell leaves the pattern unchanged. Of course it's better not to rely on what might or might not be in the current directory..
Searching Files With A Specific Size
This parts needs expansion.
- -size: the size of the file such as : 600M for a 600 megabytes file. You can also specify a minimum size by adding a + in front of the size. Like so: +600M will find files of 600 or more megabytes.
Acting On The files
This parts needs expansion.
- -exec: This is used to execute a command to the filenames found. Use {} to substitute the filename and \; to end the command Ex: find ./ -name test.txt -exec ls -l {} \;
Advanced Usage
You can combine several Expressions, for instance if you want to find the files whose names contains both "dylan" and ogg you can do:
find . -name '*dylan*' -name '*ogg*'
There is an implicit and between the arguments. If you want to find the files whose names contains "dylan" or "elvis" you can do:
find . -name '*dylan*' -o -name '*elvis*'