Top 50+ Linux Commands You MUST Know – DigitalOcean

Do you use the Linux command regularly? Today we’ll look at 50+ Linux commands you should know! The commands listed below are some of the most useful and most commonly used Linux commands. Let’s get right to it!

Top 50 Linux Commands You Should Know as a Normal User

  1. ls – The most commonly
  2. used command in Linux to list

  3. pwd directories – Print working directory command on Linux CD
  4. – Linux command to

  5. browse through directories mkdir – Command used to
  6. create directories in Linux mv
  7. Move or rename files in Linux
  8. cp – Similar use to mv but to copy
  9. files in Linux

  10. rm – Delete touch files or directories
  11. – Create

  12. blank / empty
  13. ln files – Create symbolic links (shortcuts) to other
  14. cat files – Display the contents of the file in
  15. the terminal

  16. delete – Clear the echo from the terminal screen –
  17. Print any text that follows the minus
  18. command – Linux command to

  19. display paged outputs on the terminal man
  20. Access manual pages for all Linux commands uname – Linux command for basic information about the whoami operating system – Get the active username tar –
  21. Command to extract and compress files in Linux
  22. grep – Search for a string inside an
  23. output head
  24. – Return the specified number of lines from the

  25. top tail – Return the specified number of lines from
  26. the bottom diff –

  27. Find the difference between
  28. two cmp files –

  29. Check if two files are identical
  30. comm – Combines diff and cmp functionality
  31. sort – Linux command to sort the contents of a file while
  32. exporting occurs – Export environment variables
  33. in Linux zip –

  34. Zip
  35. files in Linux unzip –

  36. Unzip
  37. files in Linux

  38. ssh – Secure Shell command in
  39. Linux

  40. service – Linux command to start and stop
  41. ps
  42. services – Show active processes

  43. kill and killall – Kill active processes by process ID
  44. or

  45. df name – Display mount disk file system information
  46. Mount file systems in Linux
  47. chmod – Command to

  48. change chown file permissions – Command
  49. to

  50. grant ownership of ifconfig files or folders
  51. – Show network interfaces and
  52. IP traceroute addresses – Track all network hops to reach the destination
  53. wget – Direct download of files from
  54. the

  55. ufw
  56. Internet –

  57. iptables firewall command – Base firewall for all other firewall utilities to interact with
  58. apt, pacman, yum, rpm – Package managers depending on the distro
  59. sudo – Command to escalate privileges in Linux
  60. cal – View
  61. a command line calendar alias –

  62. Create custom shortcuts for your commonly used
  63. commands dd – Mainly used to create bootable USB sticks
  64. where it is – Locate the binary, source and manual pages
  65. of a

  66. whatis command – Find out what a command is used
  67. for – View live active processes with your use
  68. of

  69. useradd and usermod system – Add new user or change existing user data
  70. passwd – Create or update passwords for existing users

Now let’s dig a little deeper into each of these commands and understand them in more detail. We already have many existing articles for each of those individual commands. For your convenience, we will add links to all existing articles and continue to update the article as new topics are covered.

The ls command on

Linux The ls command

is used to enumerate files and directories in the current working directory. This is going to be one of the most used Linux commands you should know about.

Ls Command Default

As you can see in the image above, using the command alone without any argument will give us an output with all the files and directories in the directory. The command offers a lot of flexibility in terms of displaying the data in the output.

Learn more about the ls command (link to full article)

The pwd command in

Linux The pwd command

allows you to print the current working directory on your terminal. It is a very basic command and solves its purpose very well.

Now, your terminal indicator should usually have the full directory anyway. But in case you don’t, this can be a quick command to see the directory you’re in. Another application of this command is when creating scripts where this command can allow us to find the directory where the script has been saved.

The cd command in Linux

While working within the terminal, moving within directories is practically a necessity. The cd command is one of the important Linux commands you should know about and will help you navigate directories. Just type cd followed by directory as shown below.

root@ubuntu:~# cd <directory path>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/cd-command-default.png” alt=”Cd Command Default” />

As you can see from the command above, I simply typed cd /etc/ to enter the /etc directory. We use the pwd command to print the current working directory.

The mkdir command

on Linux The

mkdir command allows you to create directories from within the terminal. The default syntax is mkdir followed by the directory name.

root@ubuntu:~# mkdir <folder name>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/mkdir-default.png” alt=”Mkdir Default” />

As you can see in the screenshot above, we created the JournalDev directory with just this simple command.

