Common commands

Tool: terminal

Reload shell without exit

exec $SHELL -l

Close shell keeping all subprocess running

disown -a && exit

Exit without saving shell history

kill -9 $$
unset HISTFILE && exit

Perform a branching conditional

true && echo success
false || echo failed

Pipe stdout and stderr to separate commands

some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr)

Redirect stdout and stderr each to separate files and print both to the screen

(some_command 2>&1 1>&3 | tee errorlog ) 3>&1 1>&2 | tee stdoutlog

List of commands you use most often

history | \
awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | \
grep -v "./" | \
column -c3 -s " " -t | \
sort -nr | nl |  head -n 20

Sterilize bash history

Look also: A naive utility to censor credentials in command history.

Quickly backup a file

Empty a file (truncate to 0 size)

Delete all files in a folder that don't match a certain file extension

Pass multi-line string to a file

Edit a file on a remote host using vim

Create a directory and change into it at the same time

Convert uppercase files to lowercase files

Print a row of characters across the terminal

Show shell history without line numbers

Run command(s) after exit session

Generate a sequence of numbers

Simple Bash filewatching

Tool: busybox

Static HTTP web server

Tool: [mount](https://en.wikipedia.org/wiki/Mount_(Unix))

Mount a temporary ram partition

  • -t - filesystem type

  • -o - mount options

Remount a filesystem as read/write

Tool: [fuser](https://en.wikipedia.org/wiki/Fuser_(Unix))

Show which processes use the files/directories

Kills a process that is locking a file

  • -i - interactive option

Kills a process that is locking a file with specific signal

  • --list-signals - list available signal names

Show what PID is listening on specific port

Show all processes using the named filesystems or block device

Tool: lsof

Show process that use internet connection at the moment

Show process that use specific port number

Lists all listening ports together with the PID of the associated process

List all open ports and their owning executables

Show all open ports

Show open ports (LISTEN)

List all files opened by a particular command

View user activity per directory

Show 10 largest open files

Show current working directory of a process

Tool: [ps](https://en.wikipedia.org/wiki/Ps_(Unix))

Show a 4-way scrollable process tree with full details

Processes per user counter

Show all processes by name with main header

Tool: [find](https://en.wikipedia.org/wiki/Find_(Unix))

Find files that have been modified on your system in the past 60 minutes

Find all files larger than 20M

Find duplicate files (based on MD5 hash)

Change permission only for files

Change permission only for directories

Find files and directories for specific user/group

Find files and directories for all without specific user/group

Looking for files/directories that only have certain permission

Delete older files than 60 days

Recursively remove all empty sub-directories from a directory

How to find all hard links to a file

Recursively find the latest modified files

Recursively find/replace of a string with sed

Recursively find/replace of a string in directories and file names

Recursively find suid executables

Tool: [top](https://en.wikipedia.org/wiki/Top_(software))

Use top to monitor only all processes with the specific string

  • <str> - process containing string (eg. nginx, worker)

Tool: vmstat

Show current system utilization (fields in kilobytes)

  • 2 - number of times with a defined time interval (delay)

  • 20 - each execution of the command (count)

  • -t - show timestamp

  • -w - wide output

  • -S M - output of the fields in megabytes instead of kilobytes

Show current system utilization will get refreshed every 5 seconds

Display report a summary of disk operations

Display report of event counters and memory stats

Display report about kernel objects stored in slab layer cache

Tool: iostat

Show information about the CPU usage, and I/O statistics about all the partitions

  • 2 - number of times with a defined time interval (delay)

  • 10 - each execution of the command (count)

  • -t - show timestamp

  • -m - fields in megabytes (-k - in kilobytes, default)

Show information only about the CPU utilization

Show information only about the disk utilization

Show information only about the LVM utilization

Tool: strace

Track with child processes

Track process with 30 seconds limit

Track processes and redirect output to a file

Track with print time spent in each syscall and limit length of print strings

Track the open request of a network port

Track the open request of a network port (show TCP/UDP)

Tool: [kill](https://en.wikipedia.org/wiki/Kill_(command))

Kill a process running on port

Tool: diff

Compare two directory trees

Compare output of two commands

Tool: vimdiff

Highlight the exact differences, based on characters and words

Compare two JSON files

Compare Hex dump

diffchar

Save diffchar @ ~/.vim/plugins

Click F7 to switch between diff modes

Usefull vimdiff commands:

  • qa to exit all windows

  • :vertical resize 70 to resize window

  • set window width Ctrl+W [N columns]+(Shift+)<\>

Tool: [tail](https://en.wikipedia.org/wiki/Tail_(Unix))

Annotate tail -f with timestamps

Analyse an Apache access log for the most common IP addresses

Analyse web server log and show only 5xx http codes

Tool: [tar](https://en.wikipedia.org/wiki/Tar_(computing))

System backup with exclude specific directories

System backup with exclude specific directories (pigz)

Tool: [dump](https://en.wikipedia.org/wiki/Dump_(program))

System backup to file

Restore system from lzo file

Tool: cpulimit

Limit the cpu usage of a process

Tool: pwdx

Show current working directory of a process

Tool: taskset

Start a command on only one CPU core

Tool: [tr](https://en.wikipedia.org/wiki/Tr_(Unix))

Show directories in the PATH, one per line

Tool: chmod

Remove executable bit from all files in the current directory

Restore permission for /bin/chmod

Tool: [who](https://en.wikipedia.org/wiki/Who_(Unix))

Find last reboot time

Detect a user sudo-su'd into the current shell

Tool: last

Was the last reboot a panic?

Tool: screen

Start screen in detached mode

Attach to an existing screen session

Tool: [script](https://en.wikipedia.org/wiki/Script_(Unix))

Record and replay terminal session

Tool: du

Show 20 biggest directories with 'K M G'

Tool: inotifywait

Init tool everytime a file in a directory is modified

Tool: openssl

Testing connection to the remote host

Testing connection to the remote host (debug mode)

Testing connection to the remote host (with SNI support)

Testing connection to the remote host with specific ssl version

Testing connection to the remote host with specific ssl cipher

Verify 0-RTT

Generate private key without passphrase

Generate private key with passphrase

Remove passphrase from private key

Encrypt existing private key with a passphrase

Check private key

Get public key from private key

Generate private key and CSR

Generate CSR

Generate CSR (metadata from existing certificate)

Where private.key is the existing private key. As you can see you do not generate this CSR from your certificate (public key). Also you do not generate the "same" CSR, just a new one to request a new certificate.

Generate CSR with -config param

Other values in [ dn ]:

Example of oids (you'll probably also have to make OpenSSL know about the new fields required for EV by adding the following under [new_oids]):

For more information please look at these great explanations:

List available EC curves

Print ECDSA private and public keys

Generate ECDSA private key

Generate private key and CSR (ECC)

Generate self-signed certificate

Generate self-signed certificate from existing private key

Generate self-signed certificate from existing private key and csr

Generate DH public parameters

Display DH public parameters

Extract private key from pfx

Extract private key and certs from pfx

Extract certs from p7b

Convert DER to PEM

Convert PEM to DER

Verification of the private key

Verification of the public key

Verification of the certificate

Verification of the CSR

Check the private key and the certificate are match

Check the private key and the CSR are match

Tool: secure-delete

Secure delete with shred

Secure delete with scrub

Secure delete with badblocks

Secure delete with secure-delete

Tool: [dd](https://en.wikipedia.org/wiki/Dd_(Unix))

Show dd status every so often

Redirect output to a file with dd

Tool: gpg

Export public key

  • --export - export all keys from all keyrings or specific key

  • -a|--armor - create ASCII armored output

Encrypt file

  • -e|--encrypt - encrypt data

  • -r|--recipient - encrypt for specific

Decrypt file

  • -o|--output - use as output file

  • -d|--decrypt - decrypt data (default)

Search recipient

  • --keyserver - set specific key server

  • --search-keys - search for keys on a key server

List all of the packets in an encrypted file

Tool: system-other

Reboot system from init

Init system from single user mode

Show current working directory of a process

Show actual pathname of the executed command

Tool: curl

  • -I - show response headers only

  • -k - insecure connection when using ssl

  • -s - silent mode (not display body)

  • --location - follow redirects

  • -X - set method

  • -A - set user-agent

  • --proxy [socks5://|http://] - set proxy server

  • -o - write output to file

  • -C - resume the transfer

Find your external IP address (external services)

Repeat URL request

Check DNS and HTTP trace with headers for specific domains

Tool: httpie

  • -p - print request and response headers

    • H - request headers

    • B - request body

    • h - response headers

    • b - response body

  • -F, --follow - follow redirects

  • --verify no - skip SSL verification

  • --proxy [http:] - set proxy server

Tool: ssh

Escape Sequence

Compare a remote file with a local file

SSH connection through host in the middle

Run command over SSH on remote host

Get public key from private key

Get all fingerprints

SSH authentication with user password

SSH authentication with publickey

Simple recording SSH session

Using Keychain for SSH logins

SSH login without processing any login scripts

SSH local port forwarding

Example 1:

Example 2:

  • -n - redirects stdin from /dev/null

  • -N - do not execute a remote command

  • -T - disable pseudo-terminal allocation

SSH remote port forwarding

Tool: linux-dev

Testing remote connection to port

  • <proto - set protocol (tcp/udp)

  • <host> - set remote host

  • <port> - set destination port

Read and write to TCP or UDP sockets with common bash tools

Tool: tcpdump

Filter incoming (on interface) traffic (specific )

  • -n - don't convert addresses (-nn will not resolve hostnames or ports)

  • -e - print the link-level headers

  • -i [iface|any] - set interface

  • -Q|-D [in|out|inout] - choose send/receive direction (-D - for old tcpdump versions)

  • host [ip|hostname] - set host, also [host not]

  • [and|or] - set logic

  • port [1-65535] - set port number, also [port not]

Filter incoming (on interface) traffic (specific ) and write to a file

  • -c [num] - capture only num number of packets

  • -w [filename] - write packets to file, -r [filename] - reading from file

Capture all ICMP packets

Check protocol used (TCP or UDP) for service

Display ASCII text (to parse the output using grep or other)

Grab everything between two keywords

Grab user and pass ever plain http

Extract HTTP User Agent from HTTP request header

Capture only HTTP GET and POST packets

or simply:

Rotate capture files

  • -G <num> - pcap will be created every <num> seconds

  • -C <size> - close the current pcap and open a new one if is larger than <size>

Top hosts by packets

Excludes any RFC 1918 private address

Tool: tcpick

Analyse packets in real-time

Tool: ngrep

  • -d [iface|any] - set interface

  • [domain] - set hostname

  • port [1-65535] - set port number

  • (host [ip|hostname]) - filter by ip or hostname

  • (port [1-65535]) - filter by port number

  • -q - quiet mode (only payloads)

  • -t - added timestamps

  • -O [filename] - save output to file, -I [filename] - reading from file

  • HTTP - show http headers

  • tcp|udp - set protocol

  • [src|dst] host [ip|hostname] - set direction for specific node

  • -l - stdout line buffered

  • -i - case-insensitive search

Tool: hping3

  • -V|--verbose - verbose mode

  • -p|--destport - set destination port

  • -s|--baseport - set source port

  • <scan_type> - set scan type

    • -F|--fin - set FIN flag, port open if no reply

    • -S|--syn - set SYN flag

    • -P|--push - set PUSH flag

    • -A|--ack - set ACK flag (use when ping is blocked, RST response back if the port is open)

    • -U|--urg - set URG flag

    • -Y|--ymas - set Y unused flag (0x80 - nullscan), port open if no reply

    • -M 0 -UPF - set TCP sequence number and scan type (URG+PUSH+FIN), port open if no reply

  • -c [num] - packet count

  • -1 - set ICMP mode

  • -C|--icmptype [icmp-num] - set icmp type (default icmp-echo = 8)

  • --flood - sent packets as fast as possible (don't show replies)

  • --rand-source - random source address mode

  • -d --data - data size

  • -w|--win - winsize (default 64)

Tool: nmap

Ping scans the network

Show only open ports

Full TCP port scan using with service version detection

Nmap scan and pass output to Nikto

Recon specific ip:service with Nmap NSE scripts stack

Tool: netcat

  • -l - listen for an incoming connection

  • -k - listening after client has disconnected

  • >filename.out - save receive data to file (optional)

  • < filename.in - send data to remote host

  • -v - verbose output

  • -z - scan for listening daemons

  • -u - scan only udp ports

Transfer data file (archive)

Launch remote shell

Simple file server

Simple minimal HTTP Server

Simple HTTP Server

Restarts web server after each request - remove while condition for only single connection.

  • -p - port number

Simple HTTP Proxy (single connection)

Create a single-use TCP or UDP proxy

Tool: gnutls-cli

Testing connection to remote host (with SNI support)

Testing connection to remote host (without SNI support)

Tool: socat

Testing remote connection to port

  • - - standard input (STDIO)

  • TCP4:<params> - set tcp4 connection with specific params

    • [hostname|ip] - set hostname/ip

    • [1-65535] - set port number

Redirecting TCP-traffic to a UNIX domain socket under Linux

  • TCP-LISTEN:<params> - set tcp listen with specific params

    • [1-65535] - set port number

    • bind=[hostname|ip] - set bind hostname/ip

    • reuseaddr - allows other sockets to bind to an address

    • fork - keeps the parent process attempting to produce more connections

    • su=nobody - set user

    • range=[ip-range] - ip range

  • UNIX-CLIENT:<params> - communicates with the specified peer socket

    • filename - define socket

Tool: p0f

Set iface in promiscuous mode and dump traffic to the log file

  • -i - listen on the specified interface

  • -p - set interface in promiscuous mode

  • -d - fork into background

  • -o - output file

Tool: netstat

Graph # of connections for each hosts

Monitor open connections for specific port including listen, count and sort it per IP

Grab banners from local IPv4 listening ports

Tool: rsync

Rsync remote data as root using sudo

Tool: [host](https://en.wikipedia.org/wiki/Host_(Unix))

Resolves the domain name (using external dns server)

Checks the domain administrator (SOA record)

Tool: [dig](https://en.wikipedia.org/wiki/Dig_(command))

Resolves the domain name (short output)

Lookup NS record for specific domain

Query only answer section

Query ALL DNS Records

DNS Reverse Look-up

Tool: certbot

Generate multidomain certificate

Generate wildcard certificate

Generate certificate with 4096 bit private key

Tool: network-other

Get all subnets for specific AS (Autonomous system)

Resolves domain name from dns.google.com with curl and jq

Tool: git

Log alias for a decent view of your repo

Tool: python

Static HTTP web server

Static HTTP web server with SSL support

Encode base64

Decode base64

Tool: awk

Search for matching lines

Search non matching lines

Print matching lines with numbers

Print the last column

Find all the lines longer than 80 characters

Print only lines of less than 80 characters

Print double new lines a file

Print line numbers

Print line numbers for only non-blank lines

Print the line and the next two (i=5) lines after the line matching regexp

Print the lines starting at the line matching 'server {' until the line matching '}'

Print multiple columns with separators

Remove empty lines

Delete trailing white space (spaces, tabs)

Delete leading white space

Remove duplicate consecutive lines

Remove duplicate entries in a file without sorting

Exclude multiple columns

Substitute foo for bar on lines matching regexp

Add some characters at the beginning of matching lines

Get the last hour of Apache logs

Tool: sed

Print a specific line from a file

Remove a specific line from a file

Remove a range of lines from a file

Replace newline(s) with a space

  • :a create a label a

  • N append the next line to the pattern space

  • $! if not the last line, ba branch (go to) label a

  • s substitute, /\n/ regex for new line, / / by a space, /g global match (as many times as it can)

Alternatives:

Delete string +N next lines

Tool: grep

Search for a "pattern" inside all files in the current directory

Show only for multiple patterns

Except multiple patterns

Show data from file without comments

Show data from file without comments and new lines

Show strings with a dash/hyphen

Remove blank lines from a file and save output to new file

Tool: perl

Search and replace (in place)

Edit of *.conf files changing all foo to bar (and backup original)

Prints the first 20 lines from *.conf files

Search lines 10 to 20

Delete first 10 lines (and backup original)

Delete all but lines between foo and bar (and backup original)

Reduce multiple blank lines to a single line

Convert tabs to spaces (1t = 2sp)

Read input from a file and report number of lines and characters

Shell functions  [TOC]

Table of Contents

  • Domain resolve

  • Get ASN

Domain resolve

Example:

Get ASN

Example:

Last updated

Was this helpful?