# Linux OS & File System For Beginners

# *Why Linux?*

Linux is used by beginners as well as advanced programmers due to its scalability, ease of maintenance and it is user-friendly. Some of the other advantages are listed below:

* Security: Linux is more secure than many other operating systems.  It has built-in features like low user permissions and a community that regularly tests for vulnerabilities.
    
* Free: Linux is free to download and use.  Most applications written for Linux are also free.
    
* Open source: Linux is open-source software, so anyone can contribute, modify, and enhance the source code.
    
* Stability: Linux is highly stable.
    
* Customizable: Linux is highly customizable.
    
* Enterprise infrastructure: Linux makes it easy to configure and access your computer, check processes, and manage virtual environments.
    
* Scalability: Linux can scale across multiple systems for added efficiency and flexibility.
    

Take a quick refresher from this video and get on with this blog:

%[https://www.youtube.com/watch?v=rrB13utjYV4&pp=ygUTbGludXggYmVzdCByZXNvdXJjZQ%3D%3D] 

These are important files below in which we get the information about our system and where the data is stored when the user requires the data or wants to know the location of the files.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701758802830/668f0e8d-5950-4ede-9351-fd4aafcd41f9.png align="center")

# *Commands & Packages*

To get acquainted with the Linux operating system get to know about the current distribution of Linux you are using and other system info such as CPU and RAM. For beginner users we are using Ubuntu.

Some basic and important commands are posted below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1701760750668/31119935-bf8f-4b3d-9257-87a68ae83d58.png align="center")

You can also refer to the link below by Chad M Crowell which gives a cheat sheet about Linux.

%[https://github.com/chadmcrowell/linux-docker/blob/main/linux_cheatsheet.sh] 

## *Syslog*

Syslog is **<mark>a protocol and utility for logging system information in Linux</mark>**. It allows devices like routers, switches, and servers to send event messages to a central log server. These messages are called Syslog messages and include information like the date, time, device hostname, and message content.

This gives us an idea about where exactly our user details are stored on the Linux OS.

## *USER*

Now we are going to add the user in the root directory(in the root directory **the parent path to all files on the installation's partition**). All operating systems have a root directory. If you are familiar with Windows systems, they use the C:\\ path as their root directory.

We are using the BASH shell as our default shell.

Here is how you can add a user.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713028230894/202345cd-d1d8-47c9-8b0e-de3232fab5e6.png align="center")

## *Prompt*

Now we can also change our prompt to our preference. Follow along as I have mentioned in the snippet.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713029446833/11540a8e-ef0d-4cf4-b7e6-2d22c4dc10da.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713029538178/63af3f1b-fc94-493a-8fc2-bff27cd130b6.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713029764931/db721f7a-8ae5-4fd0-bc1b-6a65272de93a.png align="center")

Locate PS1 = "String" and replace it with your desired set of characters. I have used PS1 = "Punisher$ "

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713030045028/5f494933-0d2f-4b5c-87f8-c2c259cd0c13.png align="center")

Done you are now set to use your default created prompt. Try out and play around with different things.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713089143849/ba1f10a2-9779-4ddb-8c99-14afdcc75ef4.gif align="center")

### Basic commands of Linux

1. SHELL - The most common shell is known as Bash.
    

* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713032063416/323d9595-d070-481c-8bec-15242e95a3fe.png align="center")
    

```bash
echo $SHELL
```

2. Stands for "print working directory". It shows the current directory you are in.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713032698517/f626c68d-3e6c-46c6-91b0-a38b976da0b9.png align="center")

```bash
pwd
```

3. **ls**: This command lists the contents of a directory. It shows the files and subdirectories within the current directory.
    
    Example: `ls`
    

```bash
ls
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713032961741/759a36b1-1827-4976-95ae-7a188d3d70d6.png align="center")

4. **cd**: Stands for "change directory". It allows you to navigate between directories.
    
    Example: `cd Documents`
    
    ```bash
    cd Documents
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713033010776/756cfcc7-ce04-4c4c-9c2e-56725f7a287b.png align="center")
    
