VPS terminal commands: Understanding the basics

VPS terminal commands: Understanding the basics

About 90% of the Internet is powered by Linux servers. If you want to manage or deploy applications on these Linux servers, such as a virtual private server (VPS), you need to have a decent understanding of Linux command line basics. But, for beginners, using the Linux terminal, which is otherwise known as the shell, can be daunting, as there’s a veritable ocean of commands to learn and understand. Let’s take a look at some of the key VPS terminal commands, starting with the basics.

PWD command

The pwd is a command line utility tool that prints the current working directory to the standard output. The output contains the full system path of current working directory. By default, pwd ignores the symbolic link,s but with proper option, you can look at the full physical path of the current working directory.

$ cd /home/dd/Pictures
$ pwd

Use the P switch to find the full physical path if you have traversed inside a directory which is symbolically linked.

$ pwd -P

CD command

The cd command stands for “change directory,” and it helps you change the shell’s current working directory.

To navigate to the particular folder with cd command, pass the folder path as the parameter.

$ cd /home/dd/Documents
$ pwd

With no options, the cd command changes the working directory to user’s home directory.

$ cd
$ pwd

Another way of doing the same i.e to navigate to the home directory quickly is to use the ~ switch.

$ cd ~
$ pwd

You may want to navigate to the previous working directory without typing the entire folder path again. cd - does exactly that.

$ cd /home/dd/Documents
$ pwd
$ cd -
$ pwd

MV Command

The mv command is another utility command that moves files and folders from one location to another. The mv command can move a single file, multiple files, and directories.

To move a single file using mv, pass the name of the file that needs to be moved as a first parameter and the new file name as a second parameter. In this case mv commands renames the filename.

$ mv a.txt b.txt
// renames the file a.txt to b.txt
$ mv some_directory new_directory
// renames the folder some_directory to new_directory

To move a group of files to a folder, pass the name of the files followed by destination folder name with cd command.

$ mv a.txt b.txt c.txt some_directory
$ mv *.txt some_directory

By default the mv command overwrites the destination file. To prompt before overwriting the destination file, use the -i option.

$ mv -i a.txt b.txt
mv: overwrite 'b.txt' ?

RM Command

The rm command is used to delete or remove files and directories. Be cautious when you use the rm command because once a file or directory is deleted, you cannot recover it later.

To delete a single file, just pass the name of the file along with the rm command.

$ rm file.txt

It is also possible to delete multiple files at one go.

$ rm file1.txt file2.txt image.png

To delete a directory, use the -r switch, which means to delete all files and folders recursively.

$ rm -r some_directory

To perform deletion safely and interactively, use the -i switch, which prompts before each delete action is performed.

$ rm -i file.txt
rm: remove regular file ‘file.txt’? y

MKDIR command

mkdir command speaks for itself—time to create a directory! To create a directory, pass the name of the directory along with mkdir command.

$ mkdir test_directory

Sometimes, you need to create a nested directory structure. Rather than creating directories one by one, use the -p option to create entire directory structure.

$ mkdir -p dir1/dir2/dir3
$ tree dir1
└── dir2
    └── dir3

If you want mkdir to give details of what operation it is performing in the process of creating directories, use the -v switch.

$ mkdir -v -p dir_1/dir_2/dir_3
mkdir: created directory 'dir_1'
mkdir: created directory 'dir_1/dir_2'
mkdir: created directory 'dir_1/dir_2/dir_3'

LS Command

ls is the list command in Linux, and it shows full list of files or contents of a directory. Just type ls and press the Enter key. The entire contents of the directory will be shown.

$ ls

Use the -l switch to show the list of files of current directory in a long list format.

$ ls -l

In Linux, hidden files start with a . (dot) symbol and are invisible to the regular directory. The -a switch will list entire contents of current directory including the hidden files.

$ ls -la

Sometimes you may want to get the details of a directory rather than its content. To get the details of a directory, use -d option. For example, if you use ls -l /home, it will display all the files under /home directory. But if you want to display the information about the /home directory then use -ld option as shown below.

$ ls -ld /etc
drwxr-xr-x 162 root root 12288 Jun 18 09:42 /etc

TOUCH Command

The touch command is a utility in Linux that is used to modify the access/modification timestamps of files. It is also used to create a new file quickly.

