Alex Rivera | Logout

Using an alias in find -exec

Asked 2011-10-04T20:07:53.173
27

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 to execute this alias using find -exec

find . -exec foo '{}' \;

but find cannot find foo:

find: foo: No such file or directory

Is it possible to use an alias in find?

Edit
Report

1 Answer

12

Nope, find doesn't know anything about your aliases. Aliases are not like environment variables in that they aren't "inherited" by child processes.

You can create a shell script with the same commands, set +x permissions and have it in your path. This will work with find.

answered 2011-10-04T20:14:23.980

Your Answer