19
May

Linux Inode

Linux Inode


What is Inode?

Inode is abbreviated as Index Node. As we know in Linux, whatever is there is a file. So, in order to maintain a consistency by treating everything as a file (even the hardware devices). The monitor, hard disk, printer, mouse, keyboard or directories are also treated as files in Linux. The regular files contain data such as text files, music files (mp3, mp4, audio etc.), video (multimedia files ) etc. Keeping aside the regular data, there is some other data about these files such as their size, ownership, permissions, time stamp etc. This meta data about a file is managed with a data structure known as Inode.

Where is Inode stored?

In Linux, file is stored in two different parts of a disk – the data blocks and the Inodes. The data block contains contents of a file. All other information about the file is stored in Inode.

Example1 : Rename a directory dir1 to Directory_1 which is in your current path

Syntax:

Kindly note that Inode number of dir1 will be same as Directory_1. In order to view properties of a directory, use ls –d  command.

Example2 : Prompt for confirmation before overwriting Examine.txt in /tmp directory

Syntax:

This is used while we are taking a backup so that updated file is stored and kept for use.

The input required during the prompted confirmation is:

  • For yes : YES, Y, yes, y
  • For no : NO, N, no, n

When the destination file permission is different than source file, mv –i  command will display the confirmation in following way:

Example3 :Move multiple files in specific directory. ( Let’s say  we have Linux_Lect1, Linux_lect2 and we need to move it to Linux_tuts directory). We have both Linux_lect1, Linux_lect2 in my current path:

Syntax:

Example4 : Take a backup of Destination file “Examine“ before overwriting a file:

Using a mv command  with – – suffix  option we can take a backup of destination file before overwriting .  The destination file will be moved with the specified extension:

–S

or

–suffix option.

Syntax:

Backup for Examine file is taken and changed to Examine.doc

Example5 : Suppose there are 10 files in directory d1 and we have copied any 8 files in directory d2. Now, we need to copy rest of the 2 files in directory d2.

Syntax:

-u option will perform update only if the source is newer than destination file






16
May

Linux ECHO Command

Linux ECHO Command


 

Usage of Linux ECHO Command:

This command is very important command widely used in bash and c shells. It is used to display a line of text/string on standard output or a console.

Syntax:

Example1 : Input a line “Hi, this is my session 2” and display on standard output.

pic1

Example2 : Declare a variable x and assign its value let’s say 30. Then, echo its value i.e. print value of x.

pic2

Example3 : Print statement “ I Love Linux” with no space using echo.

Explanation: Usage of \b as backslash interpreter.

pic4

Example4 : Print all words of a string keeping one word in each line. Lets take string as “I Love Linux”.

Explanation: \n is used as next line interpreter.

pic5

Example5 : Print all files and folder in current path using echo command (an alternative of ls command).

 


 






16
May

Linux CP Command

Linux CP Command


 

Usage of Linux cp Command:

This command is used to copy one or more files from source path to destination path.

Syntax:

Example1 : Make a copy of file into same directory.

Explanation:

  • Creates a copy of “originalfile” in present working directory. The copied file will be named as “newfile”.
  • Be very cautious while running the above command. If in case any file named as “newfile” exists in the same directory, it will be overwritten without confirmation prompt. This is the default behavior of cp command.
  • If you want to be prompted while overwriting a file, use interactive option (i). For example : # cp –i originalfile newfile. If “newfile “  exists , you will be prompted as:

    • cp : overwrite ‘newfile’?
  • If you type any of the combination (y,Y,yes,YES), the newfile will be overwritten and if you type any of the combination (n,N,no,NO), the newfile will not be overwritten, i.e. command will be nullified.

 

Example2 :Copy a file named as originalfile to another location say (/home/root). 

 

Or

Both syntax are same. The forward slash-dot (/.) is implied in second command (the dot is very special in every Linux directory which means  “this directory”).

Suppose originalfile is at following path: /home/root/folder1/contentfile. Then, above syntax will be written as:

Example3 : Copy a file named as originalfile to another location say (/home/root) with a new name testFile.

Example4 : Copy all files starting with word “testing” from home directory of user “root” to home directory of user “govind”.

Note : Asterisk (*) is a wildcard or special character which expands to match other characters.

Example5 : Copy all files from the home directory of root to home directory of user ram.

Example6 : See what cp command is doing.

Example7 : Create backup date of each copied file.

If destination folder already have a file and we know that by using cp command, it will overwrite the same in destination directory. So, we use – backup option , cp command will make a backup of each existing file.

–backup=simple option will create a backup file which will be marked by a tilde sign(~) at the end of file. —backup option has following control options:

  • none, off: no backup will be created (even if –backup is given)
  • number, t : make numbered backup
  • existing, nil : numbered if numbered backup exist, simple otherwise.
  • simple, never: always make simple backups.
