Useful for "living off the land" techniques or in scripts:
timeout 1 bash -c "cat /dev/null > /dev/tcp/google.com/80"
echo $? # 0 = OK
TLDR: run the command "cat /dev/null > /dev/tcp/google.com/80" which uses linux's TCP device files and wait for 1 second. If the TCP connection is successful, exit code will be 0
Uwrapping the above command from the end:
/dev/tcp/google.com/80
: we're using linux's inbuilt TCP/IP dev filescat /dev/null > /dev/tcp/google.com/80
: sending "null" to this endpoint (google.com, port 80)cat
command to completetimeout
, it's easier to wrap the command with inverted commas (to avoid redirecting the output of "timeout" itself by mistake), and feed it into bash -c
which accepts string commands and feeds them to bashecho $?
outputs the previous command's exit code. In this case, 0 will mean TCP connection was successful, and otherwise a non-zero exit code is returnedLinux "mount" command takes the "bind" argument:
mount --bind /source/dir /dest/dir
this essentially creates a shortcut (similar to a symlink created with "ln"), however rather than a "link" the shortcut can be viewed more as a "gateway" and is hence stronger than a symlink
It's useful in situation where operations in a symlink target throw errors referencing the original location (e.g. some compilation pipelines, or SNAP packages). In this case, replace the symlink with a bind mount