Special offer
popup-offers
English
+370 5 205 5502 sales@monovm.com

Basic Linux Commands Cheat Sheet With Examples [Updated]

Check out these basic Linux commands cheat sheet with examples to perform or increase your speed/productivity while executing any Linux task/program.

05 Sep, 21 by Susith Nonis 14 min Read

List of content you will read in this article:

Linux is an Operating System that is widely used by developers for making all kinds of applications. In order to accomplish these applications, it is necessary to have a good understanding of basic Linux commands with examples that will be used in hundreds of tasks. The below section introduces a few basic Linux commands cheat sheet that will be helpful for every person using Linux.

PWD Command [Print Working Directory]

In Linux, “Print Working Directory” is abbreviated as pwd.

PWD command prints the path to the current working directory, beginning at the root. The root node is the initial node in the Linux directory hierarchy.

pwd is either a shell command (pwd) or a binary (/bin/pwd).

$PWD is an environment variable that stores the path to the current directory. This variable can be printed using the echo command.

There are two flags for this command.

  • pwd -L is a command that prints the symbolic path.
  • pwd -P: Prints the actual path. Let’s see an illustration for the command.

PS Command

This is an important terminal command in Linux that will allow you to check what processes are currently executing on your system. Processes are just running instances of the operating system's applications.

It's a simple yet powerful method for evaluating system resources, and it allows you to control system operations directly from the terminal. This command also prints the process's PID, which can be used to terminate the process.

This is one of the simplest and most efficient Linux monitoring tools available to Linux enthusiasts.

Locate Command

You may use the locate command to hunt for a file by name.

It functions similarly to the search command, except that it operates in the background.

The locate command analyses the database, whereas the find command explores the file system.

The locate command can be used from any location inside the operating system.

It's more efficient than using the search command.

If you wish to use the locate command to find the file, keep your database up to date.

Head Command

In order to view the beginning of a file, use the head command.

Among Linux users who do a lot of text processing, this is one of the most common Linux commands available.

When working with a large number of files at the terminal, use this command to avoid confusion.

It publishes the top 10 lines of the files by default. It's possible to print a certain number of lines by using the -n option. Check out an example of this command in action!

Tail Command

The tail command, as a complement to the prior command, is likely to be used far more frequently than the header commands.

tail, along with cat and echo, is a simple Linux terminal command that can accomplish things you wouldn't expect. Let’s see an example of using these commands.

Less Command

The less command is also frequently used for analysing the contents of a file due to its ease of use. Users can navigate a file in both directions by using less rather than cat commands, and the terminal session is not interrupted.

Kill Command

Kill Command is a powerful tool for terminating programmes that have been stuck due to a shortage of resources.

The importance of this command will become clear as your understanding of the Linux operating system increases.

The kill command, which appears regularly on lists of funny Linux commands, is as strong as its name implies.

The command's syntax is as follows:

kill PID

Where  PID is the ID of the process we need to kill.

Let’s see an example of this command.

Sort Command

To sort a file, sort is used to arrange a certain order for the records. This command sorts files by default, assuming that the contents is ASCII. It may also be used to sort numerically using parameters in the sort command.

CMP Command

The cmp command will allow you to compare two files and publish the results to the standard output stream. This, along with the comm command, is one of the best Linux commands by users who regularly process huge amounts of text files.

MV Command

Short for a move, it’s a compliment to the cut operation you do in the GUI.

Just like cp, you may use the mv command to move either single or many files from one location to another.

With the -f option, you may compel this Linux programme to transmit big files.

CD Command

In Linux, the cd command is known as the “change directory” command.

It's used to switch to a different working directory.

To go back to the previous directory, you may use:

cd ..

and to go to some sub-directory, you could use:

cd [directory name]

MKDIR Command

This command is used to create new directories from the Linux terminal.

The command expects the name of the new directory after it. Let’s execute this command and verify that the directory was actually created. You can verify it using ls command which basically lists all the files and directories in the current working directory.

RMDIR Command

The rmdir command removes a directory from the system. You must have write access in the parent directory and the directory must be empty before you can delete it. To see if a directory is empty, use the ls -al command.

DF Command

The df command is one of the most powerful Linux terminal tools for seeing important information about your filesystem's disc space.

System administrators use it extensively to monitor and evaluate real-time server or network-oriented systems.

DIR Command

The dir command, by default, lists files and directories in columns that are ordered vertically, and special characters are represented by backslash escape sequences. However, unlike ls, when the output is on the terminal, it does not create colourful output.

Clear Command

This command is used to clear the terminal screen. Type the following command in your terminal and you will get the terminal outputs cleared. The below example of clear command will erase all the text currently written on the terminal once you press enter.

Useradd Command

The useradd command in Linux is used to add user accounts to your system. In Linux, it is just a symbolic link to the adduser command, with the difference that useradd is a native binary built with the system, whereas adduser is a Perl script that uses the useradd binary in the background.

To create a new user, you must have root access.

Userdel Command

The userdel command on a Linux system is used to delete a user account and its related files. This command modifies the system account files by deleting any references to the username LOGIN. It is a straightforward tool for removing users. You will need root access for this command.

Passwd Command

