Loading...

Knowledge Base
Save up to  70% off.  Start your website today!

Linux Shell Basics

Here are some basic commands to help you get started with Linux Shell commands.

Please remember we do not offer support for shell via live chat or phone. You can use one of the numerous websites which offer to teach SSH (secure shell) or Unix/Linux command line, such as http://ss64.com/bash/.

Below are some shell basics:


Accessing Shell

To use the following commands, you will need a terminal. Alternatively, you can use a program such as PuTTY or WinSCP.

On some hosting plans, such as Shared and Reseller, you may need to have SSH access activated first. Shell access is turned off by default on most accounts to help prevent unauthorized access. For complete details, please read:


Logging into the Server


Using PuTTY

With a program like PuTTY, logging in is simple. Just type your domain name or server IP address in the Host field, enter 22 for the port, then click Open.

Note: Shared hosting plan must use port 2222. Also, if you change the port number for SSH, use that port number instead of 22.

Shared hosting

In terminal, type the following:

ssh USER@SERVER -p 2222

Now you will be prompted for your primary user's password. You may not see the characters as you type them or when you paste from your clipboard; that is normal.


VPS and Dedicated hosting

In terminal, type the following:

ssh USER@SERVER -p 22

Be sure to replace USER with your primary username, and replace SERVER with the server IP or your domain name.


Viewing Directories

In terminal or PuTTY, type the following to view a listing of all the files and subdirectories, complete with details:

ls -la


Alias/Shortcut

Shared and Reseller servers have a shortcut (alias) for the same detailed list.

ll


Alias/Shortcut Setup

The shortcut (alias) may not be set up on all servers, such as VPS or Dedicated. It can be set up with the command:

alias ll='ls -la'


Moving between Folders

The following command takes you inside the specified directory where you can list the files to see what's inside. Be sure to replace FOLDER with the actual directory name.

cd FOLDER

The following command allows you to navigate directly into the file structure with the direct file path. Be sure to replace FOLDER/PATH/ETC with the actual directory name.

cd FOLDER/PATH/ETC


Moving between Directories

To move up one directory, use the following:

cd ..

To move back to the previous directory, use the following:

cd -

File Management


View Files

The following command allows you to view a file without any possibility of modifying it. Be sure to replace FILE.NAME with the desired file name. 

cat FILE.NAME


Creating Files

The following command creates a file if one does not exist or changes the timestamp on an existing file. Be sure to replace FILE.NAME with the desired file name.

touch FILE.NAME


Deleting Files

The following command permanently removes files; so use with caution. Be sure to replace FILE.NAME with the desired file name.

rm FILE.NAME


Editing Files

These commands allow you to edit a file, so use them with caution. Be sure to replace FILE.NAME with the desired file name.

There are other ways to edit files besides using shell. Select an editor you are comfortable with before making changes to your files.
pico FILE.NAME

or

nano FILE.NAME

Accessing MySQL

The following command takes you to MySQL where you can enter SQL syntax. Be sure to replace USER with your primary username or database user, and replace DB_NAME with the actual database name.

mysql -u USER -p DB_NAME

After using this command, you will be prompted for your primary password or the database user's password. Once logged into MySQL, the mysql> prompt will appear.


View Databases

At the mysql> prompt, type the following:

show databases;


View Tables

At the mysql> prompt, type the following:

use DB_NAMEshow tables;

Be sure to replace DB_NAME with the actual database name, hit enter, then type the rest of the command.


View Table Attributes

At the mysql> prompt, type the following command:

use DB_NAMEdescribe TABLE;

Be sure to replace DB_NAME with the actual database name, hit enter, then type the rest of the command, replacing TABLE with the actual table name.


MySQL Queries

At the mysql> prompt, type the SQL query as you normally would.


Exiting MySQL

exit


Exporting a Database

The following command must be entered in the normal prompt, not the mysql> prompt. Be sure to exit MySQL if you are in it.

mysqldump -u USER -p DB_NAME > FILE.sql

Be sure to replace USER with your primary username or database user; replace DB_NAME with the actual database name; replace FILE with the desired backup file name. A prompt for your password will appear shortly after.


Importing a Database

This must be done in the normal prompt, not the mysql> prompt. Be sure to exit MySQL if you are in it.

mysql -u USER -p DB_NAME < FILE.sql

Be sure to replace USER with your primary username or database user, replace DB_NAME with the actual database name, and replace FILE with the known backup file name.  A prompt for your password will appear shortly after.

Did you find this article helpful?

 
* Your feedback is too short

Loading...