个人工具
登录
查看“UbuntuHelp:Find”的源代码 - Ubuntu中文
UbuntuHelp
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“UbuntuHelp:Find”的源代码
来自Ubuntu中文
←
UbuntuHelp:Find
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{From|https://help.ubuntu.com/community/find}} {{Languages|UbuntuHelp:find}} <<Include(Tag/StyleCleanup)>> <<Include(Tag/NeedsExpansion)>> == 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 [[UbuntuHelp:BasicCommands|BasicCommands]] for a quick introduction to the command line) == The Basics == The general syntax for using finds is: <pre><nowiki> find [-H] [-L] [-P] [path...] [expression]</nowiki></pre> 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 <pre><nowiki> 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</nowiki></pre> 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: <pre><nowiki> find dir -name 'myfile' </nowiki></pre> 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: <pre><nowiki> find dir -name '*myfile*' </nowiki></pre> 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. <pre><nowiki> $ ls myfiles mytestfile $ ls myfiles/ test.txt</nowiki></pre> and we run the above find command <pre><nowiki> $ find . -name *test* #<-- wrong ./mytestfile</nowiki></pre> 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: <pre><nowiki> find . -name '*dylan*' -name '*ogg*'</nowiki></pre> There is an implicit and between the arguments. If you want to find the files whose names contains "dylan" or "elvis" you can do: <pre><nowiki> find . -name '*dylan*' -o -name '*elvis*'</nowiki></pre> To search the files related to some specific user name you can do: <pre><nowiki> find . / -user "root"</nowiki></pre> ---- [[category:CategoryCommandLine]] [[category:UbuntuHelp]]
该页面使用的模板:
模板:From
(
查看源代码
)
模板:Languages
(
查看源代码
)(受保护)
模板:Languages/Lang
(
查看源代码
)(受保护)
返回至
UbuntuHelp:Find
。