This command is used to generate and manage user passwords.

A regular user can only change their own password, but a superuser can change the password for all accounts. passwd command also changes the password's validity term.

Groupadd Command

In Linux, groups are collections of multiple users inside the OS. A single system can have several users. In a multi-user system, certain users may be able to manage all privileges at the user level while others do not. As a result, we may utilise groups to gather and assign rights and permissions to the entire group. Try the following command to create a group in your system.

sudo groupadd developer

Groupdel Command

The groupdel command is used to delete an existing group. It deletes all group-related records, modifies system account files, and is administered by the superuser or root user. The syntax for the command is

groupdel [options] GROUP

Mount Command

Unlike Windows, whether you attach an SD card or a USB device, your Linux distribution is unlikely to recognise them immediately away.

To mount it using your existing filesystem, use the mount command.

Uname Command

The uname command is one in the best Linux command list that shows system information such as name, version, and other attributes.

You may use this programme to quickly validate your operating system and kernel versions, as well as your system's instruction length.

Using the -a option with the command gives comprehensive information on the kernel and the operating system.

File Command

The file command is used to determine the file type. The file format can be human-readable (for example, 'ASCII text') or MIME (for example, 'text/plain; charset=us-ascii'). The syntax for this command is shown below.

file [option] [file name]

COMM Command

You may use comm to check two files for similar and dissimilar lines. It was one of the first Unix commands to make its way to Linux.

This is a must-have terminal for people who need to process large amounts of files on the terminal.

SU Command

A user can run commands with the privileges of another user account by using the Unix command su, which stands for substitute user. It starts a shell without changing the current working directory or user environment.

When the command is run without the new user id as a command-line parameter, it defaults to using the superuser account (user id 0).

su [username]

Which Command

This command will help you find all of the files you're looking for. This useful terminal command uses specific parameters to search for binary files based on the $PATH environment variable with great efficiency.

Whereis Command

The command whereis locates the source/binary file position of the command and uses manual sections for a specific Linux file. It looks similar to the find command but provides relatively accurate and fast results.

Ping Command

The ping command is used to test a network connection between two hosts. This command accepts an IP address or a URL as input and sends a data packet with the message "PING" to the specified address. The time it takes for the server/host to respond is recorded, and this time is referred to as latency. This is helpful for network administration and debugging.

Curl Command

curl is a command-line utility for transferring data to and from a server using any of the supported protocols (HTTP, FTP, FILE, etc). This technology is recommended for automation because it is designed to function without user intervention. This command can also be used to download packages into your machine. curl can send and receive multiple files at the same time.

This command can also be used to display the content of a specific URL. Let's look at an example.

Whatis Command

In Linux, whatis is used to get a brief explanation of a page manual. In Linux, each manual page contains some kind of explanation of a topic. This control looks for manual page names and displays the file name or argument manual page description.

The following command prints debugging information once we use -d option.

Iptables Command

The iptables command starts a terminal programme that allows system administrators to manage incoming and outgoing internet traffic on a single host computer. It is one of the most commonly used Linux commands by system administrators to identify legitimate network traffic and to block suspicious or untrusted network requests.

ARP Command

The arp command modifies the ARP cache of the system. ARP is an abbreviation for Address Resolution Protocol. The primary function of this protocol is to resolve a system's IP address to its mac address.

Traceroute Command

This command is widely used by security professionals to identify the path a network packet takes from one system to another by combining it with other terminal commands. This is a handy network command that can defend your system against a wide range of hostile intruders.

Chown Command

The chown command allows you to change the owner of a file or directory to a different user or group.

All files in Linux are connected with an owner and a group, and authorization access privileges are assigned to the file owner, group members, and others. Below is the syntax for the command.

chown [OPTIONS] USER FILE(s)

Chmod Command

The chmod command is used in Unix-like operating systems to alter the access mode of a file. Change mode is an acronym for the name. The references are used to differentiate the users to whom the permissions apply, i.e. they are a list of letters that specify to whom access should be granted.

The below example gives read and write permissions to the owner of the file named “test.txt”

NL Command

This command simply lists the number of lines present in a file along with the content in each line. Let’s look at an example for this command.

SS Command

ss stands for socket statistics. It is a command that displays network statistics. The ss command is a more efficient version of the netstat command. ss, in conjunction with the ip command, is useful for gathering network information and troubleshooting network issues.

Last Command

The last command displays information about the most recently logged-in users. It's very useful when we need to track login activities of the users or to identify the source of some unusual activity. The information about logins and logouts are stored in a log file: “/var/log/wtmp”.

I hope this basic Linux commands manual will help you to execute your many tasks and make it easier for you while executing. The above Linux commands list is the top pick by our community members who are experts and Linux Administrator. This article is also used for Linux terminal command. If you feel we have missed listing any Linux commands cheat sheet here which is also the most useful commands then comment that in the below listed comment section.

You can request us also for the PDF of this Linux commands list for examples.

Also, you can try to practice these commands with Linux VPS Server.

People Are Also Reading:

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I veture into the world of Technology I try to share what I know in the simplest way possible. Not a fan of coffee, a sweet addict and a self accredited 'master chef'.