Choose another country or region to see content specific to your location and shop online.
United States
USA

Command lines: 24 ways to Use Basic Linux Commands on Your VPS Server

Picture of William Bacchus
William Bacchus

Published: January 27, 2024

Last updated: April 12, 2024

Table of Contents

How to Use Basic Linux Commands on Your VPS Server

Linux, an open-source operating system, is the backbone of countless web servers and personal computers around the globe. With its various distributions such as Ubuntu, CentOS, CoreOs, Arch Linux, Debian, and many more, it caters to both desktop and server environments. Although these distributions might possess unique characteristics, they all share a common ground – the Linux commands. This guide aims to equip you with key Linux commands to enhance your system management skills.

Getting Started with commands

Before we delve into the commands, make sure you have the following:

If you’ve not got a VPS plan, why not check out this useful article, detailing the best Virtual Private Server plans available. We recommend going with The Elite Web Co’s., VPS plan. They offer both self-managed and fully-managed VPS hosting, giving great options for both those with and without hosting experience. Furthermore, they offer you unrestricted root access, including shell access. This solves the second problem of having Shell access to your server.

command lines for vps servers

# 1: Navigating Directories with cd

In the Linux ecosystem, cd stands for ‘Change Directory’. It’s a fundamental command that allows you to switch to different working directories. For instance, to hop into the ‘var’ directory, you would use the following command:

cd /var

Additionally, you can traverse one directory up by using cd followed by two dots:

cd ..

# 2: Crafting Directories with mkdir

The ‘mkdir’ commands, short for ‘Make Directory’, enables users to create new directories. Here’s how you use it:

mkdir <directory name>

For example, to create a directory named ‘new_folder’, you would type:

mkdir new_folder

# 3: Locating Yourself with pwd

pwd, an acronym for ‘Print Working Directory’, reveals the current directory you’re operating in. Simply type the commands below in your terminal window to use it:

pwd

The output will be the complete path of your current location in the file system.

# 4: Duplicating Files with cp

The cp commands serves to copy a file. Here’s the basic syntax:

cp <source file> <destination file>

For example, to clone ‘sample.txt’ to ‘sample2.txt’ in the same directory, you’d execute:

cp sample.txt sample2.txt

Remember, you must hold the necessary permissions to copy files into a directory.

# 5: Relocating Files with mv

When you need to shift files around in Linux, the mv commands comes in handy. The syntax goes as follows:

mv <source file> <destination directory>

For instance, to transport ‘sample.txt’ from the working directory to the downloads directory, you’d use:

mv sample.txt ~/Downloads/

# 6: Listing Contents with ls

The ls commands in Linux serves to list the contents of a directory. To see the contents of our ‘/var’ directory, you’d type:

ls /var

The output will show all the files and directories housed in ‘/var’.

# 7: Copying Directories with cp -a

The cp -a commands can replicate an entire directory. For example, to backup our ‘mail’ directory, we’d utilize the following syntax where ‘mail_backup’ is the name of our new directory:

cp -a /var/mail /var/mail_backup

# 8: Modifying Permissions with chmod

The chmod commands is employed to alter the permissions of a file or directory. For example, we can change the permissions of ‘/var/www’ directory using commands:

chmod 755 /var/www

In this example, complete access is preserved for the current user, while others are restricted from modifying the files in the directory. A permission of 755 signifies that the file owner will have read, write, and execute permissions, while the group and other system users will only have read and execute permissions.

# 9: Changing Ownership with ‘chown

The ‘chown’ command in Linux allows you to modify the ownership of a file or directory. Here’s the basic syntax:

chown <username> <file/directory>

For example, to transfer the ownership of ‘/var/www/’ folder to a user named ‘francis’, we’d use:

chown -R francis /var/www/

The ‘-R’ option is used to change the ownership of all files and directories inside the target directory recursively.

# 10: Checking Memory with free

The free command lets you analyze the total used and available memory on your Linux system:

free -h

The ‘-h’ (human-readable) option displays the memory usage in a user-friendly way, using units like K, M, G.

# 11: Inspecting Disk Space with df

The df command offers a report on the disk space usage of your Linux server:

df -h

The ‘-h’ option presents the information in a human-readable format.

# 12: Deleting Files and Directories with rm

The rm command is used to completely remove a file from the system:

rm <filename>

You can also erase a directory using the rm command with a ‘-r’ option:

rm -r <directory>

Ensure you have appropriate permission to delete the file or use sudo to perform the task.

# 13: Checking Time with date

To obtain the current date and time of your Linux server, apply the date command as follows:

date

# 14: Managing System with reboot and shutdown

To restart your Linux VPS server, use:

reboot

To power off the server, type the following command:

shutdown -h now

# 15: Creating Files with touch

The touch command in Linux is used to generate new files. For example, to create a new file named ‘new_file’ in your current directory, execute:

touch new_file

# 16: Viewing File Contents with cat

You can display the content of files in Linux using the cat command:

cat <filename>

To concatenate the content of multiple files, use:

cat <filename1> <filename2>

You can also append the content of the concatenated files to a different file, say ‘sample3.txt’ using:

cat <filename1> <filename2> > sample3.txt

# 17: Reading Files with more

The more command allows you to read the content of a file one screen at a time:

more <filename>

# 18: Searching Text with grep

The grep command in Linux lets you search for specific text within a file. The basic syntax is:

grep <keyword> <file>

For instance, to search for the phrase ‘chemist’ in a file named sample.txt, you’d type:

grep 'chemist' sample.txt

If your keyword is found, it will be highlighted in the output.

# 19: Listing Commands with history

This command will display a list of previously executed commands:

history

To reuse a previously used command, type the ‘!’ character followed by the numeric key associated with the command.

# 20: Clearing Screen with clear

To tidy up your terminal screen filled with commands and outputs, run the clear command:

clear

# 21: Tracking Packets with traceroute

You can trace the route of packets from your computer to a given host using traceroute:

traceroute <hostname>

# 22: Checking Network Parameters with ifconfig

ifconfig, short for Interface Configuration, queries network interface parameters:

ifconfig

# 23: Connecting Remotely with ssh

The ssh command in Linux enables you to connect to another remote server:

ssh <username>@<hostname>

# 24: Downloading Files with wget

You can download files in a Linux machine using the wget command:

wget <URL of the file>

That’s a wrap on the basic Linux commands that function across all distributions. Although this isn’t an exhaustive list, these commands lay a strong foundation for managing your Linux server, especially for beginners.

Sign up for free news, tips & offers

Your email is safe with us, we don't spam.

Picture of William Bacchus
William Bacchus
Will joined the Elite team in 2021. He has a background in content writing as well as a keen interest in media journalism. His interests include taijutsu and a immense passion for film and television. He aims to inform as many people as he possibly can about the vast and often confusing nature of web design!

Leave a Reply

Your email address will not be published. Required fields are marked *

New customer

New to ELITEWEB.Co? Create an account to get started today.

Registered users

Have an account? Sign in now.

Reseller login

If you’re a reseller, use the button below to sign in. (your reseller account is separate to your regular account)

Reseller login

If you’re a reseller, use the button below to sign in. (your reseller account is separate to your regular account)

New customer

New to ELITEWEB.Co? Create an account to get started today.

Registered users

Have an account? Sign in now.

Sign up to our newsletter for the latest news + a Free WordPress Guide

NEWSLETTER