我遇到了bash中find命令的問題。 我試圖找到以.c結尾且文件大小超過2000字節的文件。我認爲它會是:查找超過特定文件大小的特定擴展名的文件
find $HOME -type f -size +2000c .c$
但顯然這是不正確的。
我在做什麼錯?
我遇到了bash中find命令的問題。 我試圖找到以.c結尾且文件大小超過2000字節的文件。我認爲它會是:查找超過特定文件大小的特定擴展名的文件
find $HOME -type f -size +2000c .c$
但顯然這是不正確的。
我在做什麼錯?
find $HOME -type f -name "*.c" -size +2000c
看一看到-name
開關的鬃毛頁:
-name pattern
Base of file name (the path with the leading directories
removed) matches shell pattern pattern. The metacharacters
(`*', `?', and `[]') match a `.' at the start of the base name
(this is a change in findutils-4.2.2; see section STANDARDS CON‐
FORMANCE below). To ignore a directory and the files under it,
use -prune; see an example in the description of -path. Braces
are not recognised as being special, despite the fact that some
shells including Bash imbue braces with a special meaning in
shell patterns. The filename matching is performed with the use
of the fnmatch(3) library function. Don't forget to enclose
the pattern in quotes in order to protect it from expansion by
the shell.
注意最後的建議,總是內部封閉模式引號。選項的順序不相關。曾經,再次,一看手冊頁:
EXPRESSIONS
The expression is made up of options (which affect overall operation
rather than the processing of a specific file, and always return true),
tests (which return a true or false value), and actions (which have
side effects and return a true or false value), all separated by opera‐
tors. -and is assumed where the operator is omitted.
If the expression contains no actions other than -prune, -print is per‐
formed on all files for which the expression is true.
所以,選項,默認情況下,與和-and
運營商連接:他們已經是所有真正爲了找到一個文件和順序沒有按」根本不重要。該命令可能僅適用於比-and
其他運算符更復雜的模式匹配。
試試這個:
find $HOME -type f -size +2000c -name *.c
嘗試以下操作:
find $HOME -type f -size +2000c -name *.c
謝謝你,順便說一句,沒有命令的順序重要的發現聲明。如果我想要,可以輸入find $ HOME -name「* c」-type f -size + 2000c嗎? – Unknown
用於引用glob。 – l0b0
@BernieMacinflor,不要害怕man page。用你評論的答案編輯答案。 ;) – Zagorax