Assignment

Few questions with their answers are present in assignment section for this command.


 





15
May

Linux LS Command

Linux LS Command


 

Usage of Linux LS Command:

This command is used to get list of files & folder at a particular path. Suppose there is a folder containing files and you want to know what all files are there in that folder we use this command. We use certain switches to get desired output.

Syntax:

Example1 : List all files in a folder.

pic1

Example2 : Show all the files of a directory, size, modified date and time, file and folder name and owner of file and its permission.

pic2

Example3 : View all hidden files in the folder.

pic3

Example4 : Know all files and directories in a current folder.

pic4

All files which are followed by / are directories and rest are files.

Example5 : List all files in reverse order.

pic5

Example6 : To print all files in reverse order.

pic6

Example7 : Sort the files by files size.

pic7

Example8 : List your home directory.

Example9 : List the home directory of user “Aman”.


 






14
May

Linux SU Command

Linux SU Command


 

Usage of Linux SU Command:

This command is used to become another user in his own session. By default, user without username will login as super-user (i.e. Root).

Syntax:

Example1 : Login as “guest “user.

Example2 : Run specific command with another user privilege say govind.

-c option is used to return back to the command line of former user after execution is completed.

Example3 : Login as root user.

Or

Note: In Linux while giving password it won’t be visible because of security reason.


 






10
May

Linux Introduction

Linux Introduction


 

Some historical fact for Linux:

In 1991, in Helsinki, Linus Torvalds began a project that later became the Linux kernel. He wrote the program specifically for the hardware as he wanted to use the functions of his new PC with an 80386 processor.

What is Linux?

Linux is an Operating System.

What is Operating System?

Low level software that supports a computer’s primitive function such as scheduling tasks and controlling peripherals.

Types of Operating System:

  1. System Software: System software are those software which incorporate the programs that are dedicated to manage the computer itself, such as the operating system, file management utilities, and disk operating system.For instance : Linux , Windows etc
  1. Application Software: Application software or simply applications, are often called productivity programs or end-user programs because they enable the user to complete. Specific examples of application software incorporate Microsoft Office, Excel and Outlook, Google Chrome, Mozilla Firefox and Skype.
  1. Utilized Software: Utilized Software or a business application is any software or set of computer programs used by business users to perform variety of business functions.  For instance: Antivirus, McAfee etc.

Finally we conclude: Linux is Open Source Operating System. Specifically Linux is System Software providing an interface between user and computer.

Advantages of Linux:

  • Linux is very durable.
  • Linux is less susceptible to computer malware.
  • Linux as compared to other OS is fast and does not slow down over time.
  • Old desktop/Laptops can be given new life using Linux OS
  • Linux has variety of distributors so we have many varieties in Linux.
  • Because there are many distributors you can freely access this software.
  • It’s a superior method of upgrading software

Disadvantages of Linux:

  • Many windows programs will not run in Linux thus requires a change.
  • There is a smaller selection of peripheral hardware drivers for Linux.
  • People who are new to Linux requires to learn this skill thoroughly in order to use the Operating System.

Features of Linux OS:

  • There are two prompts in Linux
    • $ -> Local user prompt
    • # -> Admin user prompt or Root Prompt
  • Commands are followed by switches but it does not matter in which order we are using switch.
    Example: ls –lrt is same as ls –rtl same as ls -l -r -t
  • Linux is case sensitive so using upper case will give different output and lower case different.
  • Linux is Open source operating system.
  • Several program are running at same time.
  • Several users on same machine at same time

Wild characters in Linux

S. No.Wild CharactersDescription
1*Asterisk find any number of characters in a filename, including none.
2?Question mark find any single character.
3[]Square brackets enclose a set of characters, any one of which may match single character at that position.
4Hyphen used within [ ] denotes a range of characters
5~Tilde at the beginning of a word expands to the name of home directory.

 






9
May

Linux Tutorial

 

Linux Tutorial


In this free Linux Tutorial, we will cover most important topics of Linux in a short, crisp and concise manner. Tutorial sections will have Linux Commands with examples and brief of each command how it works. This tutorial will cover Linux Beginner Level to Linux Advanced Level. In case, you are good in Linux and want to assess your knowledge. You should solve the Linux Assignments present and take the Linux Quiz to see where you stand. 

Pre-Requisites

To learn this tutorial, you don’t require any previous knowledge of this domain. Having knowledge in this domain is an added advantage.

Audience

Anyone who wants to gain extra knowledge of Linux Operating System and Linux Commands. This course can take up by students, geeks, Linux developers, testers, administrator. After completing this tutorial, you will find yourself ready to browse Linux Operating System, to answer Linux Interview Questions and to explore more around Linux.