To simply create a blank file with touch command, use the following syntax.

$ touch a.txt
// Creates a file by the name a.txt
$ touch a.txt b.txt c.txt
// Creates multiple files
$ touch {A..Z}.txt
// Creates files with names from A.txt to Z.txt

If you want to update the access time of an existing file to the current time without creating it, use the -c switch. If the file exists, touch will update the access time, otherwise it will do nothing.

$ touch -c a.txt

To change the access time of a file use the -a switch with touch command.

$ touch -a a.txt

To change the modification time of a file use the -m switch with touch command.

$ touch -m a.txt

To change the both the access and modification times use the -a and -m switches together.

$ touch -am a.txt

To change the access and modification time to a specific datetime, use the -t switch and specify the datetime in the format [[CC]YY]MMDDhhmm[.ss].

$ touch -c -t 1806181015 a.txt

Once you have updated the access or modification time using touch command, verify the access/modification time with stat command.

$ stat touch.txt
File: 'touch.txt'
Size: 1838          Blocks: 24         IO Block: 4096   regular file
Device: 2fh/47d    Inode: 4471138     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/dwijadas)   Gid: ( 1000/dwijadas)
Access: 2018-06-19 12:38:26.274344027 +0530
Modify: 2018-06-19 12:38:21.120301504 +0530
Change: 2018-06-19 12:38:21.152289411 +0530
Birth: -

LESS Command

The less command is used to view files and is similar to the more command, but allows navigation in both forward and backward direction. less does not need to read entire input file before processing, so with large input file it starts faster than other text editors like vi.

To view a file using less, just pass the filename along with the less command.

$ less a.txt

