Linux tricks and tips!

Automate workflows with entr

This is one of my favorites. entr tool provides a separation-of-concerns style method of automating arbitrary commands when s or directory changes.


    # Auto-compile or install your software project any time you update the code:
    ag -l | entr -p ./ install
    find . -iname "*.py" | entr -p ./ install

    ag -l | make install

    # Same thing is possible to e.g. run your test suite

Bash leave no command history

Sometimes it's helpful to not pollute your .bash_command history. You will lose the functionality of up-arrows to view previous command and any sort of saving the commands, however. Only known to work in BASH.

    How to leave no .bash_history

    : > ~/.bash_history # truncates history file
    kill -9$$           # kills pid of current shell


    unset HISTFILE
    set +o history
    history -c

ltrace wrapper

This is another sweet one. Sometimes you want to debug a binary, and watch what sort of system calls and/or library calls. The way you use this is create a new file, or copied below and edit to run the file you want to run at the bottom. Open two terminals, we want two windows to see the program on one side and the system/library calls on the other. First, run the and it will give you a PID. Second, run strace -p $PID in the other terminal. Finally, on the first terminal where thhe program is running hit enter to continue program. You will see the syscalls in the case of strace (may require root) or library calls to shared libraries in the case of ltrace. You can also use the file variable so you don't have to type the PID every time you run it.


    # the pid could be sent to a file or named pipe the-thing-that-does-
    # strace could be watching, though in most cases a human could copy it
    echo "PID to strace is $$"
    echo "$$" > /tmp/

    trap : USR2

    # block while human copies pid over to strace (or some program acts on
    # the above pid being written in that other terminal). Busy loop or
    # something instead if this program must not consume input (`sleep`
    # complicates the signal handling)
    read blocking

    # then when strace is up, send this process a USR2 signal. this will
    # mean there will be some strace of this script in addition to the
    # target, hence the kinda sorta caveat.


Making HTTP and HTTPS requests manually

    Making HTTP and HTTPS requests manually


    GET / HTTP/1.1<shift-enter to go to newline without sending>

    openssl s_client -connect

    GET / HTTP/1.1<shift-enter to go to newline without sending>

Execute python code on remote computer (Linux or ssh-server supporting only)

    Execute Python on Remote
    cat <file>.py | ssh python -