Glass Onion Blog

Cheat sheets, post-its and random notes from the desk of a programmer

Posts Tagged ‘command line’

Linux: Renaming multiple files from command line

Posted by walrus on September 12, 2008

How to rename multiple files at a shell prompt under Linux? The rename command is quite useful.

Rename command usage:

rename oldname newname *.files

Some examples:

Rename all *.abc file as *.xyz:

$ rename .abc .xyz *.abc

Remove .txt file extension:

$ rename 's/\.txt$//' *.txt

Convert all uppercase filenames to lowercase:

$ rename 'y/A-Z/a-z/' *

Posted in Software, linux | Tagged: , , , , | Leave a Comment »

Back up and Restore MySQL database from the command line

Posted by walrus on July 30, 2008

Backing up via the command line:

Type the following at the prompt with the appropriate USERNAME and DATABASE name:

mysqldump -u USERNAME -p DATABASE > dump.sql

You will be prompted for your database password and then the DATABASE will be dumped to a plain-text file called dump.sql.

Restoring via the command line:

First drop and recreate the database as needed:

Drop the database

mysqladmin -u USERNAME -p drop DATABASE

Recreate the database

mysqladmin -u USERNAME -p create DATABASE

Import the backup data

mysql -u USERNAME -p DATABASE < dump.sql

Posted in MySQL, Software, linux | Tagged: , , , , | Leave a Comment »