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 GNUfind(fromfindutils) in a directory on your PATH ahead of the systemfindcommand.I used to have my own private variant of
cpthat would copy files to the current directory if the last item in the list was not a directory. I kept that in my personalbindirectory 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 thatcp file1 file2is ambiguous between copying a file over another and copying two files to the current directory.)Consider writing your own wrapper to
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:
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
cpcommand.