Best Ubuntu commands
Commands

25 Must-Know Ubuntu Commands

Sagar Sharma
Sagar Sharma

Table of Contents

What are the top Ubuntu commands that everyone should know?

There is no set answer to that. It differs from person to person, based on their need.

In this tutorial, I will share my list of 25 Linux commands I think all Ubuntu users should know.

Ubuntu 18.04 Review of New Features
Ubuntu 18.04 Review of New Features

Must know Ubuntu commands

And if you are curious to know what commands you must know to get the most out of your Ubuntu machine, here's a summary of what I'm about to discuss:

Command Description
ls List the contents of the directory.
cd Change to a different directory.
mkdir Create a new directory.
touch Create a new empty file or update the modification time of a file.
cp Copy a file or a directory.
mv Can be used to move or rename a file or directory.
nano A simple text editor which can be used to create or edit files.
cat Shows the contents of a file.
grep Sorts the output based on a given pattern.
chmod Change the permission of a file or a directory.
chown Change the owner of a file or a directory.
tar Create or extract a tar archive file.
zip Creates a zip file.
unzip Extract the zip archive file.
ssh Securely connect to a remote server.
ping Test the connectivity between two devices over the network.
su Switch to another user account.
netstat Shows network connections, routing tables, and network stats.
top Shows the live status of system resources and ongoing processes.
free Displays the information about the system's memory usage.
df Gets the disk usage information.
kill Used to kill the ongoing process.
find Searches for a file or a directory based on given arguments.
history Gets the list of previously executed commands.
apt Ubuntu package manager which is used to install, update and remove packages.

Want to know how to use every command mentioned above with an example? Here you have it.

1. ls command: List the content of the directory

This is one of the most basic commands and it is thought first if anyone is starting their Linux journey.

And when used without any options, it will list the contents of the current working directory:

ls
use ls command to list the contents of a folder in ubuntu

Similarly, you can use the -a option with the ls command to list hidden files:

ls -a

If you notice carefully, it listed files and directories starting with . which are hidden files/directories and won't be listed by default.

Want to learn more about the ls command? Here are some useful examples:

ls Command in Linux: 17 Useful Examples Explained
The ls command in Linux is one of the most used commands. But most people don’t utilize its full potential. Check out the basics as well as advanced ls command examples in Linux.

2. cd command: Chage to a different directory

This might be the most used command in Linux as if you are dealing with the terminal, you are required to chage the directories pretty frequently.

To use the cd command, all you have to do is append the directory name followed by space to the cd command:

cd [directory-name]

For your reference, here, I changed my directory to Images:

cd Images
use cd command to chage directory in ubuntu terminal

Suggested read: Practical examples of the cd command.

3. mkdir command: Create a new directory

You may want to create a new directory to store specific files inside.

And in that case, you can use the mkdir command followed by the space and name of the directory as shown:

mkdir [directory-name]

For example, here, I created a new directory named Examples:

mkdir Examples
create a new directory using the mkdir command

And as you can see, when I used the ls command, it showed the recently created directory.

To learn more, you can read our detailed guide on how to create directories using the mkdir command:

mkdir command: Create New Directories in Linux
mkdir is one of the essential Linux commands that every Linux user should know. You can create new directories using mkdir.

4. touch command: Create empty files

In an operating system where everything is treated as a file, creating files is one of the most essential things you do with Linux.

And in the times when you want to create an empty file, you can use the touch command as shown:

touch [Filename]

So let's say I want to create an empty text file named Hello.txt, then, I will be using the touch command in the following manner:

touch Hello.txt
create an empty file using the touch command in Linux

And if you want to learn more, you can check out our guide on how to use the touch command with examples:

Touch Command in Linux: 9 Useful Examples
Learn to use touch command in Linux with these useful and practical examples.

5. cp command: Copy files or directories

You may want to copy your files or directories from one place to another and in that case, you can utilize the cp command.

And to copy files using the cp command, it needs to be executed in the following manner:

cp source_file target_directory

Let's say I want to copy a text file named Hello.txt to the MyFiles directory, then, I'd have to use the following command:

cp Hello.txt MyFiles/
copy files in Linux terminal using the cp command

Must read: Practical examples of cp command

How to Copy Files in Linux With cp Command
cp command in Linux is used for copying files and directories. In this tutorial, you’ll learn some of the essential usages of the cp command.

6. mv command: Move or rename file/directory

