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.


  • 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

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.

$ whoami



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

2: Linux pwd Command

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

$ pwd



3: Linux cd Command

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

$ cd test


$ james@server1:~/test$

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

$ cd ..


$ james@server1:~$

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

$ cd /



4: Linux ls Command

$ ls


$mail  test

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

$ ls –l


drwx------ 3 james james 4096 Jul  1 11:49 mail
drwxrwxr-x 2 james james 4096 Jul 16 08:23 test

5: Linux mkdir Command

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

$ mkdir demo

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

$ ls –l


drwxrwxr-x 2 james james 4096 Jul 16 09:07 demo
drwx------ 3 james james 4096 Jul 1 11:49 mail
drwxrwxr-x 2 james james 4096 Jul 16 08:23 test

6: Linux touch Command

$ touch text1.txt

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

$ ls -l


drwxrwxr-x 2 james james 4096 Jul 16 09:07 demo
drwx------ 3 james james 4096 Jul 1 11:49 mail
drwxrwxr-x 2 james james 4096 Jul 16 08:23 test
-rw-rw-r-- 1 james james 0 Jul 16 09:08 text1.txt

7: Linux rmdir Command

$ rmdir demo

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

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

$ rm text1.txt

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

$ rm -r

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

$ rm -r demo

9: Linux cp Command

$ cp

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

$ touch demo1.txt

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

$ cp demo1.txt demo2.txt

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

$ ls –l


-rw-rw-r-- 1 james james 0 Jul 16 09:10 demo1.txt
-rw-rw-r-- 1 james james 0 Jul 16 09:11 demo2.txt

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

$ mkdir demos

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

$ cp *.txt demos/

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:

$ cd demos
$ ls -l


-rw-rw-r-- 1 james james 0 Jul 16 09:13 demo1.txt
-rw-rw-r-- 1 james james 0 Jul 16 09:13 demo2.txt

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

$ cd ..

10: Linux mv Command

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:

$ mv


$ mv demo3.txt demo4.txt

11: Linux man command

$ man mv


MV(1)                                                 User Commands                                                 MV(1)
mv - move (rename) files
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.

12: Linux echo Command

$ echo sample text


sample text

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

$ echo sample text > text1.txt

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:

$ echo additional sample text >> text1.txt

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

$ echo *

13: Linux cat Command

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

$ cat text1.txt


sample text
additional sample text

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

$ cat text1.txt text2.txt

14: Linux more Command

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

$ more text1.txt


sample text
additional sample text

15: Linux grep Command

The general syntax is:

$ grep 'keyword'

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

$ grep sample text1.txt


sample text
additional sample text

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

16: Linux history Command

$ history

Sample Output

1    ls -a
2 rm *.txt
3 rm -r demos
4 rm test
5 ls -a
6 ls
7 ls -p

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:

$ !5

17: Linux chown Command


$ chown .

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:

$ mkdir demo10

Then, change ownership:

$ sudo chown joseph.joseph demo10

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

drwxrwxr-x 2 joseph joseph 4096 Jul 16 10:08 demo10

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

18: Linux chmod Command

General syntax

$ chmod options

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

$ chmod 777 demo10

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

$ free –h


total        used        free      shared  buff/cache   available
Mem: 985M 302M 72M 2.3M 610M 496M
Swap: 0B 0B 0B

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

20: Linux df Command

$ df –f

Sample Output

Filesystem      Size  Used Avail Use% Mounted on
udev 464M 0 464M 0% /dev
tmpfs 99M 640K 98M 1% /run
/dev/vda1 25G 3.4G 20G 15% /
tmpfs 493M 0 493M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 493M 0 493M 0% /sys/fs/cgroup
tmpfs 99M 0 99M 0% /run/user/1000

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

21: Linux date Command

$ date


Mon Jul 16 10:26:39 EAT 2018

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

$ date --set="YYYYMMDD HH:MM"


$ sudo date --set="20180716 10:30"

22: Linux sudo Command

23: Linux reboot Command

$ sudo reboot


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.


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