Essential Linux Tutorial Every Beginner Should Know

In this Linux tutorial, I will list down important concepts related to the Linux/Unix operating system, its file structure and essential commands used globally.

What is Linux?

Linux is an open-source operating system designed and developed by Linus Torvalds. One of Linux’s key characteristics is its flexibility allowing for customization, resulting in the different variations or flavours of Linux distribution. Some trendy Linux flavours includes Ubuntu, Debian, CentOs, Fedora, Slackware and Oracle Linux.

Linux File Structure

At the core of every Linux distribution lies its file structure, which is hierarchical and organized to facilitate efficient system management. Here’s a breakdown of key directories and their purposes:

Linux Tutorial
  1. / (Root Directory): This is the top-level directory in the Linux file system. This contains all other directories and files. The Root directory is the home directory of the root/admin user.
  2. /home (Home Directories): Each user created in the Linux system has their own home directory located within /home. User-specific settings, files, and directories reside here.
  3. /bin (Binaries): The bin directory stores the executable files/programs known as binaries. bin commands can be executed by any user.
  4. /etc (Configuration Files): This directory stores the Configuration files for system-wide settings and applications.
  5. /var (Variable Data): This directory holds variable data files such as logs, databases, and temporary files, which are expected to grow in size over time, making it a crucial repository for dynamic system data.
  6. /usr (User Programs): This directory contains read-only User-accessible programs, libraries, and documentation that can be shared.
  7. /opt (Optional Programs): This directory is used to install optional software packages that are not the part of core OS.
  8. /boot: This directory is used to store bootable files.

Essential Linux Commands

Let’s explore some essential Linux/Unix commands.

1) Basic Navigation Commands

1. pwd (Present working directory): Where am I in the system?

pwd

/Users/AQH/Desktop //output

2. ls: List all the files in the current directory excluding hidden files.

3. cd (change directory)

4. ls -a: List all the files in the current directory including hidden files.

5. ls -l: List all the files with complete information.

The above image shows the list of all files present in the current directory along with the information like timestamp, permission, author etc.

2) File & Directory Commands

1. mkdir (Make Directory): Create new directories with the mkdir command. For example, “mkdir Documents” will create a new directory named Documents. The below command will create nested directories.

mkdir -p dir1/dir2/dir3 

2. touch filename/touch filename1,filename2: Create an empty file/ Create multiple empty files.

touch myfile
  or
tpuch myfile1,myfile2,myfile3

3. rm (remove): Used to remove files of directories.

rmdir documents
  or
rm myfile

4. cp (Copy): This command copies files or directories from one location to another using the cp command. For example, “cp <source><destination>” will copy file1.txt to the Documents directory.

cp file1.txt /home/user/Documents

5. mv (Move): The mv command is used to move files or directories to a new location as “mv <source><destination>”.

mv file.txt /tmp

The above command will move file.txt to the /tmp directory.

3) Cat Commands

1. Cat > filename — Create a new file and enter text directly into it from the terminal, ctrl+d (to exit).

2. cat >> filename — append new content to existing file.

3. cat filename — Describe file content

4. cat -n filename — Display file content with line number.

4) Network Commands

1. hostname: Describe hostname.

2. ifconfig: To see the network interface configuration.

3. cat /etc/os-release: To see Operating system-related information.

4. top: To see what is currently happening on the system.

5) Sorting and filtering

1. head filename: By default, this command displays the top 10 lines of the entire file.

head mydocument.text

2. head -3 filename: Will display by default the top 3 lines of the entire file.

3. sort filename: Rearrange file content in alphabetical order by default.

4. tail -n filename: This command displays the bottom n line of the file.

tail -5 mydocument.text

5. wc filename: This command Prints a count of lines, words and characters.

6) Users & Groups

1. useradd user/ adduser user: This command adds new users to the system. It stores the created user information in the /etc/password directory.

adduser username

    2. userdel: This command delete a user from the system.

    userdel username

    3. passwd: This command is used to change a user’s password.

    passwd username

    4. groupadd: This command creates a new group on the system.

    groupadd devops

    5. groupdel: This command is used to delete a group from the system.

    groupdel groupname
    

    6. usermod -aG: This command adds a user to a group.

    usermod -aG groupname username

    7. groups: This command displays the groups a user belongs to.

    groups username

    7) Search Commands

    1. grep “pattern” filename: The grep command is used to search keywords in the file content.

    grep "text" myfile

    2. grep -n “pattern” filename: This command displays the line numbers along with the matching lines in the file.

    3. grep “pattern1\|pattern2” filename: This command searches for lines containing either “pattern1” or “pattern2”.

    4. grep “pattern” file1 file2 file3: This command searches for the pattern in multiple files simultaneously, streamlining the process of text pattern matching across multiple files..

    grep "text" myfile1 myfile2 myfile3

    Conclusion

    Linux is a powerful operating system popular for its stability, security, and flexibility.By understanding Linux file structure and mastering essential Linux/Unix commands, we can harness the full potential of Linux.

    Discover more from AutomationQaHub

    Subscribe now to keep reading and get access to the full archive.

    Continue reading