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?
To see a list of aliases set up on your linux box, just type alias at the prompt. You can see there are a few already set up on a default Redhat 9 installation. To remove an alias, use the unalias command.
To view the alias for a particular name, enter the command alias followed by the name of the alias. Most Linux distributions define at least some aliases. Enter an alias command to see which aliases are in effect. You can delete the aliases you do not want from the appropriate startup file.
Definition of alias : otherwise called : otherwise known as —used to indicate an additional name that a person (such as a criminal) sometimes uses John Smith alias Richard Jones was identified as the suspect.
find
itself doesn't know anything about aliases, but your shell does. If you are using a recent enough version of bash
(I think 4.0 added this feature), you can use find . -exec ${BASH_ALIASES[foo]} {} \;
to insert the literal content of the alias at that point in the command line.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With