echo 2>/dev/null with a find command help

Why does this not work?

echo 'find / -iname \'*katt*\' -size +500M 2>/dev/null'

How does this work? I have 5 single quotes. I though you needed an even amount of single quotes.

echo 'find / -iname \'*katt*\' -size +500M 2>/dev/null''

What is the trick to make it work with an alias? This won't work.

alias findnamesize="echo 'find / -iname \'*katt*\' -size +500M 2>/dev/null''"

Because the \ escape does not work within single quotes. Try:

echo "find / -iname '*katt*' -size +500M 2>/dev/null"

Should you want to stick with single quotes for the external ones, you can use that syntax:

echo 'find / -iname '"'"'*katt*'"'"' -size +500M 2>/dev/null'

@cokedude
When you post code which does not work, please provide sample input and sample expected output making the process specification emphatically clear.
Please also post what Operating System and version you are running and what Shell you are using.

It is unlikely than an optimum solution to your problem would involve the alias command.

Ps. I do wonder sometimes why do you persist in trying to use alias for complex commands when you should be using proper Shell Scripts?
Imho. If the alias command was deleted from all Shells it would be no great loss.

Did you know? You can modify the ${PATH} environment variable to include your scripts directory:
e.g.

PATH="${PATH}:/home/myuser/myscripts";export PATH

Then you can use the name of your script as if it was a command and avoid using aliases.

Or you can define functions instead of aliases...

findnamesize() { find / -iname '*katt*' -size +500M 2>/dev/null ;}

There is no reason to use aliases anymore..

1 Like