Unix

Files backup

tar czpf site_files.tar.gz httpdocs --exclude='ajax-uploader' --exclude='anyotherdirectory'

Files backup, split into more files with max size

tar cvzf - DIR | split --bytes=200MB - sda1.backup.tar.gz.
tar cvzf - FILE | split --bytes=200MB - sda1.backup.tar.gz.

Join splitted files to one file

cat vid* > test.tar.gz


Unzip tar gzip

gunzip magento-1.4.1.0.tar.gz
tar xf magento-1.4.1.0.tar

Search for text in all files under dir

grep -r "something.co.uk" /etc/nginx/conf.d


Tar gzip

tar -czf dbname.tar.gz dbdump.sql


Get free space on server

df -h


Get size of directory

du -sh DIRECTORY


Change user

su - USERNAME


Change folder permissions (for user lrg and folder var)

chown lrg:lrg var -R


List folder

ls -l


Find string in file (simple)

grep simple system.log | less


Show processes list

ps axf | less


Check if Magento reindex process is running

ps aux | grep php | grep indexer


Kill process

kill NNNN


Move all files one dir up

mv myfolder/* .


List of unsend mails - mail queue

mailq


Display email with concrete header

postcat -q E6A0227EDB


Kill all chrome

ps aux | grep chrome | awk ' { print $2 } ' | xargs kill -9


Find all files bigger than 250mb

find . -size +250M -ls


To find out all files that have been modified on 2013-02-07 (07/Feb/2013)

find /path/to/dir -type f -name "*" -newermt 2013-02-07 ! -newermt 2013-02-08




DB

Mysql backup

mysqldump -u USERNAME -pPASSWORD DB_NAME > FILENAME.sql

Db dump

mysqldump -u username -ppassword dbname > dbdump.sql


List running mysql queries (showing the longest running at the bottom of the list)

mysql -e 'show full processlist;' | grep -v Sleep | sort -n -k 6


Mysql kill query

mysql> kill query QUERYID;


Connect to db

mysql -h localhost -u username -ppasword


Import db - if in sql file is query for creating db

mysql -u username -ppassword < dbdump.sql


Import db - if in sql file isnt query for creating db

mysql -u username -ppassword dbname < dbdump.sql


Mysql show databases

show databases;


Copy db

mysqldump mydbname | mysql mydbcopy


Change mysql password for user

set password fop 'db-user'@'db' = PASSWORD('db-password');
flush privileges;