Learn more about the mkdir command (Link to article)

The commands

cp and mv The cp and mv commands are equivalent to copy-paste and cut-paste in Windows. But since Linux doesn’t really have a command to rename files, we also make use of the mv command to rename files and folders.

root@ubuntu:~# cp <source> <destination>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/Cp-command-default.png” alt=”Cp Command Default” />

In the above command, we create a copy of the file named Sample. Let’s see what happens if we use the mv command in the same way. For this demonstration, I will delete the Sample-Copy file.

root@ubuntu:~# mv <source> <destination

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/mv-command-default.png” alt=”Mv Command Linux commands you should know” />

In the previous case, since we were moving the file within the same directory, it acted as a rename. The file name has now changed.

Learn more about the cp command (Link

to article) and the mv command (Link to article).

The rm command on Linux

In the previous section, we deleted the Sample-Copy file. The rm command is used to delete files and folders and is one of the important Linux commands you should be aware of.

root@ubuntu:~# rm <file name> root@ubuntu:~# rm -r <folder/directory name>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/rm-default.png” alt=”Rm Default” />

To delete a directory, you must add the -r argument to it. Without the -r argument, the rm command will not delete directories.

The touch command

on Linux

To create a new file, the touch command will be used. The touch keyword followed by the file name will create a file in the current directory.

root@ubuntu:~# touch <filename>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/touch-command-default.png” alt=”Touch Command – Linux commands you should know” />

The ln command in Linux To create a link to another file, we use the

ln command

. This is one of the important Linux commands you should know if you plan to work as a Linux administrator.

root@ubuntu:~# ln -s <source path> <link name>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/symbolic-link-default.png” alt=”Token Link Default” />

The

basic syntax involves using the -s parameter so that we can create a symbolic link or a soft link. The

commands

cat, echo and less When you want to generate the contents of a file, or print anything in the output of the terminal, we make use of the cat or echo commands. Let’s look at its basic use. I’ve added some text to our new file we created earlier.

root@ubuntu:~# cat <filename> root@ubuntu:~# echo <Text to print in terminal>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/cat-and-echo-commands.png” alt=”Cat And Echo Commands” />

As you can see in the example above, the cat command when used in our “New-File”, prints the contents of the file. At the same time, when we use the echo command, it simply prints what follows after the command.

The less command is used when the output printed by any command is larger than the screen space and needs scrolling. The less command allows the use to break down the output and scroll through it with the use of the enter or space keys.

The simple way to do this is with the use of the pipe operator (|).

root@ubuntu:~# cat /boot/gurub/gurub.cfg | less Learn more about the echo(Link to article) command

and the cat(Link to article) command.

The man command

in Linux The

man command is a very useful Linux command that you should know. When working with Linux, the packages we download can have a lot of functionality. Knowing everything is impossible.

Man pages offer a really efficient way to learn about the functionality of almost every package you can download using the package managers in your Linux distribution.

root@ubuntu:~# man <command> The uname and whoami commands

The uname and whoami commands

allow you to know basic information that is very useful when working on multiple systems. In general, if you’re working with a single computer, you won’t really need it as often as someone who is a network administrator.

Let’s look at the output of both commands and how we can use them.

root@ubuntu:~# uname -a

Uname And Whoami Commands Linux commands you should know

The -a parameter that I supplied to uname means “all”. This prints out the complete information. If the parameter is not added, all you will get as output is “Linux”.

The tar

, zip and unzip commands The tar

command on Linux

is used to create and extract archived files on Linux. We can extract multiple different archive files using the tar command.

To create a file, we use the –

c parameter and to extract a file, we use the -x parameter. Let’s see it work.

#Compress root@ubuntu:~# tar -cvf <file name> <space-separated files> #Extract root@ubuntu:~# tar -xvf <filename>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/tar-basic-usage.png” alt=”Basic tar Linux commands you should know” />

In the first line, we create a file called Compress.tar with New-File and New-File-Link. In the following command, we have extracted those files from the archive.

Now coming to the zip and unzip commands. Both commands are very simple. You can use them without any parameters and they will work as intended. Let’s look at an example below.

root@ubuntu:~# zip <filename> <space-separated filenames> root@ubuntu:~# unzip <filename>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/zip-unzip-commands.png” alt=”Zip Unzip Commands” />

Since we already have those files in the same directory, the unzip command asks us before overwriting those files.

Learn more about the tar command (Link to article) and zip and unzip commands (Link to article)

The

grep command on Linux

If you want to search for a specific string within an output, the grep command comes into play. We can pipe (|) the output to the grep command and extract the required string.

root@ubuntu:~# <Any command with output> | grep “<string to find>”

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/grep-command-example.png” alt=”Grep Command Example” />

This was a simple demonstration of the command. More information about the grep command (Link to article)

The head and tail commands When issuing large files,

the head and tail commands

are useful. I have created a file called “Words” with many words sorted alphabetically. The head command will generate the first 10 lines of the file, while the tail command will generate the last 10. This also includes any blank lines and not just lines with text.

root@ubuntu:~# head <filename> root@ubuntu:~# tail <filename> <img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/head-command.png” alt=”Head Command” />

As you can see, the head command displayed 10 lines from the top of the

file.

<img src

=”

https://journaldev.nyc3.digitaloceanspaces.com/2020/01/tail-command.png” alt=”Tail Command Linux commands you should know” />

The tail command

generated the bottom 10 lines of the file

.

Learn more about the tail command(Link to article)

The diff, comm, and cmp Linux

commands

offer multiple commands for comparing files. The diff, comm, and cmp commands compare differences and are some of the most useful Linux commands you should be aware of. Let’s look at the default outputs for all three commands.

root@ubuntu:~# diff <file 1> <file 2> <

img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/diff-command.png” alt=”Command diff Linux commands you should know” /

>

As you can see above, I’ve added a small piece of text that says “This line is edited” to the New-File-Edited file

. root@ubuntu:~# cmp <file 1> <file 2> The

cmp command only instructs you to use the line number that is different. Not the actual text. Let’s see what the comm command does.

root@ubuntu:~# comm <file 1> <file2>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/comm-command.png” alt=”Comm Command” />

Text that is

left-aligned is text that is only present in file 1. Center-aligned text is present only in file 2. And right-aligned text is present in both files.

From the looks of it, the comm command makes more sense when we’re trying to compare larger files and we’d like to see everything organized together.

The sort

command on Linux The sort command

will provide an orderly output of the contents of a file. Let’s use the sort command without any parameters and see the output.

The

basic syntax of the

sort command is: root@ubuntu:~# sort <filename>

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/sort-command.png” alt=”Sort Command Linux commands you should know” />

The export command in

Linux The export command

is

especially used when exporting environment variables at run time. For example, if I wanted to update the bash indicator, I will update the PS1 environment variable. The bash message will be updated with immediate effect.

root@ubuntu:~# export <variable name>=<value>

If for some reason, your bash message does not update, just type bash and you should see the updated terminal message

.

Learn more about the export command(Link to article)

The ssh command in

Linux The

ssh command

allows us to connect to an external machine on the network with the use of the ssh protocol. The basic syntax of

the ssh command is: root@ubuntu:~ ->> ssh username@hostname

Learn more about the ssh command(Link to article)

The service command in Linux

The service command in Linux

is used to start and stop different services within the operating system. The basic syntax of the command is as follows.

root@ubuntu:~ ->> service ssh status root@ubuntu:~ ->> service ssh stop root@ubuntu:~ ->> service ssh start

<img src="https://journaldev.nyc3.digitaloceanspaces.com/2020/01/service-command.png" alt="Service Command" />

As you can see in the image, the ssh server is running on our system.

The commands

ps, kill and killall Since we’re on the subject of processes, let’s see how we can find active processes and kill them. To find the running processes, we can simply type ps at the terminal prompt and get the list of running processes.

root@ubuntu:~ ->> ps root@ubuntu:~ ->> kill <Process ID> root@ubuntu:~ ->> killall <process name>

For demonstration purposes, I’m creating a shell script with an infinite loop and will run it in the

background.

With the use of the symbol & I can pass a process to the background. As you can see, a new bash process is created with PID 14490.

Ps Command Linux commands you should know Now, to kill a process with the kill

command, you can type kill followed by b the PID of the process.

Kill Command linux commands you should know

But if you don’t know the process ID and just want to kill the process with the name, you can use the killall command.

Killall Command linux commands you should know

You will notice that PID 14490 remained active. That’s because both times, I killed the sleep process.

Learn more about the ps command (Link to article).

The

df and mount commands When

working with Linux, the df and mount commands are very efficient utilities for mounting file systems and getting file system details

.

When I say mount, it means that we will connect the device to a folder so that we can access the files from our file system. The default syntax for mounting a file system is as follows

: root@ubuntu:~ ->> mount /dev/cdrom /mnt root@ubuntu:~ ->> df -h

In the above case, /dev/cdrom is the device that needs to be mounted. Typically, a mountable device is located inside the /dev folder. /mnt is the destination folder where the device is mounted. You can change it to any folder you want, but I’ve used /mnt since it’s pretty much a default system folder for mounting devices.

To view the mounted devices and learn more about them, we make use of the df command. Simply typing df will give us the data in bytes that are not readable. So we’ll use the -h parameter to make the data human-readable.

<img src="https://journaldev.nyc3.digitaloceanspaces.com/2020/01/df-command.png" alt="Df

command Linux commands you should know” />

Learn more about the df command(Link to article)

The chmod and chown

commands The chmod and chown commands give us the functionality to change file permissions and file ownership are the most important Linux commands you should know.

The main difference between the functions of the two commands is that the chmod command allows us to change the file permissions, while chown allows us to change the owners of the file.

The default syntax for both commands is chmod <parameter> filename and chown user:group filename

root@ubuntu:~ ->> chmod +x loop.sh root@ubuntu:~ ->> chmod root:root loop.sh

<img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/chmod-command.png” alt=”Chmod Command linux commands you should know” />

In the example above, we are adding executable permissions to the loop.sh file with the chmod command. Other than that, with the chown command, we have made it accessible only to the root user and users within the root group.

Chown Command linux commands you should know

As you may notice, the root part is now changed to www-data, which is the new user who has full ownership of the file.

Learn more about the chmod(Link to article) command and the

chown command (Link to article)

The ifconfig and traceroute

commands

Moving on to the networking section on Linux, we come across the ifconfig and traceroute commands that will be used frequently if you manage a network.

The ifconfig command will give you the list of all network interfaces along with IP addresses, MAC addresses and other interface information.

root@ubuntu:~ ->> ifconfig

There are several parameters that can be used, but we will work with the basic command here

. <

img src=”https://journaldev.nyc3.digitaloceanspaces.com/2020/01/ifconfig-command.png” alt=”Ifconfig command Linux commands you should know” /

>

When working with traceroute, you can simply specify the IP address, hostname, or domain name of the endpoint.

root@ubuntu:~ ->> traceroute <destination address>

Traceroute Command linux commands to know

Now, obviously, localhost is just a hop (which is the network interface itself). You can try this same command with any other domain name or IP address to see all the routers your data packets pass through to reach the destination.

Learn more about the ifconfig command(Link to article)

The wget command

on Linux

If you want to download a file from the terminal, the wget command is one of the most practical command-line utilities available. This will be one of the important Linux commands you should know when working with source files.

When you specify the link to download, it has to be directly a link to the file. If the wget command can’t access the file, it will simply download the webpage in HTML format instead of the actual file you wanted.

Let’s try an example. The basic syntax of the

wget command is: root@ubuntu:~ ->> wget <link to file> OR root@ubuntu:~ ->> wget -c <link to file>

The -c argument allows us to resume an interrupted download

.

The ufw and iptables

UFW and IPTables commands are firewall interfaces to the netfilter firewall of the Linux kernel. IPTables passes firewall rules directly to netfilter, while UFW configures rules in IPTables, which then sends those rules to netfilter.

Why do we need UFW when we have IPTables? Because IPTables is quite difficult for a newbie. UFW makes things extremely easy. See the following example where we are trying to allow port 80 for our web server.

root@ubuntu:~# iptables -A INPUT -p tcp -m tcp -dport 80 -j ACCEPT root@ubuntu:~# ufw allow 80

I’m sure you now know why UFW was created! See how easy the syntax gets. Both firewalls are very comprehensive and can allow you to create any type of configuration required for your network. Learn at least the basics of UFW or IPTables firewall, as these are the Linux commands you should know.

Learn more about opening ports in Linux(Link to article)

Package managers in

Linux

Different Linux distributions make use of different package managers. As we are working on an Ubuntu server, we have the apt package manager. But for someone working on a Fedora, Red Hat, Arch or Centos machine, the package manager will be different.

Debian- and Debian-based distributions – apt install <package name> Arch and Arch-based distributions – pacman -S <package name> Red Hat and

    Red Hat

  • based distributions
  • – yum install <package name>

  • Fedora and CentOS – yum install <package
  • >