Previously, I explained how you can copy files using the cp command but what if you want to move them?

Well, in that case, you can use the mv command in the following manner:

mv target_file target_directory

For example, here, I have moved Hello.txt to the Docs directory:

mv Hello.txt Docs/
use the mv command to move files in Linux terminal

And as you can see, the file was moved successfully.

Want to learn more? Here are the practical examples of the mv command:

mv Command Examples in Linux: Move Files and Directories
mv command in Linux is used for moving and renaming files and directories. In this tutorial, you’ll learn some of the essential usages of the mv command.

7. nano command: Create or edit text files easily

The nano text editor is by far the easiest text editor in the Linux terminal which can be used to create and edit the text files in Linux.

To edit the text file using nano, append the filename to the nano command followed by the space as shown:

nano Filename

For example, here, I made a few changes to the Hello.txt file using the nano text editor:

edit files using the nano text editor in Linux terminal

But nano can do a lot more than this!

To learn more, you can check out a detailed guide on how to edit files using nano text editor:

Linux Terminal Basics #9: Editing Files in Linux Terminal
Learn about editing text files in the Linux terminal using the beginner friendly Nano editor in the second last chapter of this series.

8. cat command: Read a text file

In times when you want to read the content of the text file, the cat command is all you need. In simple words, it will display the text content in your standard output.

And to use the cat command, you'd need to execute it in the following manner:

cat Filename
use cat command to read the text file in linux

But did you know that you can merge two files using the cat command? But it is just the tip of the iceberg, you can do a lot more:

Cat Command in Linux: Essential and Advanced Examples
cat is one of the most used commands in Linux but do you really know the cat command? Learn the basics as well as advanced examples of cat command in Linux.

9. grep command: Find from the file content or command output

There are various commands that'd fill the whole screen with their output so in that case, you can use the grep command to find exactly what you were looking for.

Also, the same can be applied to files.

It can be used directly or can be piped to the existing command.

So for your reference, here, I have piped the grep command to the cat command to find the word Hello from the Hello.txt file:

cat Hello.txt | grep -w "Hello"
use grep command to find words from the text file in Ubuntu terminal

Want to learn how it can be used for advanced use cases, I would recommend checking out practical examples of the grep command:

10 Practical Grep Command Examples for Developers
The grep command is used to find patterns in files. This tutorial shows some of the most common grep command examples that would be specifically beneficial for software developers.

10. chmod command: Change file permissions

From its core, Linux is built to have multiple users and in that case, you might not want to allow other users to access your personal files.

And using the chmod command, you can change the read, write, and execution permission of a file.

To use the chmod command, you'd have to follow the given command syntax:

chmod [options] mode file(s)

So let's say I want to make a Hello.sh script executable, then, I will be using the following:

chmod +x Hello.sh
use chmod command to make the file executable in Ubuntu terminal

And as you can see, the file is now executable!

The chmod command offers two modes to tweak the permission and to learn more, I would recommend our detailed guide on how to use the chmod command:

Use the chmod Command on Ubuntu
Learn about changing file permissions in Ubuntu terminal with the chmod command.

11. chown: Change file ownership

This is similar to what I explained above but using the chown, you can change the ownership of the file, and later on, you can use the chmod to change permissions for the owner (if you want to).

To use the chown command, you'd have to follow the given command syntax:

chown [OPTIONS] USER[:GROUP] file

For example, here, I changed the ownership of the Hello.txt to the root user:

sudo chown root Hello.txt
change file ownership in Ubuntu terminal using the chown command

If you want to learn more about the chown command, I would recommend checking out the guide on how to change file ownership in Ubuntu:

How to Change File Ownership in Ubuntu
Here’s how to change the ownership of files and folders in Ubuntu command line.

12. tar command: Create or extract a tar archive file

If you attempt to install packages manually in Linux, you'd get the file in the form of the tar archive in most cases.

And you can use the tar command to create or extract the tar archive files.

To do so, you'd have to use the tar command in the following manner:

tar [options] [archive_name] /target/file/or/directoty

For your reference, here, I created a tar file named Files.tar which contains Hello.txt and LU.txt:

But what about extracting the tar files? Or do you want to create a tar file from a directory?

To do so, refer to our detailed guide on tar:

How to Create and Extract Tarballs in Linux Command Line
Tar is one of the most common tool used for archiving files in Linux. Learn how to create a tarball and how to extract it in the beginner’s tutorial.

