Bash

Frequently used bash snippets

Check memory from bash

free -mh

Check access through ssh

last | head

Check open ports nmap

while :; 
do nmap <addres> -p443,9200,80,22 -Pn --max-rtt-timeout 60ms  ;
sleep 1 ; done

Check open ports lsof

sudo lsof -i -P -n #or
sudo lsof -i -P -n | grep LISTEN #or
lsof -i :8000 # by port

Openning port in ubuntu

sudo ufw allow [PORT]

If statements

if [ -z STRING]
then
fi

If with multiple conditions and checking lenght == 0

Uninstall packages

Kill processes

Search keywords in files within a directory

Remove character in-place

Remove a specific line from file

Add character to the beginning of the file

Remove first line from file

Create sudo user

List omitting directory

Collect http urls from several csv into a single one

cURL requests

Delete history entry

history -d <line_number>

tmux

Create a new session

List sessions

Attach a session

Detach a session

Send a command to a detached session

Split panes for detached sessions

Compress file

unzip file

Text processing

Get specific line from file

awk > sed for big files

Substitute char in big file

Might require LC_ALL=C at the beginning depending on in_file encoding

Get content between START and END pattern

Generate a password or key

Generate base64 encoded for text

References

Last updated

Was this helpful?