HostGator.com » Support Portal

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 "how to use shell" via live chat or phone. You can ask for shell help via email to support@hostgator.com or use one of the numerous websites which offer to teach shell.

Please consult with public documentation for how to use SSH (secure shell) or Unix/Linux command line. One useful resource is http://ss64.com/bash/ and plenty of other ones can be found through the search engines.

Here are some basics you are sure to need!


Accessing Shell

You are going to need a terminal where you can type command line. Alternatively, you can use a program such as PuTTY or WinSCP.

On some plans, such as shared and reseller plans, you may need to have SSH access activated first. On most accounts shell access is turned off by default to help prevent authorized access. Please read our article on How do I get and use SSH access? for complete details.


Login to your server

With a program like PuTTY, this is super easy. Just type your domain name or server IP address for the Host field, and 22 for the Port, then click the Open button.

Note: Shared and reseller plans must use port 2222. Also, if you change the port number for SSH, then use that port number instead of 22.

In terminal, type this: (Be sure to replace USER with your primary username, and replace SERVER with the server IP or your domain name.)

ssh USER@SERVER -p 22

For shared and reseller plans, you would have to use:

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.


View directory

In terminal or PuTTY, type this:

ls -la

Now you see a list of all the files and subdirectories, along with details.

Some of our servers, like shared & reseller servers have a shortcut (alias) for the same detailed list:

ll

This shortcut (alias) may not be setup on all servers, such as VPS or dedicated. You can setup this alias with the command: alias ll='ls -la'


Navigate directories

This command takes you inside the named directory, where you can list the files to see what's inside: (Be sure to replace FOLDER with the actual directory name.)

cd FOLDER

You can move deep into the file structure if you know the path: (Be sure to replace FOLDER/PATH/ETC with the actual directory path.)

cd FOLDER/PATH/ETC

You can easily move up one directory with this:

cd ..

You can easily move back to the previous directory you were in with this:

cd -

View a file

This command allows you to view a file without any possibility of modifying it: (Be sure to replace FILE.NAME with the actual file name.)

cat FILE.NAME

Create a file

This 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

Delete a file

This command permanently removes files, so use with caution: (Be sure to replace FILE.NAME with the desired file name.)

rm FILE.NAME

Edit a file

These commands allow you to edit a file, so be careful: (Be sure to replace FILE.NAME with the desired file name.)

pico FILE.NAME

or

nano FILE.NAME

There are other popular editors, and you must chose which editor you are comfortable with.


Access MySQL

This command takes you to MySQL, where you can type 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

Now you will be prompted for your primary password or database user's password.

Once logged into MySQL, you will see a mysql> prompt.

View Databases

At the mysql> prompt, type this:

show databases;

View Tables

At the mysql> prompt, type this: (Be sure to replace DB_NAME with the actual database name, hit Enter, then type the rest.)

use DB_NAME
show tables;

View Table Attributes

At the mysql> prompt, type this: (Be sure to replace DB_NAME with the actual database name, hit Enter, then type the rest while replacing TABLE with the actual table name.)

use DB_NAME
describe TABLE;

MySQL queries

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

Exit MySQL

exit

Export a Database

This must be done in the normal prompt, not the mysql> prompt. Just be sure to exit MySQL if you are in it. (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 desired backup file name.) You will be prompted for your password.

mysqldump -u USER -p DB_NAME > FILE.sql

Import a Database

This must be done in the normal prompt, not the mysql> prompt. Just be sure to exit MySQL if you are in it. (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.) You will be prompted for your password.

mysql -u USER -p DB_NAME < FILE.sql

For more commands you will need, please refer to our related article, "Shell Commands".


Your comments help us keep the knowledge base updated. This is not a medium for support. If you have questions or need help, please contact us via email, phone or live chat for fast assistance.

Post Comment