5. **mkdir and rmdir**: Stands for "make directory" and "remove directory". It creates a new directory and the latter one deleted the directory.
    
    Example: `mkdir my_folder`
    

```bash
mkdir my_folder
rmdir my_folder
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713033070689/c6f9b240-532b-4cfa-92e9-953a139df8a6.png align="center")

6. **touch**: Creates a new file if it doesn't exist without any contents.
    
    Example: `touch my_file.txt`
    
    ```bash
    touch my_file.txt
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713033211899/c9098a4c-72c0-4578-b4be-4585c939c9ad.png align="center")
    
7. **cp**: Stands for "copy". It copies files or directories from one location to another.
    
    Example: `cp file1.txt /path/to/destination`
    
    ```bash
    cp file1.txt /Desktop
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713033390604/5235c6fd-b71f-4f07-974f-f80cdfd3e8b9.png align="center")
    
8. **mv**: Stands for "move". It moves files or directories from one location to another.
    
    Example: `mv file1.txt /path/to/destination`
    

```bash
mv file1.txt /path/to/destination
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713033441041/6eaadf85-abfb-4239-a1ea-815ff6c32926.png align="center")

9. **rm**: Stands for "remove". It deletes files or directories. Use with caution as it permanently removes files.
    
    Example: `rm file1.txt`
    

```bash
rm file1.txt
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713033519404/7248601a-07c5-48b0-89f6-b4cc889ad9d6.png align="center")

10. **cat**: Stands for "concatenate". It displays the contents of a file.
    
    Example: `cat file1.txt`
    

```bash
echo "Content to write in the file" > file1.txt
cat file1.txt
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713033792293/5b2f2cbe-311d-49b7-99b5-4443c6afc6c7.png align="center")

11. **grep**: Searches for a specific string within files.
    
    Example: `grep "pattern" file.txt`
    

```bash
echo "Content to write in the file pattern" > file.txt
grep "pattern" file.txt
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713033949352/d49c1a1a-a89a-40e4-bde7-2cd6c90cf663.png align="center")

12. **echo**: Displays a line of text/string that is passed as an argument.
    
    **Example:** `echo "Hello World"`: Prints "Hello World" in the terminal.
    
    ```bash
    echo "Hello World"
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713078818218/ce50859e-9cc0-4a30-9df3-0287ddb12644.png align="center")
    
13. **sudo**: `sudo` stands for "superuser do". It is used in Linux and Unix-like operating systems to allow users to run programs with the security privileges of another user, typically the superuser (root).
    
    Example: `sudo su - yash` and `sudo apt-get update`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713077878346/25d99d34-9387-4bb6-a7c1-21e777a40c3c.png align="center")
    
    ### Some advanced Linux commands:
    
    1. **man**: Displays the manual pages for other commands.
        
        `man ls`: Displays the manual page for the "ls" command.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713079074128/03a6bf40-666b-4428-b8f5-456240c98d50.png align="center")
        
    2. **df**: Reports disk space usage.
        
        `df -h`: Shows disk space in human-readable format (e.g., KB, MB).
        
        **Note:** The -h flag refers to the human readable format which commands the terminal to show the given information in human readable format.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713079100325/ac6379be-4a43-4d48-b983-2822e9314e1d.png align="center")
        
    3. **du**: Estimates file space usage.
        
        `du -sh`: Shows the total space used in the current directory in human-readable format.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713079342039/38c0830f-e248-460a-b555-23b21aa175b5.png align="center")
        
        Fun exercise: Enter `du -h` in terminal and try to limit it to say 5 lines or 10 lines. If you were not able to do it follow along I will showcase you how it is done ;)
        
    4. **ps**: Displays information about active processes.
        
        `ps aux`: Shows a detailed list of all running processes.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713079511107/6358281e-5deb-4949-8861-1c90414a8f44.png align="center")
        
    5. **kill**: Sends a signal to a process, usually to stop the process.
        
        `kill -9 -1`: Kill all processes you can kill.
        
    6. **vim**: `vim` is a powerful and popular text editor in Unix-like operating systems. It is an improved version of the traditional Vi editor and is highly configurable and extensible.
        
    
    Example: `vim filename.txt`
    
    This command opens the `filename.txt` file in the vim text editor, allowing you to view and edit its contents.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713077923862/422c35d0-fa24-41e2-b6c1-70f4f9780316.png align="center")
    
    **Basic vim commands:**
    
    * **Normal Mode**: This is the default mode where you can navigate the document and execute commands.
        
    * **Insert Mode**: Allows you to insert and edit text.
        
    * **Command-Line Mode**: Used for executing commands and saving changes.
        
    
    **Exiting Vim**:
    
    * To exit Vim and save changes: Press `Esc` to enter normal mode, then type `:wq` and press `Enter`.
        
    * To exit Vim without saving changes: Press `Esc` to enter normal mode, then type `:q!` and press `Enter`.
        
        **Editing Text**:
        
        * **i**: Enter insert mode before the cursor.
            
        * **a**: Enter insert mode after the cursor.
            
        * **x**: Delete the character under the cursor.
            
        * **dd**: Delete the current line.
            
        * **yy**: Copy the current line.
            
        * **p**: Paste the copied or deleted text after the cursor.
            
    * **Saving Changes**:
        
        * **Enter ":w"**: Save changes to the file.
            
        * **Enter ":w filename"**: Save changes to a new file.
            
        * **Enter ":wq"**: Save changes and exit Vim.
            

