Useful Terminal Commands and More For Design and Development

by: Preston Schmidt

Exporting A Database via SSH

Open Terminal and enter the following command:

ssh (enter)

(enter password when prompted)

Now that you have SSH access, use the following command to perform a SQL dump:

mysqldump -u username -p  databasename > filenameyouwant.sql (enter)

(enter password when prompted)

You will then need to use SFTP or SCP command to download the file to your local hard drive.

Importing sql File To Local Database

Open Terminal and enter the following command:

mysql -u -root -p  databasename < path/to/file.sql (enter)

(enter password when prompted)

or you can use...

mysql -u root -p (enter)

(enter password when prompted) then

use databasename (enter) then

source path/to/file.sql (enter)

RSYNC File Transfer Protocol

rsync is a method to transfer files via ssh through terminal, there is a standard syntax for writing the command

rsync -avz /source/path/to/file ssh username@domain:/path/to/destination/

Writing the command like this allows you to take a file from your local computer and sync it to a remote server location. rsync can be used in this way, or used completely local to sync directory. The important part of writing the command is that you call rsync first, follow it with the appropriate 'flags', in this case and most -avz will work, and that the source location comes first followed by the destination location.

Securely Copy A File From Server

SCP is a method to copy a file from a secure server location to your local hard drive. Open Terminal, cd into the directory where you want to download the file, then enter the following command:

scp (copies given file from server to the current local directory)

The "path to your file" is the location of the file on the server, which is always written from the root directory on the sever.

Common Git Commands:

git clone (use this to copy a site from a repo to your computer)

git add (add a modified file to the “staging” area)

git commit -m “put reason message here” (commit an added file in git so you can push it)

git push (pushes a committed file up to a server for deployment)

git rm —cached (removes a file from your .git file/repo and does not track it)

git stash (hides any un-committed file changes on your local computer)

Other Terminal Commands

To show hidden files in your finder window enter the command:

defaults write AppleShowAllFiles TRUE

To locate a file on your computer enter the command:

find /path/to/directory -name "what you're looking for in quotes"

just use a / to search your entire computer

Bash Profile Aliases Equals Convenience

Writing aliases in your .bash_profile file can save a lot of time and typing in Terminal and it's really easy to write an alias for a command you type regularly. The file is located just under your user name on your system and you can open and edit it in any typical text editor. On a new line you can write the following to create an alias:

alias aliasname="the command you would normally type in Terminal"

A good example would be:

alias sqlup="sudo /usr/local/mysql/support-files/mysql.server start"

With this alias all you have to type in Terminal is "sqlup" to start your local sql service. If you do not have a .bash_profile file already, you can create one in Terminal with these:

cd ~/ (enter)

touch .bash_profile (enter)

Now you can edit the file and add some aliases!


Video, Web, and Design Agency