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.
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.
You can also issue the id –un command to get the same output.
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.
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:
$ cd test
If you want to move back one level, type two dots after the cd command as shown below:
$ cd ..
To move to the root of your Linux server, type cd followed by a space and a forward slash:
$ cd /
The ls command is used to list directory contents. The list includes all files, folders and symbolic links within the directory:
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
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:
$ 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
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:
$ 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
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:
$ 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:
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:
$ 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
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.
$ 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 ..
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:
$ mv demo3.txt demo4.txt
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:
$ man mv
MV(1) User Commands MV(1) NAME mv - move (rename) files SYNOPSIS mv [OPTION]... [-T] SOURCE DEST mv [OPTION]... SOURCE... DIRECTORY mv [OPTION]... -t DIRECTORY SOURCE... DESCRIPTION Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. Mandatory arguments to long options are mandatory for short options too.
You can use the Linux echo command to display text on your terminal window or redirect the output to a file.
$ echo 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 *
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
$ cat text1.txt
sample text additional sample text
To concatenate the text of two files, use the syntax below:
$ cat text1.txt text2.txt
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:
$ more text1.txt
sample text additional sample text
You can use the grep command to search text on a file name:
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.
To see a list of commands that have been executed by the current logged in user, use the history command.
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:
This is an administrative command used to change the ownership of Linux files.
$ 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:
You can change the permissions of a file by issuing a chmod command:
$ 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.
To see the total available and used RAM as well as swap space, use the 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.
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.
$ df –f
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.
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:
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"
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.
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:
$ sudo reboot
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.
Alibaba Clouder - August 11, 2020
Alibaba Cloud Community - September 23, 2021
Alibaba Clouder - February 14, 2018
Alibaba Clouder - October 16, 2019
Alibaba Clouder - July 8, 2020
Alibaba Clouder - June 5, 2019
An online computing service that offers elastic and secure virtual cloud servers to cater all your cloud hosting needs.Learn More
Apsara Stack Agility Elastic Compute Service (Alibaba Cloud ZStack) is a light-weight hybrid cloud solution.Learn More
A convenient and secure cloud-based Desktop-as-a-Service (DaaS) solutionLearn More
Powerful parallel computing capabilities based on GPU technology.Learn More
More Posts by francisndungu