General

Utilities that can always be useful in different contexts.

Info Commands

apropos <STRING>
man <COMMAND>

Terminal

Command
Description

CTRL + ALT + T

Open terminal window

CTRL + SHIFT + T

New tabs

CTRL + SHIFT + W

Close tabs

ALT + <NUM_TAB>

Move between the tabs

Vim

Command
Description

:q!

Quit without saving

:wq

Save and quit

:w !sudo tee %

Save and quit when you forgot sudo

i

Insert mode before the cursor

a

Insert mode after the cursor

A

Insert mode at the end of the line

o

Add line above and Insert mode

O

Add line below and Insert mode

v

Visual mode

V

Select line and Visual mode

x

Delete character under cursor

dd

Delete line

r

Change one character under cursor

R

Change mode

u

Undo

CTRL + r

Redo

y " <REG> y

Copy Specific registers (+ or * for outside of vim)

p " <REG> p

Paste Specific registers (+ or * for outside of vim)

Tmux

Command
Description

tmux

New session

tmux ls

List sessions

tmux new -s <NAME>

New session <NAME>

tmux kill-ses -t <NAME>

Delete session <NAME>

tmux kill-session

Delete all session

CTRL + b d

Detach from session

tmux a -t <NAME>

Attach to a session <NAME>

Search & Filter

Search File

sudo updatedb
locate <FILE>
which <FILE>
find <PathStart> -type <f/d> -name <NAME> 2>/dev/null

Search String

grep -rHin "<STRING>" <PathStart>

Filter

<COMMAND> | grep <STRING>
Grep Options
Description

-i

Case Insensitive

-v

Not contain

-A <N>

Also show the two lines below

-B <N>

Also show the two lines above

-l

View File Name

-o

View Content

Manipulation

Command
Description

<COMMAND> | cut -f <N> -d "<SEP>"

Split the output by single character <SEP> and return field <N>

<COMMAND> | awk -F “<SEP>” '{print $<N1>, $<N2>}'

Split the output by characters <SEP> and return field <N1> and <N2>

<COMMAND> | tr "X" ”Y”

Replaces certain characters X with others Y.

<COMMAND> | sort -u

Sort and Unique

<COMMAND> | wc -w -l -c

Word/Line/Char count

<COMMAND> | rev

Reverse String

<COMMAND> | tac

Print in Reverse, starting from the last lines

Regex

Regex
Description

<START>.+?<END>

Between <START> and <END> including them

<START>(.+?)<END>

RBetween <START> and <END> excluding them

<START>([^<END>]*)

Between <START> and one of the characters in <END>

+

At least 1 character

*

Even without

Encoding

Only alphanumeric characters and + /. Multiples of 4 with padding =.

Encode

<COMMAND> | base64

Decode

<COMMAND> | base64 -d

Extract

extract.sh
function extract {
  if [ -z "$1" ]; then
    echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
  else
    if [ -f $1 ]; then
      case $1 in
        *.tar.bz2)   tar xvjf $1    ;;
        *.tar.gz)    tar xvzf $1    ;;
        *.tar.xz)    tar xvJf $1    ;;
        *.lzma)      unlzma $1      ;;
        *.bz2)       bunzip2 $1     ;;
        *.rar)       unrar x -ad $1 ;;
        *.gz)        gunzip $1      ;;
        *.tar)       tar xvf $1     ;;
        *.tbz2)      tar xvjf $1    ;;
        *.tgz)       tar xvzf $1    ;;
        *.zip)       unzip $1       ;;
        *.Z)         uncompress $1  ;;
        *.7z)        7z x $1        ;;
        *.xz)        unxz $1        ;;
        *.exe)       cabextract $1  ;;
        *)           echo "extract: '$1' - unknown archive method" ;;
      esac
    else
      echo "$1 - file does not exist"
    fi
  fi
}
extract.sh <FILE>

Cross-Compiling

C

sudo apt-get install gcc 
apt-get install gcc-multilib 
apt-get install g++-multilib
gcc <FILE.c> -o <NEW_NAME>  # 64 bit
gcc <FILE.c> -m32 -o <NEW-NAME>  # 32 bit
chmod +x <NEW_NAME>

