Assorted OSX / Linux commands cheat sheet

Reset mysql root access:

sudo service mysql stop
sudo mysqld_safe —skip-grant-tables —skip-networking &
mysql -u root

In the mysql:

use mysql;
update user set authentication_string=password('NEWPASSWORD') where user='root';
flush privileges;
quit

Restart mysql:

sudo service mysql restart

In case of: mysqld_safe Directory ‘/var/run/mysqld’ for UNIX socket file don’t exists. error, create this directory and set ownership:

mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld

Grant access to mysql from other host:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Check for running server in local network:

for i in {2..255}; do echo $i; curl --connect-timeout 1 192.168.0.$i; done

Check which process uses port:

sudo lsof -i :8081

Send image via POST form request using CURL:

curl -X POST -F 'image=@/Users/me/image.jpg' https://server/image

Multiple http requests reading each url from line in the file:

cat links | while read line; do curl -O $line; done

Monitor Nginx errors in real time:

tail -f /var/log/nginx/error.log

Rename git branch when on this branch:

git branch -m new-name

Add new emails to Postfix

sudo nano /etc/postfix/virtual
sudo postmap /etc/postfix/virtual
sudo systemctl restart postfix

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store