Linux tricks that quickly boost everyday efficiency
The shell calculator bc can compute hexadecimal directly
1
echo'ibase=16;C06D1000-C06A5E78' | bc
Chatting and transferring files with netcat
The side that sets up the listening port first is the server. For chatting, who is the server doesn’t matter. But if you want to send a file from server A to server B,
you must listen on a port on server B, then connect and send from server A.
Chatting
Server
1
nc -l -p 9999 # listen on port 9999 with Netcat
Client
1
nc 127.0.0.1 9999 # connect to port 9999
Sending and receiving files
Server
1
nc -l -p 9999 > android.tar.gz
Client
1 2 3 4
nc -c <IP> 9999 < android.tar.gz
# The -c parameter: without it, neither side closes the connection after the file transfer completes # -c, --close close connection on EOF from stdin
Quick code debugging with && and pipes
This is a little trick I used when solving algorithm problems and in interviews. Sharing it here in case it helps.
The whole line has two parts: first compile with g++ game1.cpp -o game1,
then pipe the contents of input1.txt as standard input. For convenient testing,
I’ll paste my program and data here.
The command below pastes the entire text.txt file to the clipboard directly from the command line. It’s another favorite of mine when solving problems and during coding tests —
combined with Vim and the quick debugging method above, things get really easy.