Python

python3 <FILE.py>

SO

gcc -fPIC -shared -o <LIB_NAME.so> <FILE.c>

TOR

Start service TOR

sudo service tor start
sudo service tor stop
sudo service tor restart

Set ProxyChains

vim /etc/proxychains4.conf
vim /etc/proxychains.conf
# at the end
socks4 127.0.0.1 9050
socks5 127.0.0.1 9050

Use command over TOR

proxychains <COMMAND>

GIT

Description
Command

Access by token

Create tokens in Settings/Developer > Settings/Personal > access > token Insert token git clone https://<USERNAME>:<TOKEN>@github.com/<USERNAME>/<REPOSITORY> Or git remote set-url origin https://<USERNAME>:<TOKEN>@github.com/<USERNAME>/<REPOSITORY>

Downloading GitHub repositories

git clone <LINK_REPOSITORY_GITHUB>

Download repository changes

git pull origin main

Loading repository changes

git commit -m "<DESCRIPTION>" git push origin main

Docker

sudo systemctl start docker
sudo systemctl stop docker

Manages single containere. dockerfile

Command
Description

docker build -t <name> .

docker --version

Docker version

docker search <STRING>

Search in the Docker Hub

docker login <DOMAIN>/<IMG_NAME>

It may require authentication if you are pulling unofficial images, so you need to authenticate for that domain and image first. See a domain's registry list at <DOMAIN>/v2/_catalog.

docker pull <IMG_NAME>[:<VERSION>]

Download image from Docker Hub

docker inspect <IMG_NAME>

View information about the Docker image.

docker image

View possible commands for managing Docker images, such as ls

docker volume

View possible commands for managing Docker volumes, such as ls

docker volume create <VOLUME_NAME>

Create a volume and give it a name. They are used to store data persistently.

docker network

View possible commands for managing Docker network, such as ls

docker network create (…) <NETWORK_NAME>

Creating a network. It is important to specify: --driver=bridge : Specify the type of driver --subnet=<ip/mask> : Specify the subnet to be used by the container (ex. 172.18. 0.0/16) --gateway=<ip/mask> : Specify the gateway to communicate outside the container (ex. typically 172.18. 0.1)

docker run <IMG_NAME>

Runs a container from a specified Docker image. --name=<NAME> : Give a name to the container. -d : Run the container in the background. -p <H_PORT>:<C_PORT> : Perform port mapping. connect my H port to the C container port. -v <VOLUME_NAME>:<C_PATH> : Use a volume. Associate a created volume with a container PATH. -v <H_PATH>:<C_PATH> : Use a volume. Associate a PATH on the HOST system with a container PATH. --network=<NETWORK_NAME> : Start the container on a previously created network -h <HOSTNAME> : Specify hostname

docker run -it <IMG_NAME> bash

Start container but in interactive mode, connect to the container terminal. CTRL+P and CTRL+Q : Exit from the container while leaving it running.

docker attach <ID>

Resume interaction with a container.

docker exec -it <ID_CONTAINER> bash

Runs a new interaction process with a container's terminal (also used to reconnect after exiting, like attach).

docker ps

Show running containers. -a : Also show stopped containers (if you want to remove them).

docker top <ID_CONTAINER>

View the processes running inside a container.

docker logs <ID_CONTAINER>

View logs of a container.

docker stat <ID_CONTAINER>

Provides real-time information about the resources used by a container.

docker stop <ID_CONTAINER>

Stops a running container.

docker start <ID_CONTAINER>

Run a stopped container.

docker rm <ID_CONTAINER>

Remove and delete a container.

docker container prune

Remove all stopped containers.

docker history <IMG_NAME>

View history of operations related to a Docker image.

docker system prune

Complete cleaning of everything, be careful! (does not delete images)

docker save -o <NAME>.tar <IMG_NAME>

Save a Docker image, including all its layers and metadata.

With ls -q it prints only the IDs.

Last updated