General
Utilities that can always be useful in different contexts.
Info Commands
apropos <STRING>man <COMMAND>help <COMMAND><COMMAND> ?
<COMMAND> /?Terminal
CTRL + ALT + T
Open terminal window
CTRL + SHIFT + T
New tabs
CTRL + SHIFT + W
Close tabs
ALT + <NUM_TAB>
Move between the tabs
CTRL + L
Clear screen
CTRL + SHIFT + C
Copy
CTRL + SHIFT + V
Paste
HOME or CTRL + A
Start line
END or CTRL + E
End line
ALT + <--
Go back one word
ALT + -->
Go forward one word
CTRL + D
Delete one character forward
CTRL + W
Delete one word back
ALT + D
Delete one word forward
CTRL + U
Delete to the start of the line
CTRL + K
Delete to the end of the line
CTRL + P
On Kali, change version of the terminal
CTRL + C
Open terminal window
CTRL + Z
jobs
fg <N>
bg <N>
Background process View background processes Resume <N> in the foreground Resume <N> in the background
CTRL + S
Pause output
CTRL + Q
Resume output
2>&1 : STDERR in STDOUT
0>&1 : STDIN in STDOUT
Vim
: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)
:s/<OLD>/<NEW>
:s/<OLD>/<NEW>/g :#,#s/<OLD>/<NEW>/g
:%s/<OLD>/<NEW>/g
:%s/<OLD>/<NEW>/gc
Replace the first <OLD> with <NEW> in the line Replace every <OLD> with <NEW> in the line Replace every <OLD> with <NEW> between the lines #,# Replace every <OLD> with <NEW> in the file Replace every <OLD> with <NEW> in the file, asking for confirm
:w <FILE>
Write the selected part or all to the file <FILE>
:r <FILE>
:r !<COMMAND>
Read the file <FILE> and inserts it Execute the command and inserts the output
:Explore [<DIR>]
Vim file explorer
Operator [Number] Movement
w- Word$- End of line0- Start of linee- End word
Tmux
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>
CTRL + b c
New window
CTRL + b ,
Rename window
CTRL + b n
Next window
CTRL + b p
Previous window
CTRL + b <N>
Select window <N>
CTRL + b w
List and Navigate in window
CTRL + b %
Split screen Vertically
CTRL + b "
Split screen Horizontally
CTRL + b <ARROW>
Move between screen split
CTRL + b <SPACE>
Change layout of the split
CTRL + b CTRL + <ARROW>
Resize current split
CTRL + b [
Copy mode
CTRL + b ]
Paste
g
Go top line
G
Go bottom line
w
Forward one word
b
Backward one word
/
Search forward (move with N and n)
?
Search backward (move with N and n)
<SPACE>
Start selection
<ENTER>
Copy selection
Search & Filter
Search File
sudo updatedb
locate <FILE>which <FILE>find <PathStart> -type <f/d> -name <NAME> 2>/dev/nullSearch String
grep -rHin "<STRING>" <PathStart>Filter
<COMMAND> | grep <STRING>-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
Search File
dir /s *<STRING>*Get-ChildItem -Path 'C:\' -Include *<STRING>*, *<STRING>* -Recurse -ErrorAction IgnoreSearch String
findstr /s /i <STRING> *.* # contain
findstr /s /i /v <STRING> *.* # not containGet-ChildItem -Path 'C:\' [-Include *<STRING>*, *<STRING>*] -Recurse -ErrorAction Ignore | Select-String -Pattern '<STRING_IN_FILE>' -ErrorAction IgnoreFilter
<COMMAND> | findstr <STRING><COMMAND> | select <ATTR1>,<ATTR2>Manipulation
<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
cat << EOF > /PATH/TO/FILE
Row 1
...
Row N
EOFRegex
<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
Encode special characters into URLs.
<COMMAND> | jq -sRr @uriUse:
echo -nbase64 -w 0Extract
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 mingw-w64x86_64-w64-mingw32-gcc <FILE.c> -o <NEW_NAME> # 64 bit
i686-w64-mingw32-gcc <FILE.c> -o <NEW_NAME> # 32 bitPython
pip installa pyinstallerpython pyinstaller.py --onefile <FILE.py>DLL
x86_64-w64-mingw32-gcc -shared <FILE.c> -o <NEW_NAME.dll> [-Wl,--out-implib,<NEW_NAME.a>] # 64 bit
i686-w64-mingw32-gcc -shared <FILE.c> -o <NEW_NAME.dll> [-Wl,--out-implib,<NEW_NAME.a>] # 32 bitEnvironment
python3 -m venv myEnv
source myEnv/bin/activatepip3 install NAME_PACKAGE
pip3 install -r requirements.txtdeactivate
rm -rf nome_ambientesource ~/miniconda3/bin/activateconda create -n myEnv python=3.11
conda activate myEnv
conda deactivateconda install NAME_PACKAGE
conda install -c conda-forge NAME_PACKAGE
conda list
conda remove NAME_PACKAGE conda env export > environment.yml
conda env create -f environment.ymlconda remove -n myEnv --all TOR
Start service TOR
sudo service tor start
sudo service tor stop
sudo service tor restartSet ProxyChains
vim /etc/proxychains4.conf
vim /etc/proxychains.conf# at the end
socks4 127.0.0.1 9050
socks5 127.0.0.1 9050Use command over TOR
proxychains <COMMAND>Routing all your system network traffic through the TOR network.
sudo zerotrace --start
sudo zerotrace --ip (Show current Tor IP and location)
sudo zerotrace --stop
sudo zerotrace --new-ip
sudo zerotrace --auto --time 300 (change IP every 5 minutes)
GIT
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 add -A]
git commit -m "<DESCRIPTION>"
git push origin [main/master]
With SSH
GIT_SSH_COMMAND='ssh [options]' [git command]
GIT_SSH_COMMAND='ssh [options]' git clone <USER>@<IP>:/<REPO>
ex.
GIT_SSH_COMMAND='ssh -i id_rsa -p 43022' git clone git@192.168.213.125:/git-server
GIT_SSH_COMMAND='ssh -i /id_rsa -p 43022' git push origin master
See commit
git log
See the differences in commit
git show <COMMIT_ID>
git show --all
List of branch
git branch
Switch to another branch
git switch <NAME_BRANCH>
git checkout <NAME_BRANCH>
Read single git files in objects/X/number
git cat-file -p Xnumber
Docker
sudo apt install docker.io && sudo apt install docker-compose
sudo usermod -aG docker $USERsudo systemctl start docker
sudo systemctl stop dockerManages single containere. dockerfile
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.
Orchestration of multi-container applications. docker-compose.yml
docker compose build
Builds or rebuilds Docker service images in docker-compose.yml. Required only if changes are made.
docker compose up
Creates and starts the containers listed in the docker-compose.yml file along with a custom network.
-d : Runs the container in the background.
docker compose start
Start the service containers defined in the docker-compose.yml file.
docker compose stop
Stop all containers listed in the docker-compose.yml file.
docker compose down
Stop and delete all containers listed in the docker-compose.yml file and the created network.
docker compose logs [<SERVICE_NAME>]
Display logs of started services.
-f : Follow. Listen and display logs continuously.
docker compose ps
View the status of Docker services managed by Docker Compose.
With ls -q it prints only the IDs.
Networks
Layer 2 Data Link : MAC address, Switch/bridge (Within Subnets)
Layer 3 Network : IP address, Router (Between Networks)
Layer 4 Transport : TCP/UDP
Enable/Disable interface
sudo ip link set dev <INTERFACE> up
sudo ip link set dev <INTERFACE> down
Riname Interface
ip link set dev <OLD> name <NEW>
Add/Remove IP
ip addr add <IP>/<MASK> dev <INTERFACE>
ip addr del <IP>/<MASK> dev <INTERFACE>
ip addr change <IP>/<MASK> dev <INTERFACE>
ip addr flush dev <INTERFACE>
Add/Remove Route
route -n
ip route show
ip route add <REMOTENET_IP>/<MASK> via <GATEWAY>
ip route add <REMOTENET_IP>/<MASK> dev <INTERFACE>
ip route del <REMOTENET_IP>/<MASK> via <GATEWAY>
ip route del <REMOTENET_IP>/<MASK> dev <INTERFACE>
Clear ARP
arp
ip neigh show
ip neigh del <IP> dev <INTERFACE>
ip neigh flush dev <INTERFACE>
DHCP
sudo dhclient <INTERFACE> (request IP from DHCP)
FakeTime
sudo apt install ntpsec-ntpdate
sudo apt install faketimeexport IP=<IP># sudo timedatectl set-ntp false
faketime "$(ntpdate -q $IP | cut -d ' ' -f 1,2)" <COMMAND>Last updated
Was this helpful?