bash

Search a file or directory with regex:

find . -iname "string to search*"

-iname for a case-insensitive search.

Search a string inside files recursively:

grep -rni "string" ./

-n gives line number and -i case insensitive

Count the number of entries (files and directories, no hidden) in a directory:

ls -1 | wc -l

the -1 (warning: not an “l”) removes the . and .. directories, giving the actual number of entries.

git

ssh keys

Generate a key with a custom name mykey and without passphrase (just issue enter two times):

ssh-keygen

copy the public key into your remote provider (e.g. github.com has a section in the repo’s settings). Then you can clone it as:

GIT_SSH_COMMAND="ssh -i ~/.ssh/mykey" git clone git@github.com:user/repo.git

git is always the user. This can be used for all other commands that exchange data with remote, such as pull, push etc.

Note: with an already cloned repo, the latter commands works only when the ssh clone was used (no https).

To avoid the enviromental variable, configure:

$ cat ~/.ssh/config

Host github.com
        HostName github.com
        User git
        IdentityFile ~/.ssh/mykey
        IdentitiesOnly yes

note that mykey is the private key.

Compilation

rpath

Search runpath (default path for dynamically linked libraries)

readelf -d <exe> | grep -i runpath

binary comparison

cmp file1 file2

tmux

Split

Ctrl + b, 
  • % split vertically
  • " split horizontally
  • ← ↑ → ↓ to change focus
  • x close

abc

Create:

tmux

To detach: ctrl + b, then (without ctrl pressed) d

Tmux has a conda-like cli, follow the suggestions to use it.

creare una sessione tmux condivisa

  1. nel proprio terminale, definire un socket di comunicazione con:
     tmux -S $HOME/mytmux
    
  2. modificare l’Access Control List (ACL) del socket appena creato usando:
     setfacl -m u:<user>:xwr $HOME/mytmux
    

    dove -m specifica che l’utente <user> gli vengono dati i permessi di esecuzione, scrittura e lettura sul socket.

screen

To be executed while keeping ctrl pressed.

Detach from session: ctrl + a, ctrl + d

profiling

Save a plot from a .prof

Requires uv and graphviz installed:

uvx gprof2dot -f pstats FILE.prof | dot -Tpng -o ./FILE.png