Introduction to Linux

Kasturi NithinKasturi Nithin
4 min read

Linux is yet another powerful operating system widely used by people who give more priority to aspects like security ,multi-tasking and portability.

Linux Distributions

Various distributions of linux exists in the market.

  • Ubuntu

  • CentOS

  • Kali Linux

  • Fedora and more..

If you are a beginner Ubuntu distribution of linux is more suitable to you .Ubuntu is user-friendly with an interactive user-interface and it is open source as well .

Directories in linux and thier purposes:

Linux organizes the filesystem in an hierarchical structure ,starting from /

  • / (Root directory)- Top level directory which consists of all files and directories.

  • /bin (Binary) - Consists of essential user commands and binaries that are required by the user to operate . Example : ls ,cat ,mv ,cp .

  • /sbin (System Binaries)- It is similar to /bin ,but it consists of binaries require by rootuser.

  • /etc (Configuration files) - Consists system wide configurations and scripts.

  • /home - Store personal directories of the users. Each user’s data and files reside here.

  • /var (Variable files) - Stores all the files that are expected to be frequently changed.

  • /tmp (Temporary files) - Stores temporary files that are created by applications.

  • /lib (Libraries) - Contains shared libraries required by binaries in /bin and /sbin.

Important commands of linux :

  • pwd(Present Working Directory) - As the abbreviation states , it is used to give the present working directory path.

  • ls - Used to list files and directories.

  • cat -Displays file contents .Syntax : cat FILE-NAME

  • touch - creates a file.

  • mkdir - Used to create a directory.

  • rmdir - Used to delete a directory.

  • rm - Used to remove files or directories.

  • chmod - Change file permissions.

  • chown - change file ownership.

  • whoami -Shows the current user’s name.

  • adduser - Used to add a user.

  • deluser - Used to delete a user.

  • history - Used to list the commands used previously.

About sudo:

SuperUser Do is a command in unix/linux based systems used to operate as superuser .It performs operations that cannot be performed by regular user.

It is not recommended to use root user in every aspect ,instead we need to create users and groups, and play around with them.

Create a User:

Command to create a user is ‘sudo adduser USER-NAME‘. This creates a user with the provided name .Set password for the user and you are all set.

To check whether the user is created or not . Head to ‘etc’ directory and print the content of ‘passwd’ file .You can see the created user details at the bottom . Use the following command “cat /etc/passwd”.

To switch to the user you just created use the following command : “su USER-NAME“ .

Create a group:

We need to create groups to add users to it ,so that the users in group are restricted to perform only certain operations.

Command to create a group and add user to it : “sudo addgroup GROUP-NAME”, “sudo usermod -aG GROUP-NAME USER-NAME”.

Permissions:

Root user has to give permissions to the normal users inorder to let them perform specific action like read ,write and execute.

4-2-1 terminology :

  • 4 - read

  • 2 - write

  • 1 - execute

  • 4+2+1 = 7 full permissions to read, write and execute.

  • 4+1 = 5 read and execute permissions only .

  • 1+2 = 3 write and execute permissions only.

  • Other possibilities like 6,1,2,… etc.

Confused? Let us understand with an example command “sudo chmod 754 FILE-NAME“. Here in number 754 the unit’s digit place is for permissions to others, i.e 4 ,so others only can read. Similarly ten’s digit place is for permissions to group ,that i.e 5 [4+1] ,so groups can read and execute and finally hundered’s digit place is for permissions to owner ,i.e 7 [4+2+1],so owners can perform all the operations.

Now lets create a directory and give read only permissions to others, write + execute to groups and all permissions to owner.

Head to root directory, follow the steps:

  • “sudo mkdir first-folder“ [Create a folder]

  • “sudo touch first-folder/first-file“[Create a file]

  • “sudo chmod 734 first-folder“[Give the specified permissions]

  • And that’s it .

0
Subscribe to my newsletter

Read articles from Kasturi Nithin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kasturi Nithin
Kasturi Nithin

Exploring something new.