These are just a few basic commands to help you get started with Vim. Vim has many more features and commands, so feel free to explore and experiment as you become more comfortable with it.

7. **chmod**: Changes the permissions of a file or directory.
    
    * **chmod u+x filename**: Adds execute permission to the user.
        
    * **chmod u+r filename:** Adds read permission to the user.
        
    * **chmod u+w filename:** Adds write permission to the file user.
        
        ```bash
        chmod u+rwx,g+rw,o-r file.txt
        chmod u+x file.txt
        chmod u+w file.txt
        ```
        
8. **chown**: Changes the owner and/or group of a file or directory.
    
    * **Changing the Owner of a File**
        
        To change the owner of a file named `document.txt` to a user named `john`:
        
        ```bash
        chown john document.txt
        ```
        
        So now lets see how we could've tackled the problem we were getting when we enter the command `du -h` , we were getting bombarded with the information right. So what we are going to do is limit the lines of information to understand it more clearly. For that we use:
        
9. **head**: Outputs the first part of files.
    
    **Example:** `head -n 5 file.txt`: Displays the first 5 lines of file.txt.
    
    `ps aux | head -n 5` : we can use '|' to run multiple commands in one go. This is called a **pipe**.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713080622138/ad7571b8-67cf-464f-85d9-f52fbb8edf8b.png align="center")
    
10. **tail**: Outputs the last part of files.
    
    Example: `tail -n 5 file.txt`: Displays the last 5 lines of file.txt.
    
    `ps aux | tail -n 5`
    
    * ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713080748327/35c5a3b7-3330-4ff1-84ba-ba39e4613133.png align="center")
        
11. **man**: Displays the manual pages for other commands.
    
    * `man ls`: Displays the manual page for the "ls" command.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713080892994/8ce5202a-2ce3-45a3-b63a-496b28b7f54b.png align="center")
        

---

## Conclusion

Now we conclude this blog which was about introducing Linux to beginner developers and kickstart their developer journey into a fun and interesting one. Did you know in the world around 3 - 3.5 billion people use linux and this numbers keeps increasing every year and you are now one of them congratulations for this amazing feat.

Congratulations on taking this first step, and may your Linux adventure be filled with discovery, learning, and endless possibilities. Happy coding!"

Don't forget to like and share this post if you liked this blog. Connect with me on [**Twitter**](https://twitter.com/yashtwtss). Follow me for more such blogs.

#LearnInPublic

[Yash Pal](https://github.com/yashpal2104) 👾
