Question

Is there a possibility to do command substitution in a regex? I want to find files in Linux with specific names. The name may include fix strings, but it may also only include the hostname. So what i want to do is something like:

find /home/ -type f -regextype posix-extended -regex '.*(string1|string2|`hostname`).*'

I'm not sure whether it's possible to somehow concat the output of the hostname command with the regex? Thanks in advance!

Was it helpful?

Solution

Try this :

find /home/ -type f -regextype posix-extended -regex ".*(string1|string2|$HOSTNAME).*"

if you need to use a command instead :

find /home/ -type f -regextype posix-extended -regex ".*(string1|string2|$(hostname)).*"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top