How to Manage Your Alibaba Cloud Linux Server from the Command Line Interface (CLI)

By Francis Ndungu, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Alibaba Cloud offers flexible Elastic Compute Service (ECS) products for running powerful Virtual Private Servers (VPS). With their simple and transparent pricing starting from $4.50/month, you can setup a remote server to cater for all your cloud hosting needs.

You can deploy an Alibaba Cloud ECS instance in a few minutes right from their friendly console and scale resources up or down depending on your cloud computing needs.

Alibaba Cloud infrastructure runs with the latest Intel CPU’s, fast RAM, accelerated SSD, and unrivalled security bundled with intelligent DDoS protection. You can choose from their wide-range of Operating System images for accelerated application deployment.

Since most of the world’s powerful servers run on Linux, we will focus on managing your Alibaba Cloud Linux ECS instance from the Command Line Interface (CLI).This guide works for all Linux distributions and covers most commands for managing your Alibaba Cloud VPS instance.

Prerequisites

  • A valid Alibaba Cloud account. If you don’t have one, try Alibaba Cloud today and get $300 worth in Free Trial.
  • An ECS instance running any Linux distribution (e.g. Ubuntu, Centos, Debian)
  • An SSH username and password for the ECS instance.
  • For the sake of simplicity we will be using a hypothetical user ‘james’.

1: Linux whoami Command

To start exploring your Alibaba Cloud ECS VPS, you need to SSH to your server. You will need a command line tool like PuTTY (Windows) or terminal window in Linux or Mac. Also, get the public IP address, username and password associated with your ECS instance.

The first command that you need to know about is whoami. This command lists the username of the currently logged in user in a SSH session.

Output

You can also issue the id –un command to get the same output.

2: Linux pwd Command

The Linux pwd (Print Working Directory) command displays the full path name of the working directory. Please note in Linux, commands and filenames are case sensitive.

Therefore use the correct case otherwise you will get an error.

Output

3: Linux cd Command

In Linux, the cd command stands for Change Directory. It is one of the most useful commands because it allows users to move around or change focus from one directory to another.

For instance if the home directory for user ‘james’ contains a test directory, you can navigate to it using the command below:

Output

If you want to move back one level, type two dots after the cd command as shown below:

Output

To move to the root of your Linux server, type cd followed by a space and a forward slash:

Output

4: Linux ls Command

The ls command is used to list directory contents. The list includes all files, folders and symbolic links within the directory:

Output

To display more information about the directory content, use the -l option as shown below:

Output

5: Linux mkdir Command

The mkdir command is used for creating directories on a Linux machine. Creating folders is a common task in Linux administration.

To create a directory named ‘demo’, use the command below:

If we issue the ls -l command one more time, the demo directory should be listed on our home folder:

Output

6: Linux touch Command

Just like the way we created a directory, we can create a file using the touch command. For instance, to create a file named text1.txt, the syntax should be as follows:

You always use run the ls -l command to confirm the presence of newly created files:

Output

7: Linux rmdir Command

You can remove an empty directory in Linux by issuing a rmdir command. For instance, to remove the ‘demo’ folder that we created above, the command should be as follows:

Please note: You cannot delete a directory if it is not empty using the rmdir command. You have to use the rm -r command as discussed below:

8: Linux rm Command

The rm command is used to remove objects including files, directories and symbolic links in Linux.

To remove the file you created above named ‘text1.txt’, use the command below:

To remove a directory together with its contents, issue the command below:

For instance, to remove the non-empty ‘demo’ folder, the command should be as follows:

9: Linux cp Command

Sometimes, you may need to copy a file or a bunch of files in Linux. This can be done using the cp command. The basic syntax is shown below:

For instance, let’s create a file named ‘demo1.txt’ and try to copy it.

Once the file is created we can copy it over to ‘demo2.txt’ using the syntax below:

We can confirm the presence of the two files using the ls command:

Output

You can also copy multiple files. First create a directory named ‘demos’:

You can them move ‘demo1.txt’ and ‘demo2.txt’ file using the syntax below:

The above syntax will copy all files that end with a ‘.txt’ extension

