Linux Shell Basics

Linux Shell Basics

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

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 and Reseller plans must use port 2222. Also, if you change the port number for SSH, use that port number instead of 22.

Shared and Reseller

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.

Dedicated and VPS

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 a file

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_NAME
show 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_NAME
describe 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.

Leave a Reply

Your email address will not be published. Required fields are marked *