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.
Disable touchpad (any input device actually)
I have a problem with my touchpad being too sensitive, there's a better way via syncdaemon, an app brought by synaptics package that will monitor keyboard input and disable touchpad temporarily. But I can't get my touchpad recognized by the kernel yet.
This is a quick solution.
- Install xinput.
Show all input devices.
xinput list
Look for property number that mention "Device Enabled".
xinput list-props DEVICEID
Disable, set the property to 0.
xinput set-prop DEVICEID PROPID 0
Source: Nico Schottelius' blog.
Useful bash aliases
Set them in your .bash_aliases file in home directory. If your system doesn't call this file, you need to add this code in your .bashrc file (in home directory).
source .bash_aliases
Didn't find it useful, but I keep it here for later.
Prevent accidental deletions by making rm interactive:
alias rm='rm -i'
Source: