# Linux basics - Tutorial 1[redhat]

## Redhat Linux Basics - Tutorial 1.

### After going through this you will be comfortable in Linux terminal and basic linux commands.

#### Understanding the terminal

![Linux user presence-root](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/15ff1e88-df05-46ac-b567-ab17e5a55dca.png align="center")

**What does the above picture show?**

Let us understand each element one by one.  
Content shown in the pic - \[root@ip-172-31-16-22 ~\]#.

*   root - This indicates you are logged in as root user
    
*   ip-172-31-16-22 - This shows the hostname
    
*   ~ - This indicates you are inside the home directory of root user. Ex. /home/root
    
*   '#' - This indicates you are logged-in as root user.
    

**Note: / is called the root directory. It is the top most directory in Linux.**

Command to display the **username** you are currently logged in as.

```bash
whoami
```

If you type this in the terminal you will get the current username as shown in the output below.

![whoami-yolo-output](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/ab42c9ae-3d1a-4393-93bf-1833877fda40.png align="center")

Command to display the **hostname**

```bash
hostname
```

If you type this in the terminal you will see the hostname as shown in the output below.

![hostname-output](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/425367d8-1db9-4dca-bcee-30078c121882.png align="center")

Command to **switch user from root user to any user who is already there on system**

```bash
su - username
```

If you type this in the terminal you will switch to the username as shown in the output below.

![bancho-user-yosum](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/40c53ef4-d7bd-4e25-b81f-8369dfc91bd1.png align="center")

Command to **switch from any user to root user**

```bash
sudo -i
```

If you type this in the terminal you will switch to the root user as shown in the output below.

![lobhichodon-root-huten](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/2b8b52b7-91a4-4c58-84c4-97fd3faeb274.png align="center")

Command to **print your current working directory**

```bash
pwd
```

If you type this in the terminal you get the output as shown below

![Hole ole lollei](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/841dea97-7ce8-4fa0-84b7-f20dfd38d119.png align="center")

.

Command to **clear** the terminal

```bash
clear
```

If you type this in the terminal you get the output as shown below

![clear output](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/f246fde0-d2bf-4634-ac21-63ed420cbeaa.png align="center")

**Note: To clear the terminal you can also use Ctrl+l**

Command to see the **history** of all commands you executed in the terminal in the current session

```bash
history
```

If you type this in the terminal you get the output as shown below

![history output](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/0bb2698a-1503-4a14-8626-6e0b5af2cfa7.png align="center")

.

Command to see the **manual** of any linux command

```bash
man history
```

If you type this in the terminal you get the output as shown below

![maual output](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/b812a112-010c-4c62-812f-72171feaa5a4.png align="center")

**Note: To syntax is man <any\_linux\_command>. You open the manual of the command, then press q to exit out of manual.**.

Command to **list** files and directories

```bash
ls
```

If you type this in the terminal you get the output as shown below. This just lists the files and directories in the present working directory.

![ls bitches](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/3d1901ec-678d-4268-b747-d6a25f428b27.png align="center")

Command to long **list** files and directories

```bash
ls -l
```

If you type this in the terminal you get the output as shown below. This lists the files and directories in the present working directory with additional details.

![long list bitches](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/b60f7bb1-7bd1-496d-ad07-7f6225b0a725.png align="center")

Command to **list** all files and directories along with hidden files also.

```bash
ls -a
```

If you type this in the terminal you get the output as shown below. Shows all files, including hidden files and directories (those whose names start with a .)

![ls encrypted](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/8ff3c5da-0ed6-489a-938f-ecbd44ceaa96.png align="center")

Command to see the current **date and timestamp**

```bash
date
```

If you type this in the terminal you get the output as shown below.

![date-time](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/bed55d3c-80c7-40b8-ad76-7f14f768fe74.png align="center")

Command to **change directory**. Syntax cd your-directory-name.

```bash
cd ubuntu
```

If you type this in the terminal you get the output as shown below. This navigates you to ubuntu directory.

![navigate folder](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/d952d746-b79c-4bec-bc38-2b0a5f0f5075.png align="center")

**Note: There are many things you can do with *cd* command using paramaters. Let me show you some below. Please explore on your own also.**

Command to **change directory**.

```bash
cd /
```

If you type this in the terminal you get the output as shown below. This navigates you to root directory.