Familiarizing yourself well with your distribution’s package manager will make things much easier for you in the long run. Therefore, even if you have a GUI-based package management tool installed, try using the CLI-based tool before moving to the GUI utility. Add them to your list of Linux commands you should know.

The sudo command in Linux “

With great power, comes great responsibility”

This is the quote displayed when a sudoer-enabled user first uses the

sudo command

to escalate privileges. This command is equivalent to being logged in as root (depending on the permissions you have as a sudoer).

non-root-user@ubuntu:~# sudo <command you want to execute> Password:

Just add the word sudo before any commands you need to run with scaled privileges and that’s it. It’s very simple to use, but it can also be an additional security risk if a malicious user gains access to a sudoer.

Learn more about the sudo command (Link to article)

The cal command in Linux

Have you ever wanted to see the calendar in the terminal? Neither do I! But apparently there are people who wanted it to happen and well, here it is.

The cal command displays a well-presented calendar in the terminal. Simply enter the word cal on the indicator of your terminal.

root@ubuntu:~# cal root@ubuntu:~# cal May 2019

Cal Command Output

Although

I don’t need it, it’s a really cool addition! I’m sure there are people who are fans of the terminal and this is a really amazing option for them.

Does the alias command

have some commands that you run very frequently while using the terminal? It could be rm -r or ls –l, or it could be something longer like tar -xvzf. This is one of the productivity-boosting Linux commands you should be aware of.

If you know a command that you run very often, it’s time to create an alias. What is an alias? In simple terms, it’s another name for a command you’ve defined.

root@ubuntu:~# alias lsl=”ls -l” OR root@ubuntu:~# alias rmd=”rm -r” Now, every time you

enter lsl or rmd in the terminal, you will receive the output you would have received if you had used the full commands

.

The examples here are for really small commands that you can still type by hand each time. But in some situations where a command has too many arguments that you need to type, it is better to create an abbreviated version of it.

Learn more about the alias command (LInk to article)

The dd command in Linux

This command was created to convert and copy files of multiple file system formats. Currently, the command is used simply to create bootable USB for Linux, but there are still some important things you can do with the command.

For example, if I wanted to back up the entire hard drive as it is on another drive, I will use the dd command.

root@ubuntu:~# dd if = /dev/sdb of = /dev/sda The

if and of arguments represent the input file and the output file

. The

whereis and whatis commands The

names of the commands make their functionality very clear. But let’s demonstrate its functionality to make things clearer.

The whereis command

will generate the exact location of any command you type after the whereis command. root@ubuntu:~# whereis sudo sudo: /usr/bin/sudo /usr/lib/sudo /usr/share/man/man8/sudo.8.gz The whatis command gives us an explanation of what a command really is.

Similar to the whereis command, you will receive the information for any commands you type after the whatis command.

root@ubuntu:~# Whatis sudo sudo (8) – run a command as another user The top command

on Linux

A few sections earlier, we talked about the ps command. He noted that the ps command will generate the active processes and finish by itself

.

The top command is like a CLI version of the task manager in Windows. You get a live view of processes and all the information that accompanies those processes, such as memory usage, CPU usage, etc.

To get the top command, all you need to do is type the word top into your terminal.

Top Command Output Linux commands you should know

The useradd

and usermod

commands The useradd or adduser commands

are exactly the same commands where adduser is just a symbolic link to the useradd command. This command allows us to create a new user in Linux.

root@ubuntu:~# useradd JournalDev -d /home/JD The

above command will create a new user named JournalDev with the home directory as /home/JD. The

usermod command, on the other hand, is used to modify existing users. You can modify any user value, including groups, permissions, and so on.

For example, if you want to add more groups to the user, you can type

: root@ubuntu:~# usermod JournalDev -a -G sudo, audio, mysql

Learn more about creating and managing users on Linux (Link to article)

The passwd command on Linux

Now that you know how to create new users, let’s set the password for them as well. The passwd command allows you to set the password for your own account or, if you have the permissions, set the password for other accounts.

Using the command is quite simple

: root@ubuntu:~# passwd New password:

Passwd Command

If you add the user name after passwd, you can set passwords for other users. Enter the new password twice and you’re done. That’s all! You will have a new password set for the user!

Final note

This was a very long article, but I’m sure it will be something you can refer to when needed. As we add more articles to JournalDev, we will continue to add links to those articles here.

We hope you found this article helpful. If you have any questions, feel free to comment below.

Contact US