# 20 Basic Commands in Linux - Linux Simplified

## In this post, we’ll explore 20 basic Linux commands everyone should know.

## 1\. whoami

Displays the currently logged-in user.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754529317598/85b16539-c768-416d-b971-9bae1729f969.png align="center")

---

## 2\. pwd

pwd stands for **Print Working Directory**. It displays the current directory the user’s in.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754529344379/9c0458ef-858e-49ea-836c-4085cbab670b.png align="center")

---

## 3\. ls

`ls` is used to **List** files and directories. This is one of the most fundamental and frequently used commands in the Linux terminal. When used without any options, it shows the contents of the current directory the user’s in.

Here are the options for the `ls`.

* `-l` Long, detailed list of all information.
    
* `-a` Lists all files, including hidden files (those starting with a `.`).
    
* `-h` List files with human readable file sizes.
    
* `-r` Reverse order lists files with the oldest date first.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754529398698/362c4dec-66cb-4909-8f24-995e11043125.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754529384382/2ace0345-2622-4b7e-af62-e2914b002dbf.png align="center")

---

## 4\. tree

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754634503396/b5a38814-fec1-4043-8b12-e4e79891e09a.png align="center")

This command outputs a tree-like view of the specified directory and its content (files, subdirectories). It makes it easier to look up the content inside a directory.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754637018202/a67a9987-db0f-4a2a-8e4c-a90d2d715f48.png align="center")

---

## 5\. cd

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754531997265/949f13d0-9970-4f77-b6d5-f783fbc799be.png align="center")

The **Change Directory** command is used for navigating between directories.

`cd ..` Moves up a directory

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754529443838/c1fdfdee-6f9c-44d4-a52f-3983c734e014.png align="center")

`cd -` Returns to the previous directory

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754529496502/668093d9-fda0-4616-b9a1-72f39fba712f.png align="center")

`cd` Goes to the user’s home directory

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754529579135/99804fc7-25c2-46fa-a6a8-b8889dc199f4.png align="center")

---

## 6\. mkdir

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754531941800/924dcb89-badd-4784-b3c2-b967df96ef21.png align="center")

`mkdir` stands for **Make Directory.** This command is used for creating directories.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754529799111/7c0f8050-7daf-45d3-bca4-1e4e8b73e192.png align="center")

Creating multiple directories at once.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754529857989/131f6c37-2b84-4ba5-85ed-d54687dececb.png align="center")

---

## 7\. cp

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754531825756/fb2328d1-d8ba-4fd0-bf97-fd5d4684bc3e.png align="center")

`cp` stands for **Copy.** This commands is used for copying files and directories.

In this example, I want to copy the **linux.txt** file into the **Documents** directory.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754530145735/90282962-ba12-4a61-b6cb-0ef8afc0125a.png align="center")

So here’s `cp` command for that.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754530264329/41b0c95e-1839-4551-b294-8ee5fbe00e37.png align="center")

Verifying inside the **Documents** directory.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754530318355/03e9195b-4b59-4c32-b721-f10ac80b6f5b.png align="center")

Note using `cp` with `-r` allows you to copy a directory with its content.

---

## 8\. mv

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754531885577/1908e427-396a-405a-a6e6-278ba0fdb7dd.png align="center")

`mv` stands for **Move**. This command is used for moving and renaming the files and directories.

Here I moved the **linux.txt** file from the current directory (***/home/dewnuwan/Documents)*** into the Music directory (***/home/dewnuwan/Music).***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754530658753/f59aeb07-40dd-476a-a57b-545c2bb905ca.png align="center")

Verifying inside the Music directory.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754530834862/884263ee-40ca-4a80-89aa-d6e23cd0bc68.png align="center")

While there’s a `rename` command in Linux, it’s only being used for batch operations. So most of the time we just use `mv` to rename the files and directories.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754531453882/09ed472a-6b2d-48cb-92ee-0ebbd2d588b7.png align="center")

---

## 9\. rm

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754532421659/e215ef01-6b1a-4812-b14d-e39e28c269a2.png align="center")

`rm` stands for **Remove.** This is used for removing files from a directory. You need write access for the folder. Here are the most used options for this command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754636310566/650e8f33-a793-4013-a38a-54ae6e2c1380.png align="center")

`-r` Remove the directory with its subdirectories (alternative to `rmdir`).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754636371190/85654232-3c0b-4d2d-8925-fa9d1f27e466.png align="center")

`-i` Prompt a confirmation message before deleting

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754636440552/ef476e0e-0fe7-4a0e-982b-7ed1c56bcb2b.png align="center")

`-f` Force delete (without a confirmation dialogue)

### Forceful Recursion

The most common and dangerous combination of options is `rm -rf`. This command will delete everything in the directory and its subdirectories without any confirmation. So use it carefully.

*Here* **\*** *stands for all in the current directory.*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754636681073/cadaadae-2c73-4b85-a2e1-a7237edfe244.png align="center")

