Linux for Everyone..

Anubhav Singh
9 min readDec 27, 2020

In this blog we cover Linux 🤔, No All about linux 😬. This blog helps you to know the basic understanding of linux and their useful commands.

What we cover in this blog —

1- Introduction of Linux.

2- Kernel & Shell

👉3- Command usages

4- Types of command location

5- User & Group

👉5- Commands

Linux is a community of open source Unix like operating system that are based on the Linux Kernel. It initially released by Linus Torvalds on September 17, 1991.

I said NO

Linux is the best-known and most-used open source operating system. As an operating system, Linux is software that sits underneath all of the other software on a computer, receiving requests from those programs and relaying these requests to the computer’s hardware.

Kernel

Kernel is the Core of a computer operating system with complete control over everything in the system. It virtualizes the common hardware resources of the computer to provide each process with its virtual resources.

The Kernel is also responsible for preventing and mitigating conflicts between different processes. File management, Process management, I/O management, Memory management, Device management.

Shell

A special user program which provides an interface to the user to use Operating system services. “Shell accepts human readable command from the user and convert into something which Kernel can understand.”

The Shell gets started when the user starts the terminal.

Shell communicate with Kernel and Kernel have direct communication with Hardware

Shell is broadly classified into two categories —

  • CLI (Command line Interface)
  • Graphical Shell = GUI (Graphical User interface)

There are several shells available for Linux systems like BASH (Bourne Again SHell) — It is most widely used shell in Linux systems.

👉Command Usages(Important😶) —

When you open your terminal you can find some lines are pre writen like anu@localHost work $ this is called Prompt.

anu -> user name, localHost -> computer name, work -> working directory.

  • All linux commands are single-word commands.

Command Syntax —

General command syntax

Option in command -

$ ls -l

Option is a special kind of argument of command, which is preceded with a minus(-) sign to differentiate it from filename.

  • There must not be any white space between ‘-’ and ‘l’ but there must be whitespace between the command and the argument.
  • Options can be combined with only one ‘-’ sign
    ls -lat abc is the same as ls -l -a -t abc

Flexibility in command-

$ ls; pwd

  • Linux allows you to write more then one command in a line, Each command is separated by (;) semicolon.

Through semicolons the shell understands that the command of each side needs to execute. And the command execution is performed from left to right.

  • Any number of spaces can be used between command and argument. Minimum 1 space is must to enable the system to interpret them as words.

User & Group —

Linux provides us with 3 types of Users namely,

  1. Root User
  2. System User
  3. Normal User

Root User- Root user has access to run all types of commands and files in linux. He can act as system admin and perform various system actions. like Changing passwords, examining log files etc.

System User- System user is needed to handle the system account, take care of the operation of system-specific components. like a mail account, edit files.

Normal User- They are created by Root users, they provide access to other users or groups.

Commands —

  • $ useradd [option] name_of_user :- To create a user account to your system.
  • $ passwd [option] name_of_user :- “passwd” command is used to change the user account password.

The root user reserves the privilege to change the password for any user on the system. While normal user only change his own password.

Adding password to user ‘decryptor’
  • $ useradd -u user_id name_of_user :- To create a user with specific user id we use -u option while for specific group -g option is needed.
  • $ userdel name_of_user :- The ‘userdel’ command is used to delete a user account and related files. -f option is used for force delete; it doesn’t matter if the user is still logged in or not.

Group —

Basic commands of groups are similar to users with ‘group’ keywords. Like create, delete group.

  • $ groupmod -n new_name old_name :- Changing the name of the group command consists of ‘mod’ = modification and -n option is used to identify the new name.
  • add multiple users in a group by using -M option $ gpasswd -M user1, user2, Host_groupname

Locating Command-

Every command in Linux is stored in a local machine and when a particular command is executed it gets called from that particular location.

  • To know the location of command use command $ type command_name

Location is of 2 type- 1} Internal Command, 2} External Command

Internal Command- Command which are built into the shell. Execution of the same command is fast because the shell doesn’t have to search the given path. Also no process needs to be spawned for executing it. Eg cd, fg etc.

External Command- When external commands have to execute, the shell looks for the path given by the PATH variable and also a new process has to be spawned and the command gets executed. They are actually located in /bin or /usr/bin. Eg ls, cat etc.

Example of both Internal and External command

Commands-

We classify our command on the basis of uses — (👉Must try all commands in your terminal for better understanding)

🤜1- General purpose commands

🤜2- cat commands

3- cp, mv, rm commands

4- Pipe and Tee

🙌General Purpose commands —