To confirm if the copying was successful, you need to cd to the demos directory and issue the ls -l command to list the directory contents:

Output

Remember to go back to the working directory and navigate out of the demo directory by typing:

10: Linux mv Command

Linux mv command is used to move files and directories from one location to another. If you try to move the file to the same directory, the file will be renamed instead.

For instance, if you have a file named demo3.txt and you issue the command to move it to demo4.txt, the file will be renamed.

The mv command has the below syntax:

Example:

11: Linux man command

This command displays the user manual page and shows more information about using a command. For instance, if you issue the man command together with a mv command, you will get the following output:

Output

12: Linux echo Command

You can use the Linux echo command to display text on your terminal window or redirect the output to a file.

Output

If you want to redirect the output to a file name text1.txt, use the syntax below:

Please note the file will be created if it’s not there.

Also to append more text to an existing file, use to greater than symbol as shown below:

You can also print all the contents of a directory using the echo command to supplement the ls command as shown below

13: Linux cat Command

The cat command reads files and displays the content on a standard output. You can also concatenate information from multiple files and display the combined output on the screen.

For instance to view the content of the text1.txt file that we created above, we can use the command below

Output

To concatenate the text of two files, use the syntax below:

14: Linux more Command

The more command displays the content of a file one screen at a time. This is a very powerful command for displaying contents of files with large output that cannot fit on the screen.

To view the content of a file named text1.txt, use the command below:

Output

15: Linux grep Command

You can use the grep command to search text on a file name:

The general syntax is:

For example, let’s search for the word ‘sample’ in a file named ‘text1.txt’:

Output

As you can see above, our search keyword was found on the file and is highlighted in red.

16: Linux history Command

To see a list of commands that have been executed by the current logged in user, use the history command.

Sample Output

The list has line numbers. You can use the syntax below to repeat a command from the history:

For instance to run command number 5, ls -a, we can use the command below:

17: Linux chown Command

This is an administrative command used to change the ownership of Linux files.

Syntax:

For instance, if you have a directory named demo10 but you want it to be owned by a different user named ‘joseph’, use the syntax below:

First create the directory:

Then, change ownership:

If you run the command ls -l you will see the directory is now owned by the user ‘joseph

Please note you must be have the correct privilege to change the ownership of a file:

18: Linux chmod Command

You can change the permissions of a file by issuing a chmod command:

General syntax

For instance, to issue full permissions for all users to the demo10 directory, we can use the command below:

Please note you must be the owner of the file/directory to make changes permissions, otherwise, run the command using sudo.

19: Linux free Command

To see the total available and used RAM as well as swap space, use the free command.

Output

This command is useful when troubleshooting memory related issue on your Alibaba Cloud ECS VPS.

20: Linux df Command

Use the df command to list the total amount of available disk space. If you are running out of space or probably want to scale up, you can monitor the disk usage using this command.

Sample Output

From the above report, the available disc space is 20 gigabytes.

21: Linux date Command

You can view and manipulate date and time in a Linux server using the date command. To view the current system date, use the command below:

Output

To set your server date and time manually, use the command below:

Example

22: Linux sudo Command

In Linux sudo is an acronym for ‘super user do’. This command is useful when running commands that need elevated privileges (e.g. changing date) especially when installing programs or changing configuration files.

23: Linux reboot Command

Apart from the flexibility of installing custom applications, an Alibaba Cloud ECS VPS allows you to reboot your system especially if you want to apply new changes to the system. To do this, use the command below:

Conclusion

Those are the basics commands that are very helpful when managing your Alibaba Cloud ECS instance running a Linux distribution. We have covered major commands which will be very useful in administering your server.

You can also dig deeper and learn more commands related to the Linux distribution on the Alibaba Cloud Getting Started guides. As always, you can test Alibaba Cloud service by creating an account. Sign up now to try out Alibaba Cloud products and enjoy $300 worth in Free Trial.

Reference:

https://www.alibabacloud.com/blog/how-to-manage-your-alibaba-cloud-linux-server-from-the-command-line-interface-%28cli%29_593878?spm=a2c41.11858623.0.0

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.