我怎样才能使“查找” OS X上的命令默认为当前目录? [英] How can I make the "find" Command on OS X default to the current directory?
问题描述
我是一个繁重的命令行用户,在构建系统脚本中广泛使用 find
命令。然而,在Mac OS X上,当我不集中时,我经常得到这样的输出:
$ find -name \ * .plist
查找:非法选项 - n
查找:非法选项 - a
查找:非法选项 - m
查找:非法选项 - e
查找: * .plist:没有这样的文件或目录
基本上,我忘了添加小点: p>
$ find。 -name \ * .plist
因为BSD find
需要路径,GNU find
不会(如果不指定,它会假设当前目录)。我经常同时使用Linux,Mac OS X和Cygwin,所以我的所有工具的行为都是一样的。我试着写了一个bash find
函数,如果我忘了添加了./,但是我失败了。谢谢你的帮助。如果你不能自律来使用 find
'正确',那么为什么不把GNU find
(来自 findutils
)安装在系统之前的PATH目录中 find
命令。
我曾经拥有自己的私有变体 cp
如果列表中的最后一项不是目录,则会将文件复制到当前目录。我把它保存在我的个人 bin
目录中很多年了 - 但是最终删除了它,因为我不再使用这个功能。 (我的'cp.sh'是1987年编写的,在1990年和1997年编辑了两次,作为版本控制系统符号变化的一部分,我想我在1998年左右删除了它。脚本的主要问题是 file1 file2
在将文件复制到另一个文件和将两个文件复制到当前目录之间是不明确的。)
考虑编写自己的包装器to find
:
#!/ bin / sh
[! -d$ 1]&&设置 - 。 $ @
exec / usr / bin / find$ @
行说:如果参数1不是一个目录,然后调整命令行参数,包括在命令的其余部分之前的点。这将是混淆,如果您输入:
〜/ bin / find / non-existent / directory -name'* .plist'-print
,因为不存在的目录不是目录,脚本会在命令行中添加点 - 我停止使用我的私有 cp的原因
命令。
I am a heavy command line user and use the find
command extensively in my build system scripts. However on Mac OS X when I am not concentrating I often get output like this:
$ find -name \*.plist
find: illegal option -- n
find: illegal option -- a
find: illegal option -- m
find: illegal option -- e
find: *.plist: No such file or directory
Basically, I forgot to add the little dot:
$ find . -name \*.plist
Because BSD find
requires the path and GNU find
doesn't (it assumes the current directory if you don't specify one). I use Linux, Mac OS X and Cygwin often all at the same time, so it's of great benefit to me to have all my tools behave the same. I tried writing a bash find
function that added "./" if I forgot, but I failed. Thanks for your help. :)
If you can't discipline yourself to use find
'correctly', then why not install GNU find
(from findutils
) in a directory on your PATH ahead of the system find
command.
I used to have my own private variant of cp
that would copy files to the current directory if the last item in the list was not a directory. I kept that in my personal bin
directory for many years - but eventually removed it because I no longer used the functionality. (My 'cp.sh' was written in 1987 and edited twice, in 1990 and 1997, as part of changes to version control system notations. I think I removed it around 1998. The primary problem with the script is that cp file1 file2
is ambiguous between copying a file over another and copying two files to the current directory.)
Consider writing your own wrapper to find
:
#!/bin/sh
[ ! -d "$1" ] && set -- . "$@"
exec /usr/bin/find "$@"
The second line says "if argument 1 is not a directory, then adjust the command line arguments to include dot ahead of the rest of the command. That will be confusing if you ever type:
~/bin/find /non-existent/directory -name '*.plist' -print
because the non-existent directory isn't a directory and the script will add dot to the command line -- the sort of reason that I stopped using my private cp
command.
这篇关于我怎样才能使“查找” OS X上的命令默认为当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!