Common CLI commands¶
Copying files locally¶
rsync -avhW --no-compress --progress /src/ /dst/
Show only headers¶
curl has an option to display only headers using
-I. This flag is better than using a combination of
-s and redirecting the output to
2>&1 as it's easier to remember.
An important thing to note is that
-I sends a
HEAD request. As shown here:
$ curl -I -vvvv https://mrkaran.dev 2>&1 | grep -C 3 'HEAD' } [5 bytes data] * Using Stream ID: 1 (easy handle 0x55dff1e30920) } [5 bytes data] > HEAD / HTTP/2 > Host: mrkaran.dev > user-agent: curl/7.76.1 > accept: */*
However it's easy to override the HTTP method using
-X. For eg, to send a
GET request but only display the headers:
curl -I -X GET -vvvv https://mrkaran.dev
Send a JSON payload from file¶
curl -i -XPOST -H "Content-Type: application/json" -d @mock_payload.json http://localhost:6000/endpoint
Set the editor¶
git config --global core.editor "vim"
Edit in place¶
sed -i 's/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g' filename
Match only the word¶
\b in regex is used to match word boundaries (i.e. the location between the first word character and non-word character).
sed -i 's/\bsuper_specific_phrase\b/STRING_TO_REPLACE_IT/g' filename
Check for packets flowing out from an interface for a specific CIDR¶
sudo tcpdump -v -i wlo1 dst net 192.168.0.0/16
wlo1is the interface name.
netspecifies it's a CIDR range.