13. zip command: Create zip files

Want to create zip files? All you need is a zip command!

To create a zip file, you'd have to use the zip command in the following manner:

zip output_file.zip input_file

For example, here, I created a zip file named LU.zip containing multiple files:

zip LU.zip Hello.txt LU.txt

But what if you want to create a zip archive from the directory itself? To do so, I would recommend reading how to zip files and folders on Ubuntu:

How to Zip Files and Folders in Ubuntu Command Line
Learn to zip files in the Ubuntu command line with these practical examples. Also learn about combining files and folders into a zip file.

14. unzip command: Extract zip files

Unlike the tar command which can be used to create and extract tar files, you'd have to use the unzip command separately to extract zip files.

To unzip files using the unzip command, you'd have to follow the given syntax:

unzip [options] archive.zip

For your reference, here, I will unzip the LU.zip file:

unzip LU.zip
unzip files using the unzip command

Recommended read:

Unzip Files in Ubuntu Command Line
Got a zipped file? Learn how to extract a zipped file using the unzip command in the Ubuntu command line.

15. ssh command: Connect to a remote server

If you are into servers or have to manage multiple machines at the same time, SSH is all you can ever ask for!

If installed on both client and server and if you have login credentials, you can easily get into the system. To do so, use ssh in the following manner:

ssh username@Hostname_or_IP
connect to remote Linux system using ssh

Here, I have configured passwordless SSH, so it won't ask for the password. Want to know how to do so? Here's a detailed guide:

How to Disable SSH Login With Password
One of the basic SSH hardening step is to disable password based SSH login. This reduces the risk of a brute force attack on your Linux server.

16. ping command: Test connectivity between two hosts

The ping command is mostly used to check whether you have a working internet connection or not.

If you're curious, the ping command sends small packets to the specified host, the host will receive the packets and will send the response packets, if done successfully, the ping will show how long it took to get response packets.

And if you don't have an active internet connection, of course, it won't work!

To use the ping command, you'd have to specify the host IP followed by space to the ping command:

ping host-ip

If you want to learn more about ping, we have a dedicated tutorial on how to use the ping command with practical examples:

Linux Ping Command: 7 Practical Examples
Here are some of the most common usages of ping command in Linux along with their explanation.

17. su command: Log in as another user

Many beginners are not aware of this command and they often restart their system so they can log in as another user.

And using the su command, you can switch between multiple users without any hiccups.

To change the user using the su command, it needs to be executed in the following manner:

su - username

For example, here, I switched to the user milan:

change user using the su command

Want a more detailed guide on how to change users using the su command? Here's a detailed guide for you:

How to Change User in Linux Command Line
Linux systems have different users and different types of users. Learn how to switch the users in Linux command line or how to change to the root user in Linux.

18. netstat command: Show network statistics

If you are into networking, the netstat can give a wide range of information such as network connections, routing tables, and network interface statistics.

And to use the netstat command, you'd have to follow the given syntax:

netstat [options]

So let's say I want to find out the listening TCP ports, then I will be using the netstat in the following manner:

netstat -lt
use netstat command to find listening TCP ports in Ubuntu linux

But you can do a lot more than just listing listening ports.

To learn more, I would recommend checking our guide on how to use the netstat command with examples:

Netstat Command in Linux: 13 Practical Examples
Netstat is one of the most common networking commands in Linux. Learn some useful examples of netstat in this tutorial.

19. top command: Monitor processes and system resources

If your system is slowing down, the first step is to check how many processes are running in the background and their resource consumption.

And there is a specific utility for this purpose named top.

To use the top command, you can refer to its command syntax:

top [options]

You can also ignore the [options] and when executed without options, it will show the ongoing processes:

use top command monitor system resources in Ubuntu linux

But did you know that you can use the top command as a task manager? Want to learn how? Here's a detailed guide with examples:

How to Use the Top Command as Task Manager in Linux
The top command provides a quick look at system resources and processes. You can also control it to use it as the task manager in Linux terminal.

20. free command: Shows info about memory usage

If you are only interested in monitoring memory consumption, the free command offers plenty of options to get the job done.

To use the free command, you can refer to its command syntax:

free [options]

So let's say I want to know the memory consumption in my system, then I will be using the free command with the -h flag to make the output human-readable:

free -h
use free command to know the memory consumption in Ubuntu linux