![root directory](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/846e1123-c9a1-4f7c-828d-050bf681655b.png align="center")

Command to **change directory**.

```bash
cd ~
```

If you type this in the terminal you get the output as shown below. This navigates you to user's home directory.

![users home directory](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/467605d0-5a54-4edb-a5bb-02b54bb50b87.png align="center")

Command to **change directory**.

```bash
cd -
```

If you type this in the terminal you get the output as shown below. This navigates you to user's previous working directory.

![previous-directory](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/f2423b77-1218-406c-91bb-e4dc3f668eae.png align="center")

You can also use.

```bash
cd ..
```

#### Understand Important Directories

```text
/
```

Root directory

```text
/home
```

Users' home directories

```text
~
```

Current user's home directory

```text
/root
```

Root user's home directory

Command to display **calender**.

```bash
cal
```

If you type this in the terminal you get the output as shown below.

![see the dates](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/0c6adf94-ed77-41a9-b76a-711f6935da17.png align="center")

Create **single directory**

```bash
mkdir demo
```

Create **multiple directories**

```bash
mkdir dir1 dir2 dir3
```

If you type this in the terminal you get the output as shown below.

![directories](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/9ed51a2a-0938-4fd9-acc8-1a027d2101ca.png align="center")

Remove **Empty Directory**

```bash
rmdir demo
```

If you type this in the terminal you get the output as shown below.

![remove folder](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/368dce60-37dd-47a8-95f2-2d7df0992c19.png align="center")

Create **Empty Files**

```bash
touch file1.txt
```

Create **Multiple files**

```bash
touch file11.txt file2.txt file3.txt
```

If you type this in the terminal you get the output as shown below.

![files created](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/74d2593c-27ed-4f99-8747-d5b9c6ee889b.png align="center")

Remove a **file or multiple files**

```bash
rm file11.txt file2.txt file3.txt
```

If you type this in the terminal you get the output as shown below.

![dletedfiles](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/3b26319a-c075-45c8-a32a-f61549cabece.png align="center")

Create a **directory or multiple directories**

```bash
mkdir newfolder
```

If you type this in the terminal you get the output as shown below.

![Directoies](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/c6c7984e-53f2-48a3-975e-6ccb15fb4b89.png align="center")

Delete a **empty directory or multiple directories**

```bash
rmdir fol1 fol2 fol3
```

If you type this in the terminal you get the output as shown below.

![Delete direc](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/92037bbc-4980-4e15-b1ad-b42b219527d6.png align="center")

Delete a **directory with content inside**

```bash
rm -rf ubuntu
```

If you type this in the terminal you get the output as shown below.

![force delete](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/f452534c-e2c1-4d71-9b5d-f8870b8984c5.png align="center")

**Note: This is also the command to perform a force delete.**.

To know location of **any command or software**

```bash
which ls
which python
```

If you type this in the terminal you get the output as shown below.

![which man](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/15ce8024-896e-41ba-be5f-64932a816ec7.png align="center")

To know location of **file or folder**

```bash
find newfolder
```

If you type this in the terminal you get the output as shown below.

![find-this](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/64e240fc-27d4-4030-8906-ddf4d18c97b4.png align="center")

To **write** contents in a file

```bash
nano mytextfile 
```

After typying the text save and exit using Ctrl+x and Enter keys on keyboard. Keep in mind nano editor is used here, you can also explore and learn about vim editor.

If you type this in the terminal you get the output as shown below.

![Screenshot 2026-07-27 at 9.07.30 PM](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/4a5b3ac9-08f8-472f-a6db-b29492bad759.png align="center")

To **see** the contents of a file

```bash
cat mytextfile
```

If you type this in the terminal you get the output as shown below.

![I said 23](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/43437159-c9d2-4402-8b11-6d35e09d7843.png align="center")

To **find** a word in a file use **grep**

```bash
grep linux mytextfile
grep -i Linux mytextfile #ignores case sensitive
```

If you type this in the terminal you get the output as shown below.

![Screenshot 2026-07-27 at 9.15.22 PM](https://cdn.hashnode.com/uploads/covers/62db945e38759e6b49829749/bdb1f1eb-0e85-444d-b6c7-2754fb534eae.png align="center")

**With this we come to the end of the tutorial 1 of Linux. Thank you for going through this. See you all in part two.. Until then Happy Learning 😀**
