How can I make the “find” Command on OS X default to the current directory?

后端 未结 7 1646
长情又很酷
长情又很酷 2021-02-13 07:43

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 l

相关标签:
7条回答
  • 2021-02-13 07:53

    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.

    0 讨论(0)
  • 2021-02-13 07:53

    This is probably not what you want but how about: alias find="find ."

    or choose a new name (findl for find local?)

    0 讨论(0)
  • 2021-02-13 07:54

    Install GNU find instead.

    $ brew install findutils
    $ alias find=gfind
    

    Yay, it works!

    0 讨论(0)
  • 2021-02-13 07:58

    I would suggest that if you're writing scripts (which are more likely to be migrated from one system to another sometime in the future) that you should try to use the more specific form of the command, that is specifying the "." instead of relying on a default. For the same reason, I might even suggest writing sh scripts instead of relying on bash which might not be installed everywhere.

    0 讨论(0)
  • 2021-02-13 08:01
    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
    
    0 讨论(0)
  • 2021-02-13 08:08

    You may want to run the commands found in this link: https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/

    It is a bit outdated, for example I found I did not have to add many commands to my path at all.

    This covers your problem by having your system use the Non-BSD find utility from the findutils package, while also installing other tools you may want as well.

    0 讨论(0)
提交回复
热议问题