bash, being a shell , has 2 threads , you can redirect this output: stdout and stderr, because this output needs to be redirected somewhere, linux has a specific "drop all" node to / dev / null . Everything that you send there will simply disappear into the void.
(the shells also have an input stream, but I will ignore it here since you asked to suppress the output)
These streams are represented by numbers: 1 for stdout and 2 for stderr.
So, if you only want to redirect stdout, you would do it with the < and > operators (basically where it points to where the data goes)
Suppose we want to suppress stdout (redirecting to / dev / null):
psql db -f sql.sql > /dev/null
As you can see, this is stdout by default, the stream number is not used if you want to use the stream number that you write
psql db -f sql.sql 1> /dev/null
Now, if you want to suppress stderror (thread number 2), you should use
psql db -f sql.sql 2> /dev/null
You can also redirect one thread to another, for example stderror to stdout, which is useful if you want to keep all the outputs somewhere regular and errors.
psql db -f sql.sql 2>&1 > log.txt
remember that between 2>&1
there should be no spaces
Finally, and sometimes the most interesting is the fact that you can suppress all output with &> , because when you want it to be โcompletely silentโ
psql db -f sql.sql &> /dev/null