CLI commands notes

Table of contents


1. Archives

Pack

tar -zcvf --exclude="bitrix/backup/*" --exclude="bitrix/cache/*" --exclude="bitrix/managed_cache/*" --exclude="bitrix/stack_cache/*" --exclude="bitrix/html_pages/*" bitrix.tar.gz ./bitrix
tar -zcvf git.tar.gz ".git"

Unpack

tar -zxvf bitrix.tar.gz

Unpack and skip existing files

tar --skip-old-files -zxvf bitrix.tar.gz

Pack and split by size

tar cvzf - dir/ | split --bytes=200MB - sda1.backup.tar.gz.

Unpack multiple parts

cat sda1.backup.tar.gz.* | tar xzvf -

ZIP (Mac)

zip -r -X archive_name.zip folder_to_compress
unzip archive_name.zip

2. Mysql dump

Export

mysqldump --opt -u USER -p DBNAME > dbname.sql

Import .sql file

mysql -u USER -p DBNAME < dbname.sql

Import .sql.qz file

gunzip -cd dump.sql.gz | mysql -u USER -p DBNAME

Open remote connections

# open 3306 port
sudo ufw allow 3306/tcp
sudo service ufw restart

# set bind-address = *
vi /etc/mysql/mysql.conf.d/mysqld.cnf

# update user
GRANT ALL ON *.* TO root@% IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES; 

3. Work with files

Remove directories

rm -rf mydir

Show dir sizes

du -sh *

Show size of specific dir

du -sh mydir

Remove 0 size files

find /tmp -size  0 -print0 |xargs -0 rm

See last 10 lines

tail -F file.log

See first 10 line

head file.log

Symlinks

ln -s /path/to/file /path/to/symlink

Change owner

chown -Rc w19_admin:psacln .;chown -c w19_admin:psaserv .

Change permitions

chmod -R 755 /var/www

find * -type d -print0 | xargs -0 chmod 0755 # for directories
find . -type f -print0 | xargs -0 chmod 0644 # for files

Find text in file

grep --include=\*.{xml,php} -rnw '/path/to/somewhere/' -e "pattern"

Find directory by name

find  / -name "apt"

4. Git

Add repo to existing folder

git init
git remote add origin PATH/TO/REPO
git fetch
git reset --hard origin/master

Track remote branch

git branch --set-upstream master origin/master

New remote URL

git remote set-url origin new-url

Clone from SVN repo

git svn clone -s http://source.epages.su/svn/nasosik/

Update Git CentOS

yum install http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm
yum install git
git --version

Get repo from site by HTTP

git clone http://chaosdorf.de/.git/
curl http://chaosdorf.de/.git/HEAD
curl http://chaosdorf.de/.git/refs/heads/master
git http-fetch -a 57104ea967fc24763ead9c57d3463a80e9d05eea http://chaosdorf.de/.git
git checkout 57104ea967fc24763ead9c57d3463a80e9d05eea

Get changed files compared to branch

# linux
git diff --name-only --diff-filter=ACMRTUXB origin/master | grep ".sql"
# win
git diff --name-only --diff-filter=ACMRTUXB origin/master | findstr ".sql"

Delete remote branches that were merged to main

for k in $(git branch -r --merged | egrep -v "(^\*|master|main)"); do 
    git push origin -d "${k/origin\//}"
done

5. SVN

New svn repo

svnadmin create /var/svn/repos

6. Other

Find files with BOM

grep -rl $'\xEF\xBB\xBF' .

Plesk php

/opt/plesk/php/5.6/bin/php

Measure cURL response time

curl -l "https://URL" -w 'Establish Connection: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n'

7. Work with processes

ps aux | less
netstat -nlpt | grep 8080
ps ax | grep jira | grep -v grep

8. Mac OS

Add spaces to dock

defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'

Stop mysql, apache

sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
sudo apachectl -k stop

Disable mail

/etc/postfix/main.cf
default_transport = error:This server sends mail only locally.

Secondary skype

alias skype2='sudo /Applications/Skype.app/Contents/MacOS/Skype /secondary'

Find processes

ps -ef | grep php

9. DigitalOcean

Ubuntu 16 nginx /etc/nginx/

sudo systemctl restart nginx
sudo systemctl stop nginx
sudo systemctl start nginx
nginx -t

Enable site in nginx

ln -s /etc/nginx/sites-available/freebestgames.xyz /etc/nginx/sites-enabled/freebestgames.xyz

10. Kubernetes Azure

kubectl configuration

Azure CLI
az login 
az account list 
az account set --subscription "Aspire Global Corp"
az account show
az aks list
az aks get-credentials --resource-group dev_solar --name dev-solar-wdrt
kubectl get pods
PowerShell Module
Get-AzContext 
Connect-AzAccount 
Import-AzAksCredential 
kubectl version 
kubectl get pods 
kubectl exec -it solar-6fb4cf8cc7-j6pm2 sh 

K8s secrets

Create secret

kubectl create secret generic SECRET_NAME --from-literal=SECRET_KEY=SECRET_VALUE --from-literal=SECRET_KEY2=SECRET_VALUE2

Delete secret

kubectl delete secret SECRET_NAME

Edit sectet

kubectl edit secrets secret_name

Delete evicted pods

for each in $(kubectl get pods|grep Evicted|awk '{print $1}');
do
kubectl delete pods $each
done

11. DNS

Trace DNS for domain

dig -4 +trace rodion-blog.tech A @8.8.8.8