Skip to content

Instantly share code, notes, and snippets.

@ssledz
Last active April 8, 2021 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssledz/264c58786d8673e093ff7ff4cabe176f to your computer and use it in GitHub Desktop.
Save ssledz/264c58786d8673e093ff7ff4cabe176f to your computer and use it in GitHub Desktop.

check what listening on port 80

sudo ss -nltp | grep 80

encrypting compressed folder

tar cz my_folder/ | openssl enc -aes-256-cbc -e > encrypted.tar.gz.enc

list number of zombies in a system

ps auxwf | grep defunc | wc -l

checking if variable is unset or null

test -z ${x:+word} && echo 'unset or null' || echo "value=$x"

saving exit code during piping

mvn clean install $@ | tee $logfile
echo ${PIPESTATUS[0]}

multiple arguments for xargs

xargs -I XXX sh -c 'command1 XXX; command2 XXX; ...'

list all open connections

lsof -i

only tcp

lsof -i tcp

sending & receiving message using netcat & telnet

nc -l 1080 > msg.txt
echo 'message to send' | telnet localhost 1080

sending & receiving message using only netcat

nc -l 1080 > msg.txt
echo 'message to send' | nc localhost 1080

split string into chars

echo 'alamakota' |  fold -w 1

example of process substitution

cat <(date) <(date)

watch statistic from sar every 10s since 2 hour ago till now

watch -n 10 "sar -s $(date +'%H:%M:%S' -d '2 hour ago')"

example of using apache bench (ab) to post json (req=5000 concurrency = 5, -k = keep alive)

ab -k -c 5 -n 5000 -p payload.json -T application/json -H 'Authorization: Token abcd1234' http://localhost:8080/api/v1/xxxx

print a seq of numbers

for i in $(seq 1 2 10); do echo $i; done

display WM_CLASS property for a clicked app

xprop WM_CLASS

Add an existing user to existing group (-a means append, -G means secondary group)

usermod -a -G ftp tony
```bash

list of all puslaudio sinks
```bash
pactl list sinks  | grep -E 'Sink #[0-9]'

extracted list of pulsuadio sinks' ids

pactl list sinks  | grep -E 'Sink #[0-9]' | cut -d '#' -f 2

toggle mute/unmute first sink

pactl list sinks  | grep -E 'Sink #[0-9]' | cut -d '#' -f 2 | head -1 | xargs -I XXX pactl set-sink-mute XXX toggle

bump version

grep 2.14.1.0-SNAPSHOT **/*.xml | while IFS=: read -A line; do echo $line[1]; sed -i -e 's#<version>2.14.1.0-SNAPSHOT</version>#<version>2.14.2.0-SNAPSHOT</version>#g' $line[1]; done

grep 2.14.1.0-SNAPSHOT **/*.xml | while IFS=: read -A line; do echo $line[1]; sed -i -e 's#2.14.1.0-SNAPSHOT#2.14.2.0-SNAPSHOT#g' $line[1]; done

revert all changes

git status | while IFS=: read -A line; do echo $line[2]; gco -- $line[2]; done

copy remote to local ignoring symbolic links

rsync --progress -avhe ssh xxx@xxx.xxx.xxx:~/some_dir .

copy a content of remote some_dir to loacal, ignoring 'target' dir to current local dir

rsync --progress -avhe ssh --exclude 'target' xxx@xxx.xxx.xxx:~/some_dir/* .

copy local to remote, using ssh (-e ssh), progress (-P), archive (-a), verbose(-v), humna readable numbers (-h)

rsync -avhP -e ssh ~/local_dir username@remote_host:destination_directory

delete specific character

echo "the geek stuff" | tr -d 't'

replace t with d

echo "the geek stuff" | tr 't' 'd'

convert lower case to upper case

echo "the geek stuff" | tr [:lower:] [:upper:]
echo "the geek stuff" | tr a-z A-Z
echo "the geek stuff" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ

print all lines excepts first 10

cat file.txt | tail -n +11

initialize gitignore file, requires ~/.oh-my-zsh/plugins/gitignore plugin to be enabled

for s in maven java idea intellij eclipse gradle; do gi $s >> .gitignore; done

subtract 1 hour from date

date -d '1 hour ago'

date formatting

date +"%Y%m%d%H%M%S"

date from unix ts

date -d @1267619929

remove a line in a file matchin patter

sed -i "/pattern/d" file

remove empty line in a file

sed -i '/^$/d'

modify line in a file matching pattern1

sed -i "s/pattern1/pattern2/" file

echo something into stderr

(1>&2 echo "something")

redirect everything into file

(exec &> system.out; echo "something 1"; echo "something 2")

find all files matching regex and changed in last 24 hours

find . -mtime -1 -iregex "./model.*out"

find all files matching regex and not changed in last 24 hours - changed time > 24 hours

find . -mtime +1 -iregex "./model.*out"

puts last line from history to the editor

fc

read all lines from input - reads also last line without line end char

echo -n 'xxx' | while read line || [ -n "$line" ]; do echo $line; done

dirname of the currently executed scrip

dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if statements

[[ -z $profile ]] && echo "profile not set" || echo "profile: $profile"
[[ -e "file.cfg" ]] && echo "file.cfg exists"

serve current dir using http

docker run --rm -p 8080:80 -v $(pwd):/usr/share/nginx/html:ro nginx

produce record in kafka

echo 'key:value' | kafkacat -P -b localhost:9092 -t hello-world -K:

remove record from kafka in comacted mode

echo 'key:' | kafkacat -P -b localhost:9092 -t hello-world -Z -K:

read records from kafka

kafkacat -C -b localhost:9092 -t hello-world -f '%k:%s\n' -o beginning

git clone using a given ssh key

git clone -c core.sshCommand="ssh -v -i /home/sledzs/.ssh/xxx/id_rsa" $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment