How can I make the "find" Command on OS X default to the current directory?
If you must call it 'find', then you want:
alias find=/usr/bin/find\ .
in your .profile or .bash_profile or …. Substitute the real path (if not /usr/bin/find) on your Mac OSX. Enter the full path to avoid cycles (bash normally would interpret alias find=find
without issues, but better be sure).
But you better not name the alias find
(findl, myfind etc), because it will become a habit and trouble for you if you try it on another system.
Install GNU find instead.
$ brew install findutils
$ alias find=gfind
Yay, it works!
find ./ -name "*.plist"
edit: hmm, i may have misunderstood the question! if you were crazy, how about emulating it via a shell script? i routinely keep random utility scripts in ~/.bin, and that's the first thing in my PATH. if you had a similar setup perhaps you could do something like: (untested!)
#!/bin/sh
# remapping find!
CMD=`echo $1 | cut -c 1`
if [ $CMD = '-' ]
then
# pwd search
/usr/bin/find ./ $*
else
# regular find
/usr/bin/find $*
fi
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.