How can we redirect both stdin and stderr in shorter way? please correct me if the below method is wrong. Also suggest me any other way to do it at once.
command <file1.txt 2>file2.txt
If you really mean stdin
and stderr
I don't think there's a "shorter way"; even if there was some syntax sugar for this (quite unlikely), your example shows that you want to make use of different files, so you should explicitly specify each redirection anyhow...
However, for stdout
and stderr
(if you want those redirected to the same file), you can type:
command &> file.txt
The way you're doing it is correct. You can't redirect both stdin and stderr to the same file. You can redirect stdout and stderr to the same file, though:
command >file.txt 2>&1
There really isn't a "shorter" way per se (I assume by shorter you mean fewer characters) .
However, as an alternative you could use:
cat file1.txt | command 2> file2.txt