How can I securely delete the whole harddisk?

dd if=/dev/zero of=/dev/hda bs=65535

How can I check the harddisk for errors?

sudo badblocks -vs /dev/hda1

How can I search through a whole mysql-database?

The script assumes that the database is on localhost, that the user is “root” and that no password is required. Please adjust it otherwise in the script.

#!/bin/bash # This script searches in a database named $1 for a string $2 # usage example: ./search_through_database.sh “database_name” “string” # TODO: check the parameters database=$1 string=$2 query=”show [...]

How do I search recursively in specific files for a searchphrase?

Use “grep”:

grep -rsinH –include={pattern} “{searchphrase}” {file_or_directory}

For example: grep -rsinH –include=*.txt “searchphrase” ./

“rsinH” is equal to: –recursive –no-messages –ignore-case –line-number –with-filenames

As an alternative you can use grep in combination with find:

for f in $(find . -name *.txt); do grep -sinH “{searchphrase}” $f; done;

How do I perform a copy over ssh with packing and unpacking on the fly?

ssh -T {user}@{host} tar -c {source_directory} | tar -C {target_directory} -xpv

How do I create a mysql dump from a remote server to the local machine?

mysqldump –opt –host={213.211.111.11} –user=’{username}’ –password=’{password}’ –database {db_name} > {path/to/file/filename.sql}

How do I export and import a mysql database?

Export a mysql database to a file: mysqldump -u {database_username} -p {database_password} {database_name} > {filename}.sql

Read in a database export: mysql -u {database_username} -p {database_password} {database_name} < {filename}.sql

Blog by Category

Blog by Date