You can now navigate to the file using the navigation keys. Few of them are given below:

  • [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigate the file.
  • [Space bar]: Next page.
  • b: Previous page.
  • ng: Jump to line number n. Default is the start of the file.
  • nG: Jump to line number n. Default is the end of the file.
  • /pattern: Search for pattern. Regular expressions can be used.
  • G: go to the end of file
  • g: go to the start of file
  • q or ZZ: exit the less pager
  • 10j: Jump 10 lines forward.
  • 10k: Jump 10 lines backward.
  • Ctrl+G: show the current file name along with line, byte and percentage statistics.


You might be interested to know which Linux distribution or the OS version number you are using. One of the option to find this information is to use the lsb_release command. The lsb_release command displays LSB (Linux Standard Base) information about your specific Linux distribution.

To get the LSB distribution information, use the following command.

$ lsb_release

To display the single line text distribution, use -d switch.

$ lsb_release -d

To display the release number of the distribution, use -r switch.

$ lsb_release -r

To display the codename according to the distribution release, use -c switch.

$ lsb_release -c

The lsb_release command with -a option displays all the information for the Linux OS you’re using:

$ lsb_release -a

UNAME Command

The uname command is used to display the software- and hardware-related information such as the kernel release or version, processor type, hostname, etc., in your Linux system, and is built-in with the shell.

To display all the information of a system, use -a switch with uname command.

$ uname -a

The output of the above command will display following information.

  • Kernel name
  • Hostname
  • Kernel release
  • Kernel version
  • Machine hardware name
  • Processor type
  • Hardware platform
  • Operating system

Rather than displaying all the information, it is also possible to get information about your point of interest with the following switch along with uname command.

Switch Switch description
-s Display the kernel name
-n Display the hostname
-r Display the kernel release
-v Display the kernel version
-m Display the machine hardware name
-p Display the processor type or ‘unknown’
-i Display the hardware platform or ‘unknown’
-o Display the name of operating system


history is a very useful command that displays all the commands that have been used recently. In its simplest form, just run the history command with no optiosn and it will print out the bash history of the current user in the terminal.

$ history
1 cp a.txt b.txt
2 ssh [email protected]
3 ping 123.456.78.9
4 ssh [email protected]
5 rm /home/dd/Documents/a.txt

The output of history command displays line numbers. It is also possible to repeat a command by specifying its line number.

$ !3

For better view of the output of history command, filter it with less command to view the output one page at a time.

$ history | less

Alternatively, if you want to view just the last 10 commands, filter the output of history with tail command:

$ history | tail

To view the last 30 commands you have entered, pass the number i.e 30 as a parameter of history command.

$ history 30

The history of commands is stored in the file ~/.bash_history by default. If you run cat ~/.bash_history, it will display all the commands that you have entered but will not include the line numbers or formatting.

PS Command

The process status command (ps) displays information about active processes in your system. It is generally used to find process identifier number and supports searching of processes by user, group, process id or executable name.

In the simplest form, ps command displays the running processes for a user within the terminal window. To invoke it, just type ps in the terminal.

$ ps
PID     TTY        TIME       CMD
14591   pts/1      00:00:00   bash
14891   pts/1      00:00:00   ps

The output of the ps command will show the rows of data containing the following information.

  • PID
  • TTY
  • Time
  • Command

To view all the running processes in your system, use either of the following commands.

$ ps -A
$ ps -e

To view more information about processes, pass the -F option with the ps command.

$ ps -e -F

To find daemon processes running in your system, use the -d switch.

$ ps -d

You can also find information about specific process by filtering the output of ps command with grep.

$ ps -d | grep httpd

To view all processes owned by a user, use -u switch by specifying either user ID or user name.

$ ps -u dd

A common and convenient way of using ps to fetch more complete information about the processes running in the system is to use the following command.

$ ps aux

a = Displays processes for all users.
u = Displays user/owner for each process.
x = Displays processes those are not attached to the terminal.

In a nutshell, the aux options allows one to view all the running processes in a system in BSD Unix style. The output of ps aux will contain following fields.

Column name Description
USER The owner of the process
PID Process ID
%CPU CPU time used in percentage
%MEM Physical memory used in percentage
VSZ Virtual memory used in bytes.
RSS Resident Set Size, the non-swappable physical memory used by the process in KiB
TTY Terminal from which the process is started.
STAT Process state
START Starting time and date of the process
TIME Total CPU time used of the process
COMMAND The command with all the arguments which started the process

TOP Command

One of the most widely-used commands to monitor processes and system resource usage on Linux is the top command. It is installed by default on every Linux distribution. The processes are displayed in a list with multiple columns containing information like process name, pid, user, CPU usage percentage, memory usage percentage, and more.

To view the running processes, just run the top command without any options like below.

$ top

The output of the above command contains a lot of information about the system. The header areas includes uptime, load average, cpu usage, memory usage data.

The process list shows all the processes with various details in a separate columns. The following column names are included in the output of top command and are as follows.

Column hame Description
PID Process ID
%CPU CPU usage by the process
%MEM Memory usage by the process
COMMAND The command (executable file) of the process

Sort by Memory/CPU/Process ID/Running time

You can now sort the process list by memory usage, CPU usage, process ID, and running time.

  • To sort the process list by memory usage, press the M key.
  • To sort the process list by CPU usage, press the P key.
  • To sort the process list by process id , press the N key.
  • To sort the process list by process id , press the T key.

Reverse the sorting order

By default the processes are displayed in descending order. Press R to reverse the sorting order of the processes based on currently sorted column. By default the sorting is done through %CPU usage.

Change the update delay

The top command updates the information on the screen every 3.0 seconds by default. To change the update delay time, press the d key. top will ask to provide the time interval between each refresh.

Display full command path

By default, the command column does not display the full path of the command. To view the full path of the command, press the c key.

Add/Remove column

By default the top command displays only few columns. If you want to add/remove columns or change the order of columns, then press the f key.

In the following screen, you will find few fields are marked with * and they are displayed in the order in which they appear in this list. Navigate to the list using up/down arrow keys and press the d key to toggle the display of that field. Once done, press the q key to go back to the process list.

There are much more options to manipulate the output of the top command, which are out of scope for this tutorial. For more options on the top command, consult its man pages.

Now that you have a basic idea of few commands in Linux, you can dive deep in the ocean of Linux commands to sharpen your skills. With time and practice, it’ll become easier for you to maintain and configure Linux servers quickly. Have fun!

A note about tutorials: We encourage our users to try out tutorials, but they aren't fully supported by our team—we can't always provide support when things go wrong. Be sure to check which OS and version it was tested with before you proceed.

If you want a fully managed experience, with dedicated support for any application you might want to run, contact us for more information.

Suggest an update Request an article