There was a problem loading the comments.

Linux Shell basics

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Please remember we do not offer support for "how to use shell" via live chat or phone.

Please consult with public documentation for how to use SSH (secure shell) or Unix/Linux command line.

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.

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

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.

Typically, this is a known shortcut for the same detailed list:

ll

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 allows you to view a file without any possibility of modifying it: (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

These 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. You will be prompted for your password. (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.)

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. You will be prompted for your password. (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.)

mysql -u USER -p DB_NAME < FILE.sql

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


Share via
Did you find this article useful?  

Related Articles


Comments

Add Comment

Replying to  

CAPTCHA
© Osirion System Technologies