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

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.

$ whoami
james

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.

$ pwd
/home/james

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.

$ cd test
$ james@server1:~/test$
$ cd ..
$ james@server1:~$
$ cd /
james@server1:/$

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:

$ ls
$mail  test
$ 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

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

$ mkdir demo
$ 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

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
$ 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

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

8: Linux rm Command

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

$ rm text1.txt
$ rm -r
$ rm -r demo

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:

$ cp
$ touch demo1.txt
$ cp demo1.txt demo2.txt
$ 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
...
$ mkdir demos
$ cp *.txt demos/
$ 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
$ cd ..

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.

$ mv
$ mv demo3.txt demo4.txt

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:

$ 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.

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.

$ echo sample text
sample text
$ echo sample text > text1.txt
$ echo additional sample text >> text1.txt
$ echo *

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.

$ cat text1.txt
sample text
additional sample text
$ cat text1.txt text2.txt

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.

$ more text1.txt
sample text
additional sample text

15: Linux grep Command

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

$ grep 'keyword'
$ grep sample text1.txt
sample text
additional sample text

16: Linux history Command

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

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

17: Linux chown Command

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

$ chown .
$ mkdir demo10
$ sudo chown joseph.joseph demo10
...
drwxrwxr-x 2 joseph joseph 4096 Jul 16 10:08 demo10
...

18: Linux chmod Command

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

$ chmod options
$ chmod 777 demo10

19: Linux free Command

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

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.

$ 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

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:

$ date
Mon Jul 16 10:26:39 EAT 2018
$ date --set="YYYYMMDD HH:MM"
$ sudo date --set="20180716 10:30"

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:

$ sudo reboot

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

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