Saul Salazar/A few Linux scripts

Created Sun, 05 Sep 2021 00:00:00 +0000
284 Words

Scripts that I hope will help you, you can add them as an alias or copypaste directly when you need them.

Doge git commands

I will start with some funny aliases to convert git into “doge language”.

# add to your .bashrc or .zshrc
alias such=git
alias very=git
alias wow='git status'

# reload your terminal and be doge
$ wow
$ very add some_files
$ such commit -m 'Commit Message'
$ very push

How to create website backups (Apache Web Server)

It also downloads the backup directly to your workstation thanks to SSH (be sure to configure it before trying to connect) and compress the result file using GZIP.

$ ssh yourSite "cd /var/www/html/yourSite/ && tar -cf - . | gzip -9c" > /local/yourSite/yourSite.tar.gz

How to create database backups (MySQL)

It also downloads the backup directly to your workstation thanks to SSH (be sure to configure it before trying to connect) and compress the result file using GZIP.

$ ssh yourSite "mysqldump -h hostname.com -P 3306 -u userName -p password -- databaseName | gzip -9c" > /work/yourSite.sql.gz

List linux proccesses by memory usage

With a human readable format

$ ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }'

# result:
28.10 Mb light-locker
0.46 Mb /usr/sbin/cron -f
0.38 Mb /usr/bin/ssh-agent /usr/bin/im-launch /usr/bin/lxsession -s Lubuntu -e LXDE
0.38 Mb /usr/bin/ssh-agent -s
0.36 Mb /sbin/agetty -o -p -- \u --noclear tty1 linux
0.34 Mb awk { hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }
0.31 Mb sh -c vuepress dev docs