---

## 10\. rmdir

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754532529062/ded88d78-7312-4c4f-8e31-099270e9ff2a.png align="center")

This is to remove a specified **empty directory**. Use the option `-p` to force the deletion.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754637745300/59788451-b33c-47b1-9cac-ce37e1e8e29e.png align="center")

---

## 11\. cat

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754639011233/01c31bd7-443b-453a-b09f-9939daa7d649.png align="center")

`cat` is used for viewing content inside of a file. (text files, scripts..etc)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754639479415/2ffbb2f2-bfe1-41d5-b7b7-1d85b10fb524.png align="center")

---

## 12\. echo

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754638171097/cd2886ca-d67d-4451-9d49-7a0cd783c1c9.png align="center")

`echo` is useful when we want to get an output of a line of text. This is very useful when creating shell scripts.

* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754638084749/464f4abe-7a17-4dd0-930b-0ce1231ef102.png align="center")
    

Similarly, it can also be used with `>` , to overwrite a text input to a file.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754650773200/9e536d19-4f92-43a1-bf10-ffa46e76f7f5.png align="center")

We can also use `echo` to append a line of text to a file with `»`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754650883630/47a76b49-c021-42c1-b256-25ef30e6a484.png align="center")

---

## 13\. touch

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754652635010/ec804e0b-a95a-4e50-9546-36df804dd3ce.png align="center")

`touch` is useful for creating new files. Simply enter the file name with the extension.

Here I created a simple Python script called **scripting.py** using `touch` and added a code using `echo`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754652987235/2e96e587-8580-4b6e-b9c5-c3e41fa66a75.png align="center")

---

## 14\. grep

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754653080989/143ef34e-e1d3-47fa-8d3d-598c104cf093.png align="center")

`grep` stands for **Global Regular Expression Print.** It is used for searching speicifc string or a pattern within a file OR filtering out the results from a command output.

Here I listed the content inside `/` directory. And I want to see only the results including "“**lib**”.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754653510882/ce70a4df-ba18-4b06-87f5-b0159ccbcba1.png align="center")

so I will filter the ls -l command by using what we called pipe. which redirects the output of the `ls -l` command through the `grep` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754653607668/559dc571-d95c-4507-b2dd-1f88f7d8625c.png align="center")

Note that now it’s only showing the results that include the “lib” in their name.

---

## 15\. locate

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754675283286/9e2234f2-a1d7-4f89-8c00-9acb7fc6cced.png align="center")

This is another simple but very important command. Very useful when it comes to finding the path of a specific file/directory by going through the whole system at once.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754675732285/87287d13-b70e-4f49-b68b-7625231f1f42.png align="center")

Note that `locate` uses a local database to locate anything. And that database is only updated once per day. So we’ll have to use `updatedb` command once before using locate sometimes with new files/directories.

---

## 16\. find

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754676394950/065d4baa-de5b-4a6d-8719-64409dee42fe.png align="center")

`find` is the top searching utility command that we can use to find anything we want within a specific directory. Unlike the `locate` command, `find` looks for files in real time, so there’s no need to wait for the database to be refreshed.

`-name` Search files using name

`-type` Search items using its type (For files use `f`, for directories use `d`)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754808995207/cb39f0ce-a86a-4f9d-aaed-24fdf9af4eb2.png align="center")

---

## 17\. sudo

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754809607422/8638789d-2edc-478e-bd0f-f0d8b002aaf6.png align="center")

`sudo` stands for **Super User Do.** It allows a regular non-root user (who is in the ***sudo group***) to execute commands as the superuser (administrator). Once entered you need to enter the user’s password. This is a regular command you’ll be using in a Linux system.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754809699147/eecf0cf6-94f1-4fe2-9c47-a7fff53a127b.png align="center")

---

## 18\. history

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754809882931/fc4cffaf-c84e-4537-b0d3-63a5fa927e36.png align="center")

`history` allows us to view the previously entered commands history in the terminal. This is very handy when it comes to troubleshooting.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754809818482/7cbdc9f9-a7cc-467e-96af-7c3a0ec26cc7.png align="center")

---

## 19\. man

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754810227418/fccb0d31-6377-4f86-a3b8-31069e977ffa.png align="center")

`man` stands for **Manual.** This is used to figure out what a certain command is doing. Basically allows us to read the manual written by the devs. Simply adds `man` before a command name.

This example shows the manual for the `rmdir` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754810092880/222f59a0-cb79-450d-a58b-2c4350c1213a.png align="center")

---

## 20\. nano

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754819037379/9b6c1455-114a-4452-9174-e48e9249e52c.png align="center")

`nano` is an easy-to-use simple text editor that comes preinstalled with many Linux distros.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754818983914/f78abc33-1e81-4b15-b26f-a551fd377ba1.png align="center")

Okay, so this concludes the second post in this **Linux** **Simplified** blog series. Let’s talk about **user and group management in Linux** in the next post!