Im trying to add all the general use commands in this section.

  • man -: $ man ls man stands for manual. Used to give a description of any linux command.
  • ls -: $ ls ls stand for list. Used to display list of files and directories in the given path.

-a, -l, -r, -s, -R, -r, -d options are used with ls command, -a:- Show all the files even hidden(start with .)files of directory. -l:- List of all attributes of all files in the current directory. -r:- reverse the order of presentation sorted in reverse ASCII order. -s:- s Stands for size the bigger files first in the output. -R:- Display subdirectory as well. -d:- Display only directory.

  • cd-: $ cd file_name cd stands for change directory. Used to change the directory.
  • open-: $ open file_name this command is used to open argument file.
  • start-: $ start file_nameused to display information about file.
  • cal-: $ calcommand for calender argument is optional. $ cal month_number year_number us also commonly used.
  • date-: $ datesimply display date and time.
  • echo-: $ eco “Hello world”- This command is used to display a line of text of variable.
  • file-: $ file file_name- file command determines the type of file.
  • wc-: $ wc file_name- Used to count word, line and character in a file

-l, -w, -c are optionals used with wc command accordingly. We can use the wc command for multiple files at the same time. $wc file1 file2 file3.

  • sort-: $ sort file_name - sort command is used to sort the content of a text file, line by line.
  • ‘pwd’-: $ pwd - This stands for ‘present working directory’ and the command displays the directory in which you are presently working.

r, -n, -k, -c options are used with sort command. -r -: reverse, -n-: numerically, -k-: sort a table on column basis. -c-: is used to check if the file given is already sorted or not.

  • mkdir-: $ mkdir directory_name — this command is used to create a new directory. $ mkdir directory_name1 directory_name2 used to create more than one directory.
  • rmdir $ rmdir directory_name — is used to delete/remove the directory. $ rmdir directory_name1 directory_name2 used to remove more than one directory.

The rmdir command can only be used to remove a directory if the directory is empty. You cannot remove a subdirectory unless you are placed in a directory which is hierarchically above the one you have chosen to remove.

🙌cat (A Versatile) commands —

cat(concatenate) command is very frequently used in Linux. It reads data from the file and gives their content as output. It helps us to create, display content, concatenate and append to a file.

  • Create File — $cat > file_name we can create a file using command cat with > symbol.
  • Display content of file — $cat file_name . Display more then one file at a time using cat command with multiple file names. $cat file1 file2 file3
  • copy the content of one file to another file by using > between sender file and recover file. $cat file_whoseContentIsToBeCopied > destination_file
  • add more inputs to an existing file using cat command with >> as a option $cat>>file_name
  • -v — option is used to display non printing characters.
  • -n — option display line number with each lin.
example of each cat command

cp, mv, rm command —

The cp command is used for copying a file in linux and the mv command is used for two purposes: move and rename the file name and rm for remove/delete a file.

It copies a file or a group of files, the syntax requires two file_names the first file is copied to the second file.

  • If there is only one file to be copied, the destination can be either a specific file or directory. While if we copy more then one file than the last argument(destination) must be a directory.
  • $ cp file1 file2 if the destination file doesn’t exit, it will first create then copy.
  • $ cp file1 file2 file3 dirl in this example we copy 3 files to dirl directory.

Options — -i Interactive option warns the user before overwriting the destination file. -R copy an entire directory structure. (recursive search for all subdirectories and files within these subdirectories). -f force.

deletes all the content inside Music including the parent folder
  • if the last argument of mv command is directory then mv command moves the file to directory, and if with the 2nd argument is new_name then mv command rename the file.

All these options are the same for mv and mr commands. Try some examples of mv and mr command. I think mentioning all the options with mv and mr command is just making this blog bigger, not crunchy.

🙌Pipe and Tee command —

A pipe is used to combine two or more commands, and in this the o/p of one command acts as input to another command, so on. It can also be visualized as a temporary connection between two or more commands.

Syntax-

$ comd1 | comd2 | comd3 |….| comdn

eg- $ ls | wc -l = This command gives us the number of files in the directory in which we are. ls gives o/p as a list of files which is used as i/o by 2nd command to count that i/o file.

tee command reads the standard i/p and write it to both the standard o/p and one or more files. It basically breaks the o/p of a program so that it can be both displayed and saved file. It does both tasks simultaneously.

It saves one copy in a file and writes the other to standard output

Syntax-

$ command | tee file_name(to save the o/p)

eg- $ ls | tee list = O/p is saved into a file named list and result will automatically displayed.

Thank You for Reading this blog. Hope you doing well 🤘. Wish You Happy New Year 2021( in advance).

--

--

Anubhav Singh

GSoC’20 @Amahi | iOS developer | open source contributor