Keep only last X lines of a file (shrink).
1 |
echo "$(tail -n 10000 huge.log)" > huge.log |
Deploy maven artefact to a specific repo without specifying it in pom.xml (format repoId:default:repoUrl). Repo should be specified in your .m2 settings.xml with any necessary credentials.
1 |
mvn deploy -DaltDeploymentRepository=repo.mydomain.com.my.releases::default::https://repo.mydomain.com/repository/maven-my-releases/ |
One liner to set password for default PostgreSQL user after initial install.
1 |
runuser -l postgres -c $'psql -c "ALTER USER postgres WITH PASSWORD \'postgres\';"' |
Run command inside a screen and save all output to a file
1 |
screen -dm bash -c 'script -c "some chatty command" output.txt' |
Scroll around inside a screen.
1 2 3 4 5 6 7 |
screen -r myscreen ctrl+a [ ctrl+u and ctrl+d for up and down. bufer is limited |
Add 4GB swap on Centos 7 with a stroke of a copy-paste.
1 2 3 4 5 |
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab |
Standard tcpdump.
1 |
tcpdump -i eth0 -s 65535 -w dump.pcap |
Show listening ports with corresponding executables.
1 |
netstat -tulpn |
Show systemd logs for a specific service.
1 |
journalctl -u nginx.service |
Freshly installed nginx configured as reverse proxy on Centos 7 getting "Permission denied" when connecting to backend service
1 |
setsebool -P httpd_can_network_connect 1 |
Convert a certificate stored in a Java keystore to a PEM cert and key (for example, Tomcat to Nginx transition).
1 2 3 |
$JAVA_HOME/bin/keytool -importkeystore -srckeystore .keystore -destkeystore keystore.p12 -deststoretype PKCS12 -srcalias mycrtalias -deststorepass changeit -destkeypass changeit openssl pkcs12 -in keystore.p12 -nokeys -out cert.pem openssl pkcs12 -in keystore.p12 -nodes -nocerts -out key.pem |
Disable git SSL verification per-repo.
1 |
git config http.sslVerify "false" |
Disable git SSL verification at clone time.
1 |
git -c http.sslVerify=false clone something |
Clear git username and password cache for a repo (in case of password change or similar).
1 |
git config --global --unset user.password |
Give user sudo privileges.
1 |
sudo usermod -aG wheel <user> |
Git submodule is added to an existing repo and is not resolving for you locally.
1 |
git submodule update --init --recursive |
Print all TCP connections of a Docker container.
1 2 3 |
sudo docker inspect -f '{{.State.Pid}}' containerName <result> sudo nsenter -t <result> -n netstat |
Nmap portscan.
1 |
sudo nmap -p 1-65535 -sV -sS -T4 <ip> |
Force JVM to use /dev/urandom instead of /dev/random (sometimes needed in low entropy environments like Docker).
1 |
java -Djava.security.egd=file:/dev/./urandom ... |
Debug print all network activities on JVM level.
1 |
java -Djavax.net.debug=all ... |
Create .htpasswd file for Nginx
1 2 |
sudo sh -c "echo -n 'someuser:' >> /etc/nginx/.htpasswd" sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd" |
Do or do not do something if file was modified recently
1 2 3 4 5 |
RECENTLY_CHANGED=$(find /tmp/me -newermt '10 minutes ago' |wc -l |xargs) if [ "$RECENTLY_CHANGED" -eq 1 ]; then echo "File was changed recently, terminating script" exit 0 fi |

GitHub
Eurobattle.net
Lagabuse.com
Bnetdocs