Last updated 2 December 2012. Created on 19 December 2011.
Edited by thomaske, Hethrir, snowmountain, gbell12. Log in to edit this page.

Following are some useful Unix/Linux commands which are helpful if you are dealing with large sites (files and db size). I find these really handy when moving sites from one server to other, taking backups of Files, Database etc.

Note: To get access to the Unix command line, you will need an SSH client (e.g. Putty). You can also use WinSCP if you are not comfortable with Command line. WinSCP has a feature to enter custom commands using its interface.

Please add other command-line commands that you use while setting up, developing and managing your Drupal sites.

Zip Contents of current directory
zip -r *

Unzip Contents into current directory

Unzip (and extract) the tar'd, gzipped archive (tarball) Contents into current directory
tar zxvf tarballfile.tar.gz

Remove a directory and its contents (Use with extra care)
rm -rf directoryname

Backup Database
mysqldump dbname -uUSERNAME -pPASSWORD --host HOST > filename.sql

Restore Database
mysql -u root -p[root_password] [database_name] < dumpfilename.sql

Copy all files / directories from one server to other (Both servers should have SSH Support)
rsync -avz --progress username@servername:sourcefolder destinationfolder

Drupalize.Me offers a series of free videos on leveraging the command line in Linux/Unix/OSX for Drupal...
Moving Around the Command Line
Copy, Move and Delete on the Command Line
Dealing with Permissions on the Command Line
Creating Symbolic Links on the Command Line
Using Zip and Tar from the Command Line
Finding Files from the Command Line
Grep is your friend
Using Shortcuts from the Command Line
Setting Aliases in the Bash Shell
Working with the MySQL database
Using SSH and SCP to Access Remote Servers

Drupalize.Me also has a whole series of free videos on working with VI/VIM -- an extremely powerful text editor that is available on virtually all flavors of Unix/Linux/OSX systems...
Intro to the VI/VIM Editor
Editing Documents with VI/VIM
More Editing Tricks with VI/VIM
All About Shortcuts in VI/VIM

Looking for support? Visit the forums, or join #drupal-support in IRC.


asghar’s picture

For moving Drupal site code from one server to other rsync is good but scp is easy and very useful.

Copy file from local to remote via scp command
scp /your/file/ user@host:/path/to/place/directory/

Copy file from remote to local system via scp

scp user@host:/path/to/place/directory/ .

Dot for current directory location. If you want to move directory then use -r argument

Local to remote
scp -r /your/directory user@host:/path/to/place/directory/

Remote to local
scp -r user@host:/path/to/place/directory .
Dot for current directory location.