What is /dev/null 2>&1?

>> /dev/null redirects standard output (stdout) to /dev/null, which discards it. (The >> seems sort of superfluous, since >> means append while > means truncate and write, and either appending to or writing to /dev/null has the same net effect. I usually just use > for that reason.) 2>&1 redirects standard error (2) to standard … Read more

How to pass password to scp?

Use sshpass: sshpass -p “password” scp -r user@example.com:/some/remote/path /some/local/path or so the password does not show in the bash history sshpass -f “/path/to/passwordfile” scp -r user@example.com:/some/remote/path /some/local/path The above copies contents of path from the remote host to your local. Install : ubuntu/debian apt install sshpass centos/fedora yum install sshpass mac w/ macports port install … Read more

How do I use sudo to redirect output to a location I don’t have permission to write to? [closed]

Your command does not work because the redirection is performed by your shell which does not have the permission to write to /root/test.out. The redirection of the output is not performed by sudo. There are multiple solutions: Run a shell with sudo and give the command to it by using the -c option: sudo sh … Read more

How to redirect and append both standard output and standard error to a file with Bash

cmd >>file.txt 2>&1 Bash executes the redirects from left to right as follows: >>file.txt: Open file.txt in append mode and redirect stdout there. 2>&1: Redirect stderr to “where stdout is currently going”. In this case, that is a file opened in append mode. In other words, the &1 reuses the file descriptor which stdout currently … Read more