Linux Shell Basics
Posted by ASO Admin on 05 February 2020 01:54 PM
|
|
Here are some basic commands to help you get started with Linux Shell commands. Shell is available on your account by default. If you have questions about your access you can create a ticket to speak with Support about it. Access Shell To use the following commands, you will need a Terminal (Mac or Linux-based) or Command Prompt (Windows). Alternatively, you can use a program such as PuTTY or WinSCP. Log Into the ServerUsing PuTTYWith 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. Shared and ResellerIn Terminal or Command Prompt, 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. 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, which is totally normal. Dedicated and VPSIn Terminal or Command Prompt, 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. 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, which is totally normal. View DirectoriesIn Terminal or PuTTY, type the following to view a listing of all the files and subdirectories, complete with details: ls -la
Alias/ShortcutShared and Reseller servers have a shortcut (alias) for the same detailed list. ll
Alias/Shortcut SetupThe 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'
Navigate DirectoriesMoving Between FoldersThe 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 DirectoriesTo move up one directory, use the following: cd ..
To move back to the previous directory, use the following: cd -
File ManagementView a FileThe 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
Create a FileThe 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
Delete a FileThe following command permanently removes files; so use with caution. Be sure to replace FILE.NAME with the desired file name. rm FILE.NAME
Edit a FileThese commands allow you to edit a file, so use them with caution. Be sure to replace FILE.NAME with the desired file name. Select an editor you are comfortable with before making changes to your files, in this case pico or nano editors. pico FILE.NAME
or nano FILE.NAME
Access MySQLThe 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 DatabasesAt the mysql> prompt, type the following: show databases;
View TablesAt the mysql> prompt, type the following: use DB_NAME
Be sure to replace DB_NAME with the actual database name, hit Enter or Return, then type the rest of the command. View Table AttributesAt the mysql> prompt, type the following command: use DB_NAME
Be sure to replace DB_NAME with the actual database name, press Enter or Return, then type the rest of the command, replacing TABLE with the actual table name. MySQL QueriesAt the mysql> prompt, type the SQL query as you normally would. Exit MySQLexit
Export a DatabaseThe 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 and replace FILE with the desired backup file name. A prompt for your password will appear shortly after. Importing a DatabaseThis 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. | |
|