Using an alias in find -exec

前端 未结 7 681
醉酒成梦
醉酒成梦 2021-01-07 19:11

I have a very long command in bash, which I do not want to type all the time, so I put an alias in my .profile

alias foo=\'...\'

Now I want

7条回答
  •  失恋的感觉
    2021-01-07 19:57

    You can use the variable instead.

    So instead of:

    alias foo="echo test"
    

    use:

    foo="echo test"
    

    then execute it either by command substitution or eval, for instance:

    find . -type f -exec sh -c "eval $foo" \;
    

    or:

    find . -type f -exec sh -c "echo `$foo`" \;
    

    Here is real example which is finding all non-binary files:

    IS_BINARY='import sys; sys.exit(not b"\x00" in open(sys.argv[1], "rb").read())'
    find . -type f -exec bash -c "python -c '$IS_BINARY' {} || echo {}" \;
    

提交回复
热议问题