我一直在整个谷歌中寻找此类命令的解释
find /tmp -name core -type f -print | xargs /bin/rm -f
嗯,我从网络本身得到了这个命令,并且那里也提到了解释。现在我知道这个命令用于在名为“tmp”的目录中查找名为“core”的文件并删除该文件。我已经使用并检查过它,它工作得很好。
我的问题是我无法理解此命令中使用的术语,例如 -type f 和 xargs 的作用是什么? 还如何根据我们的需要生成这样的命令(除非正确理解,否则显然不能),最大的问题是在谷歌中写什么来获得有关这方面的帮助......我的意思是在什么主题下我可以期待这些。
请帮忙
问候。
最佳答案
这是一串unix命令:
find // name of command (in this case, "find")
arguments to 'find':
/tmp // where to look
-name core // name to look for, "core" (optional argument)
-type f // files only (not, eg, directories or files contents)
// (optional argument)
-print // output the list to standard output (STDOUT)
| // name of command (otherwise known as
// 'pipe') this is a little program that
// takes the output from a previous process
// (in this case, the output from 'find')
// and pass it to another process as input
xargs // name of command ('xargs') the program
// that will accept the output from 'print'
// as input (directed by 'pipe'). It provides
// a robust way to process indefinitely
// long lists by breaking them into smaller
// lists and passing each sublist through
// to its command argument
/bin/rm // name of command for xargs to execute
// on its input list ('rm' = remove)
-f // argument to rm, only remove files, not directories.
这就是 UNIX 的工作原理,它由许多小型的单一用途程序组成,这些程序具有晦涩的 2 个字母名称,专门用于单个任务。您将它们串在一起以完成更复杂的任务。
找出任何一个命令的作用的正确方法是使用“man”命令并将相关命令名称作为参数,例如
man find
man xargs
man rm
您将获得描述每个输入选项和输出可能性的详细信息页面。像“xargs”这样的名称也很容易通过谷歌搜索,但可以理解的是“find”却不容易(也许尝试“unix find”)。他们中的许多人都有维基百科页面...
也许你应该好好了解一下 unix 指南...
关于linux - 请解释一下linux命令: find/tmp -name core -type f -print | xargs/bin/rm -f,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14248516/