Linux OS & File System For Beginners

Photo by Luca Bravo on Unsplash

Linux OS & File System For Beginners

·

8 min read

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:

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.

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.

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

Syslog

Syslog is a protocol and utility for logging system information in Linux. 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.

Prompt

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

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

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

Basic commands of Linux

  1. SHELL - The most common shell is known as Bash.
echo $SHELL
  1. Stands for "print working directory". It shows the current directory you are in.

pwd
  1. ls: This command lists the contents of a directory. It shows the files and subdirectories within the current directory.

    Example: ls

ls

  1. cd: Stands for "change directory". It allows you to navigate between directories.

    Example: cd Documents

     cd Documents
    

  2. 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

mkdir my_folder
rmdir my_folder

  1. touch: Creates a new file if it doesn't exist without any contents.

    Example: touch my_file.txt

     touch my_file.txt
    

  2. cp: Stands for "copy". It copies files or directories from one location to another.

    Example: cp file1.txt /path/to/destination

     cp file1.txt /Desktop
    

  3. mv: Stands for "move". It moves files or directories from one location to another.

    Example: mv file1.txt /path/to/destination

mv file1.txt /path/to/destination

  1. rm: Stands for "remove". It deletes files or directories. Use with caution as it permanently removes files.

    Example: rm file1.txt

rm file1.txt

  1. cat: Stands for "concatenate". It displays the contents of a file.

    Example: cat file1.txt

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

  1. grep: Searches for a specific string within files.

    Example: grep "pattern" file.txt

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

  1. echo: Displays a line of text/string that is passed as an argument.

    Example: echo "Hello World": Prints "Hello World" in the terminal.

    echo "Hello World"
    

  2. 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

    Some advanced Linux commands:

    1. man: Displays the manual pages for other commands.

      man ls: Displays the manual page for the "ls" command.

    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.

    3. du: Estimates file space usage.

      du -sh: Shows the total space used in the current directory in human-readable format.

      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.

    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.

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.

  1. 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.

        chmod u+rwx,g+rw,o-r file.txt
        chmod u+x file.txt
        chmod u+w file.txt
      
  2. 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:

        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:

  3. 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.

  4. 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

  5. man: Displays the manual pages for other commands.

    • man ls: Displays the manual page for the "ls" command.


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. Follow me for more such blogs.

#LearnInPublic

Yash Pal 👾