Did you know that the free command can also be used to live to monitor memory consumption? To do so, you can refer to the following guide:

Use Free Command in Ubuntu
The free command lets you see your Ubuntu system’s current RAM usage. Learn how to use the free command.

21. df command: Get info about disk space usage

Using the df command, you can get the disk usage info of every drive at once!

And to use the df command, you'd have to follow a simple command syntax:

df [options]

While you can use the df command without any options and still get the output, but is just confusing! So to deal with that, you can use the -h option:

df -h
use the df command to get the disk usage info in ubuntu linux

Apart from listing disk usage at once, it offers various other options like excluding certain types of filesystem while using the df command.

And if you are interested, you can checkout the detailed guide:

Check Linux Disk Space with df Command [Useful Examples]
The df command is used for checking disk space in Linux. Learn some of the most common usage of the df command in Linux.

22: kill command: Kill the ongoing processes

If you find a stubborn process that is consuming a major chunk of your resource, killing it is the best way to get a smooth experience.

To do so, you can use the kill command to shut down the process in Linux.

And to use the kill command, all you need to do is follow the given syntax:

kill <signal> <PID>

For example, if I want to kill the process having PID of 3347, then I will be using the following:

kill 3347

If you notice, I didn't use any options as by default, it uses the TERM signal which is the recommended way to kill the process.

But if it is not working, you can use other signals like SIGKILL, SIGQUIT, etc. and to learn more about how signals work, you can refer to our detailed guide:

How to use SIGINT and other Termination Signals in Linux
Terminating executing process is more than just kill -9. Here are some of the prominent termination signals and their usage.

23: find command: Search for files and directories

The find command is one of the most powerful utilities that Linux has to offer if used correctly, it can find the specific file from a stack of thousands of files!

And to use the find command, it needs to be executed in the following manner:

find [path] [expression]

For example, here, I searched for Hello.txt inside my home directory (it will search recursively) :

find ~/ -type f -name Hello.txt
use find command to search files in Ubuntu terminal

But that's not even the tip of the iceberg! There are multiple ways to use the find command such as using the find command with exec.

And if you want to learn more, here are some practical examples of the find command:

15 Super Useful Examples of Find Command in Linux
Learn the super powerful and super useful find command with these practical examples.

24: history command: List the preciously used commands

If you forgot that precious command of yours that worked as expected, you can get it back with the history command!

By default, it will store the last 1000 commands and if you want to store more, you can do that too by tweaking the .bashrc file.

You can simply type the history and it will show the previous command executions:

history
use the history command in Ubuntu

Once you find out the command, you can execute the same by just using its index number.

So let's say I want to run the command having the index number 571, all I have to do is append the number to the !sign in terminal:

!571
run commands from the history in Ubuntu

Recommended read:

Using History Command in Linux [Beginner’s Guide]
Everything you type in the terminal is stored in the shell history. Learn how to use command history in Linux in this introduction to history command.

25: apt command: Install, update, and remove packages

Apt is the official package manager of Ubuntu and it is used to install, update and remove the packages.

And most of the users are familiar with the apt as you can't even update or install anything without using the apt.

So let's say you want to install Vim in Ubuntu, then you'd have to use the install flag with the package name:

sudo apt install vim

To remove a package, use it like this:

sudo apt remove package_name

You can also use it to update all the apt packages, including the Linux kernel:

sudo apt update && sudo apt upgrade

But being a package manager, there are tonnes of other options, and not possible to include them here.

So if you want to learn how to use apt in Ubuntu, here's the complete tutorial:

Using apt Commands in Linux [Complete Guide]
Brief: This article shows you how to use apt commands in Linux with examples so that you can manage packages effectively. If you are using Debian, Ubuntu, Linux Mint or any other Debian or Ubuntu based distributions, you must have come across some apt commands by now. First noticed in

Get started with Linux commands

If you are absolutely new to the terminal, you must refer to this article and learn the essential tips.

19 Basic But Essential Linux Terminal Tips You Must Know
Learn some small, basic but often ignored things about the terminal. With the small tips, you should be able to use the terminal with slightly more efficiency.

Other than that, here's a good place for you to start learning Linux commands.

Linux Command Tutorials for Absolute Beginners
Never used Linux commands before? No worries. This tutorial series is for absolute beginners to the Linux terminal.

I hope you will find this guide helpful! If you have any queries, please leave a comment.



Sagar Sharma

Sagar Sharma

A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.