Useful bash scripts
Tar
Create tar file:
tar -cv -f FILENAME.tar DIR/FILES
- -p, preserve file permissions.
- -J, xz (best) compression, or -j for bz2
Drop all database tables
Save this code as "db-truncate.sh".
#!/bin/bash
mysqldump -u$1 -p$2 --add-drop-table --no-data $3 | grep -e '^DROP \| FOREIGN_KEY_CHECKS' | mysql -u$1 -p$2 $3
For database dump: db-dump.sh
#!/bin/bash
mysqldump -hHOST -uUSER -pPASS DATABASE --no-data > DATABASE.schema.sql
mysqldump -hHOST -uUSER -pPASS DATABASE --ignore-table=DATABASE.search_index --ignore-table=DATABASE.cache% --extended-insert=FALSE --no-create-info --add-drop-table --compress | split --line-bytes=20000000 - DATABASE.sql.
gzip DATABASE.sql.*
Show hidden files on console
If you need to copy directory including the hidden files, you need this.
Set shopt dotglobe option to enable.
shopt -s dotglob
Copy hidden files and folder.
cp -pr SOURCEDIR TARGETDIR
Set shopt dotglobe option to disable.
shopt -u dotglob
Source: labtestproject.com.
Read more »