:::: MENU ::::

Removing .git / .svn directories

Sometimes you have to remove directories from your VCS tool.

find . -name .svn -exec rm -rf {} \;

Listing affected directories

find . -name .svn -exec echo {} \;

Useful curl

Headers only

--head – performs HEAD http request (not GET).

curl --head https://www.wp.pl/

Content + headers

--get – performs GET request
-i – include headers

curl --get -i https://www.wp.pl/

Low bandwidth copy

So, you have to copy one directory into another on your server and you don’t want to kill the machine?

Instead of

cp -r master master_copy


rsync --bwlimit=30000 -av master/ master_copy/

The –bwlimit=KBPS switch is for limiting I/O bandwidth.

Grep with context

Small thing but extremely useful. Getting context with grep.

-C – Print num lines of leading and trailing context surrounding each match. The default is 2 and is equivalent to -A 2 -B 2. Note: no whitespace may be given between the option and its argument.

grep -C 5 file.txt

Full MySQL dump

If you would like to dump all tables and triggers and stuff try this one:

mysqldump -uUSER -p -R --opt --triggers DB > DB_DUMP.sql

but if you have some troubles with permissions for locking tables use --lock-tables=false

mysqldump -uUSER -p -R --opt --triggers --lock-tables=false DB > DB_DUMP.sql

and to dump all databases you have

mysqldump -uUSER -p -R --opt --triggers --lock-tables=false --all-databases > DB_DUMP.sql

also, great post on StackExchange with a script for dumping all databases without databases like `mysql`, `information_schema`, `performance_schema`, `sys`.

# Collect all database names except for
# mysql, information_schema, and performance_schema
SQL="SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN"
SQL="${SQL} ('mysql','information_schema','performance_schema')"

mysql ${MYSQL_CONN} -ANe"${SQL}" > ${DBLISTFILE}

for DB in `cat ${DBLISTFILE}` ; do DBLIST="${DBLIST} ${DB}" ; done

MYSQLDUMP_OPTIONS="--routines --triggers --single-transaction"
mysqldump ${MYSQL_CONN} ${MYSQLDUMP_OPTIONS} --databases ${DBLIST} > all-dbs.sql